[backend] Fetch pinned notes with following user

fixes #567
This commit is contained in:
mia 2024-10-16 05:07:57 -07:00 committed by Iceshrimp development
parent 32faf7e0ea
commit 34823aa7b8
4 changed files with 22 additions and 4 deletions

View File

@ -383,6 +383,14 @@ export const UserRepository = db.getRepository(User).extend({
};
},
async getRandomFollower(targetId: string): Promise<User | null> {
return await this.createQueryBuilder("u")
.select(`u.id`)
.leftJoinAndSelect("following", "f", `f."followerId" = u.id`)
.where(`f."followeeId" = :id`, { id: targetId })
.getOne();
},
async packCached<
ExpectsMe extends boolean | null = null,
D extends boolean = false,

View File

@ -2,6 +2,8 @@ import type { CacheableRemoteUser } from "@/models/entities/user.js";
import type { IAdd } from "../../type.js";
import { resolveNote } from "../../models/note.js";
import { addPinned } from "@/services/i/pin.js";
import Resolver from "../../resolver.js";
import { Users } from "@/models/index.js";
export default async (
actor: CacheableRemoteUser,
@ -16,7 +18,11 @@ export default async (
}
if (activity.target === actor.featured) {
const note = await resolveNote(activity.object);
const resolver = new Resolver();
const follower = await Users.getRandomFollower(actor.id);
if (follower) resolver.setUser(follower);
const note = await resolveNote(activity.object, resolver);
if (note == null) throw new Error("note not found");
await addPinned(actor, note.id);
return;

View File

@ -1,6 +1,6 @@
import type { CacheableRemoteUser } from "@/models/entities/user.js";
import type { IRemove } from "../../type.js";
import { resolveNote } from "../../models/note.js";
import { fetchNote } from "../../models/note.js";
import { removePinned } from "@/services/i/pin.js";
export default async (
@ -16,8 +16,8 @@ export default async (
}
if (activity.target === actor.featured) {
const note = await resolveNote(activity.object);
if (note == null) throw new Error("note not found");
const note = await fetchNote(activity.object);
if (note == null) return; // not pinned either way
await removePinned(actor, note.id);
return;
}

View File

@ -753,6 +753,10 @@ export async function updateFeatured(userId: User["id"], resolver?: Resolver, li
if (resolver == null) resolver = new Resolver();
// Attempt to get a local user that follows the remote user
const follower = await Users.getRandomFollower(userId);
if (follower) resolver.setUser(follower);
// Resolve to (Ordered)Collection Object
const collection = await resolver.resolveCollection(user.featured);
if (!isCollectionOrOrderedCollection(collection))