expose thread mute status as Note.isMuting property

This commit is contained in:
Hazelnoot 2025-06-09 22:10:30 -04:00
parent 23cfb5647c
commit 87582034b5
3 changed files with 16 additions and 2 deletions

View file

@ -422,6 +422,7 @@ export class NoteEntityService implements OnModuleInit {
pollVotes: Map<string, Map<string, MiPollVote[]>>;
channels: Map<string, MiChannel>;
notes: Map<string, MiNote>;
mutedThreads: Set<string>;
};
},
): Promise<Packed<'Note'>> {
@ -460,9 +461,11 @@ export class NoteEntityService implements OnModuleInit {
const packedFiles = options?._hint_?.packedFiles;
const packedUsers = options?._hint_?.packedUsers;
const threadId = note.threadId ?? note.id;
const packed: Packed<'Note'> = await awaitAll({
id: note.id,
threadId: note.threadId ?? note.id,
threadId,
createdAt: this.idService.parse(note.id).date.toISOString(),
updatedAt: note.updatedAt ? note.updatedAt.toISOString() : undefined,
userId: note.userId,
@ -502,6 +505,8 @@ export class NoteEntityService implements OnModuleInit {
poll: opts._hint_?.polls.get(note.id),
myVotes: opts._hint_?.pollVotes.get(note.id)?.get(note.userId),
}) : undefined,
isMuting: opts._hint_?.mutedThreads.has(threadId)
?? (meId != null && this.cacheService.threadMutingsCache.fetch(meId).then(ms => ms.has(threadId))),
...(meId && Object.keys(reactions).length > 0 ? {
myReaction: this.populateMyReaction({
@ -649,7 +654,7 @@ export class NoteEntityService implements OnModuleInit {
const fileIds = new Set(targetNotes.flatMap(n => n.fileIds));
const mentionedUsers = new Set(targetNotes.flatMap(note => note.mentions));
const [{ bufferedReactions, myReactionsMap }, packedFiles, packedUsers, mentionHandles, userFollowings, userBlockers, polls, pollVotes, channels] = await Promise.all([
const [{ bufferedReactions, myReactionsMap }, packedFiles, packedUsers, mentionHandles, userFollowings, userBlockers, polls, pollVotes, channels, mutedThreads] = await Promise.all([
// bufferedReactions & myReactionsMap
this.getReactions(targetNotes, me),
// packedFiles
@ -660,6 +665,7 @@ export class NoteEntityService implements OnModuleInit {
// mentionHandles
this.getUserHandles(Array.from(mentionedUsers)),
// userFollowings
// TODO this might be wrong
this.cacheService.userFollowingsCache.fetchMany(userIds).then(fs => new Map(fs)),
// userBlockers
this.cacheService.userBlockedCache.fetchMany(userIds).then(bs => new Map(bs)),
@ -684,6 +690,8 @@ export class NoteEntityService implements OnModuleInit {
}, new Map<string, Map<string, MiPollVote[]>>)),
// channels
this.getChannels(targetNotes),
// mutedThreads
me ? this.cacheService.threadMutingsCache.fetch(me.id) : new Set<string>(),
// (not returned)
this.customEmojiService.prefetchEmojis(this.aggregateNoteEmojis(notes)),
]);
@ -702,6 +710,7 @@ export class NoteEntityService implements OnModuleInit {
pollVotes,
channels,
notes: new Map(targetNotes.map(n => [n.id, n])),
mutedThreads,
},
})));
}

View file

@ -173,6 +173,10 @@ export const packedNoteSchema = {
},
},
},
isMuting: {
type: 'boolean',
optional: false, nullable: false,
},
emojis: {
type: 'object',
optional: true, nullable: false,

View file

@ -4701,6 +4701,7 @@ export type components = {
votes: number;
}[];
}) | null;
isMuting: boolean;
emojis?: {
[key: string]: string;
};