summaryrefslogtreecommitdiff
path: root/packages/backend
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-01-26 15:12:14 +0000
committerHazelnoot <acomputerdog@gmail.com>2025-01-26 15:12:14 +0000
commitd110a72b290f80bbe074abded7ec817e65da72a2 (patch)
tree0f68fdf239fbdeefec25fa79ff3eddf6b350b9ea /packages/backend
parentmerge: Remove node 20 from engines in backend (!867) (diff)
parentimprove readability and conciseness (diff)
downloadsharkey-d110a72b290f80bbe074abded7ec817e65da72a2.tar.gz
sharkey-d110a72b290f80bbe074abded7ec817e65da72a2.tar.bz2
sharkey-d110a72b290f80bbe074abded7ec817e65da72a2.zip
merge: fix: populate myreaction on regular timeline requests. (!840)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/840 Approved-by: dakkar <dakkar@thenautilus.net> Approved-by: Hazelnoot <acomputerdog@gmail.com>
Diffstat (limited to 'packages/backend')
-rw-r--r--packages/backend/src/core/entities/NoteEntityService.ts54
1 files changed, 27 insertions, 27 deletions
diff --git a/packages/backend/src/core/entities/NoteEntityService.ts b/packages/backend/src/core/entities/NoteEntityService.ts
index eb6b353752..be45e75d74 100644
--- a/packages/backend/src/core/entities/NoteEntityService.ts
+++ b/packages/backend/src/core/entities/NoteEntityService.ts
@@ -528,44 +528,44 @@ export class NoteEntityService implements OnModuleInit {
// パフォーマンスのためノートが作成されてから2秒以上経っていない場合はリアクションを取得しない
const oldId = this.idService.gen(Date.now() - 2000);
+ const targetNotes: MiNote[] = [];
for (const note of notes) {
if (isPureRenote(note)) {
- const reactionsCount = Object.values(this.reactionsBufferingService.mergeReactions(note.renote.reactions, bufferedReactions?.get(note.renote.id)?.deltas ?? {})).reduce((a, b) => a + b, 0);
- if (reactionsCount === 0) {
- myReactionsMap.set(note.renote.id, null);
- } else if (reactionsCount <= note.renote.reactionAndUserPairCache.length + (bufferedReactions?.get(note.renote.id)?.pairs.length ?? 0)) {
- const pairInBuffer = bufferedReactions?.get(note.renote.id)?.pairs.find(p => p[0] === meId);
- if (pairInBuffer) {
- myReactionsMap.set(note.renote.id, pairInBuffer[1]);
- } else {
- const pair = note.renote.reactionAndUserPairCache.find(p => p.startsWith(meId));
- myReactionsMap.set(note.renote.id, pair ? pair.split('/')[1] : null);
- }
- } else {
- idsNeedFetchMyReaction.add(note.renote.id);
+ // we may need to fetch 'my reaction' for renote target.
+ targetNotes.push(note.renote);
+ if (note.renote.reply) {
+ // idem if the renote is also a reply.
+ targetNotes.push(note.renote.reply);
}
+ } else if (note.reply) {
+ // idem for OP of a regular reply.
+ targetNotes.push(note.reply);
} else {
if (note.id < oldId) {
- const reactionsCount = Object.values(this.reactionsBufferingService.mergeReactions(note.reactions, bufferedReactions?.get(note.id)?.deltas ?? {})).reduce((a, b) => a + b, 0);
- if (reactionsCount === 0) {
- myReactionsMap.set(note.id, null);
- } else if (reactionsCount <= note.reactionAndUserPairCache.length + (bufferedReactions?.get(note.id)?.pairs.length ?? 0)) {
- const pairInBuffer = bufferedReactions?.get(note.id)?.pairs.find(p => p[0] === meId);
- if (pairInBuffer) {
- myReactionsMap.set(note.id, pairInBuffer[1]);
- } else {
- const pair = note.reactionAndUserPairCache.find(p => p.startsWith(meId));
- myReactionsMap.set(note.id, pair ? pair.split('/')[1] : null);
- }
- } else {
- idsNeedFetchMyReaction.add(note.id);
- }
+ targetNotes.push(note);
} else {
myReactionsMap.set(note.id, null);
}
}
}
+ for (const note of targetNotes) {
+ const reactionsCount = Object.values(this.reactionsBufferingService.mergeReactions(note.reactions, bufferedReactions?.get(note.id)?.deltas ?? {})).reduce((a, b) => a + b, 0);
+ if (reactionsCount === 0) {
+ myReactionsMap.set(note.id, null);
+ } else if (reactionsCount <= note.reactionAndUserPairCache.length + (bufferedReactions?.get(note.id)?.pairs.length ?? 0)) {
+ const pairInBuffer = bufferedReactions?.get(note.id)?.pairs.find(p => p[0] === meId);
+ if (pairInBuffer) {
+ myReactionsMap.set(note.id, pairInBuffer[1]);
+ } else {
+ const pair = note.reactionAndUserPairCache.find(p => p.startsWith(meId));
+ myReactionsMap.set(note.id, pair ? pair.split('/')[1] : null);
+ }
+ } else {
+ idsNeedFetchMyReaction.add(note.id);
+ }
+ }
+
const myReactions = idsNeedFetchMyReaction.size > 0 ? await this.noteReactionsRepository.findBy({
userId: meId,
noteId: In(Array.from(idsNeedFetchMyReaction)),