mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-11-23 14:46:07 +09:00
parent
32faf7e0ea
commit
34823aa7b8
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user