summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/stream/channels
diff options
context:
space:
mode:
authorpiuvas <piuvas@proton.me>2024-12-25 16:41:40 -0300
committerpiuvas <piuvas@proton.me>2024-12-25 16:41:40 -0300
commit64abef8be9897db493670a63817ee2876db079b8 (patch)
treea15e6c7a4bd48e271ec878c64e07a4b60e2aa757 /packages/backend/src/server/api/stream/channels
parentimprovements. (diff)
downloadsharkey-64abef8be9897db493670a63817ee2876db079b8.tar.gz
sharkey-64abef8be9897db493670a63817ee2876db079b8.tar.bz2
sharkey-64abef8be9897db493670a63817ee2876db079b8.zip
turn task into a function
Diffstat (limited to 'packages/backend/src/server/api/stream/channels')
-rw-r--r--packages/backend/src/server/api/stream/channels/bubble-timeline.ts22
-rw-r--r--packages/backend/src/server/api/stream/channels/global-timeline.ts22
-rw-r--r--packages/backend/src/server/api/stream/channels/home-timeline.ts22
-rw-r--r--packages/backend/src/server/api/stream/channels/hybrid-timeline.ts25
-rw-r--r--packages/backend/src/server/api/stream/channels/local-timeline.ts22
5 files changed, 41 insertions, 72 deletions
diff --git a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts
index 41b7b7cd3c..a0875288a2 100644
--- a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts
@@ -65,25 +65,19 @@ class BubbleTimelineChannel extends Channel {
if (this.isNoteMutedOrBlocked(note)) return;
+ const reactionsToFetch = [];
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
- if (note.renote && Object.keys(note.renote.reactions).length > 0) {
- const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
- note.renote.myReaction = myRenoteReaction;
- }
- if (note.renote && note.renote.reply) {
- if (Object.keys(note.renote.reply.reactions).length > 0) {
- const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id);
- note.renote.reply.myReaction = myReplyReaction;
+ if (note.renote) {
+ reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService));
+ if (note.renote.reply) {
+ reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService));
}
}
+ } else if (this.user && note.reply) {
+ reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
}
- if (this.user && note.reply) {
- if (Object.keys(note.reply.reactions).length > 0) {
- const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
- note.reply.myReaction = myReplyReaction;
- }
- }
+ await Promise.all(reactionsToFetch);
this.connection.cacheNote(note);
diff --git a/packages/backend/src/server/api/stream/channels/global-timeline.ts b/packages/backend/src/server/api/stream/channels/global-timeline.ts
index 6da21ac72c..d133d84c09 100644
--- a/packages/backend/src/server/api/stream/channels/global-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts
@@ -60,25 +60,19 @@ class GlobalTimelineChannel extends Channel {
if (this.isNoteMutedOrBlocked(note)) return;
+ const reactionsToFetch = [];
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
- if (note.renote && Object.keys(note.renote.reactions).length > 0) {
- const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
- note.renote.myReaction = myRenoteReaction;
- }
- if (note.renote && note.renote.reply) {
- if (Object.keys(note.renote.reply.reactions).length > 0) {
- const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id);
- note.renote.reply.myReaction = myReplyReaction;
+ if (note.renote) {
+ reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService));
+ if (note.renote.reply) {
+ reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService));
}
}
+ } else if (this.user && note.reply) {
+ reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
}
- if (this.user && note.reply) {
- if (Object.keys(note.reply.reactions).length > 0) {
- const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
- note.reply.myReaction = myReplyReaction;
- }
- }
+ await Promise.all(reactionsToFetch);
this.connection.cacheNote(note);
diff --git a/packages/backend/src/server/api/stream/channels/home-timeline.ts b/packages/backend/src/server/api/stream/channels/home-timeline.ts
index d4b65222a0..8c059e2405 100644
--- a/packages/backend/src/server/api/stream/channels/home-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts
@@ -81,25 +81,19 @@ class HomeTimelineChannel extends Channel {
if (this.isNoteMutedOrBlocked(note)) return;
+ const reactionsToFetch = [];
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
- if (note.renote && Object.keys(note.renote.reactions).length > 0) {
- const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
- note.renote.myReaction = myRenoteReaction;
- }
- if (note.renote && note.renote.reply) {
- if (Object.keys(note.renote.reply.reactions).length > 0) {
- const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id);
- note.renote.reply.myReaction = myReplyReaction;
+ if (note.renote) {
+ reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService));
+ if (note.renote.reply) {
+ reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService));
}
}
+ } else if (this.user && note.reply) {
+ reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
}
- if (this.user && note.reply) {
- if (Object.keys(note.reply.reactions).length > 0) {
- const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
- note.reply.myReaction = myReplyReaction;
- }
- }
+ await Promise.all(reactionsToFetch);
this.connection.cacheNote(note);
diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
index c989721463..8eedcdbd59 100644
--- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
@@ -98,26 +98,19 @@ class HybridTimelineChannel extends Channel {
}
}
- if (this.user && note.renoteId && !note.text) {
- if (note.renote && Object.keys(note.renote.reactions).length > 0) {
- console.log(note.renote.reactionAndUserPairCache);
- const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
- note.renote.myReaction = myRenoteReaction;
- }
- if (note.renote && note.renote.reply) {
- if (Object.keys(note.renote.reply.reactions).length > 0) {
- const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id);
- note.renote.reply.myReaction = myReplyReaction;
+ const reactionsToFetch = [];
+ if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
+ if (note.renote) {
+ reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService));
+ if (note.renote.reply) {
+ reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService));
}
}
+ } else if (this.user && note.reply) {
+ reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
}
- if (this.user && note.reply) {
- if (Object.keys(note.reply.reactions).length > 0) {
- const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
- note.reply.myReaction = myReplyReaction;
- }
- }
+ await Promise.all(reactionsToFetch);
this.connection.cacheNote(note);
diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts
index 2f1720f8fe..89187c49fd 100644
--- a/packages/backend/src/server/api/stream/channels/local-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts
@@ -70,25 +70,19 @@ class LocalTimelineChannel extends Channel {
if (this.isNoteMutedOrBlocked(note)) return;
+ const reactionsToFetch = [];
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
- if (note.renote && Object.keys(note.renote.reactions).length > 0) {
- const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
- note.renote.myReaction = myRenoteReaction;
- }
- if (note.renote && note.renote.reply) {
- if (Object.keys(note.renote.reply.reactions).length > 0) {
- const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id);
- note.renote.reply.myReaction = myReplyReaction;
+ if (note.renote) {
+ reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService));
+ if (note.renote.reply) {
+ reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService));
}
}
+ } else if (this.user && note.reply) {
+ reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
}
- if (this.user && note.reply) {
- if (Object.keys(note.reply.reactions).length > 0) {
- const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
- note.reply.myReaction = myReplyReaction;
- }
- }
+ await Promise.all(reactionsToFetch);
this.connection.cacheNote(note);