turn task into a function
This commit is contained in:
parent
94c3a71e49
commit
64abef8be9
6 changed files with 50 additions and 72 deletions
|
@ -10,6 +10,7 @@ import { isRenotePacked, isQuotePacked } from '@/misc/is-renote.js';
|
||||||
import type { Packed } from '@/misc/json-schema.js';
|
import type { Packed } from '@/misc/json-schema.js';
|
||||||
import type { JsonObject, JsonValue } from '@/misc/json-value.js';
|
import type { JsonObject, JsonValue } from '@/misc/json-value.js';
|
||||||
import type Connection from './Connection.js';
|
import type Connection from './Connection.js';
|
||||||
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stream channel
|
* Stream channel
|
||||||
|
@ -101,6 +102,14 @@ export default abstract class Channel {
|
||||||
public dispose?(): void;
|
public dispose?(): void;
|
||||||
|
|
||||||
public onMessage?(type: string, body: JsonValue): void;
|
public onMessage?(type: string, body: JsonValue): void;
|
||||||
|
|
||||||
|
public async assignMyReaction(note: Packed<'Note'>, noteEntityService: NoteEntityService) {
|
||||||
|
if (this.user === undefined) { return; }
|
||||||
|
if (Object.keys(note.reactions).length > 0) {
|
||||||
|
const myReaction = await noteEntityService.populateMyReaction(note, this.user.id);
|
||||||
|
note.myReaction = myReaction;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MiChannelService<T extends boolean> = {
|
export type MiChannelService<T extends boolean> = {
|
||||||
|
|
|
@ -65,25 +65,19 @@ class BubbleTimelineChannel extends Channel {
|
||||||
|
|
||||||
if (this.isNoteMutedOrBlocked(note)) return;
|
if (this.isNoteMutedOrBlocked(note)) return;
|
||||||
|
|
||||||
|
const reactionsToFetch = [];
|
||||||
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
|
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
|
||||||
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
|
if (note.renote) {
|
||||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService));
|
||||||
note.renote.myReaction = myRenoteReaction;
|
if (note.renote.reply) {
|
||||||
}
|
reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (this.user && note.reply) {
|
||||||
|
reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.user && note.reply) {
|
await Promise.all(reactionsToFetch);
|
||||||
if (Object.keys(note.reply.reactions).length > 0) {
|
|
||||||
const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
|
|
||||||
note.reply.myReaction = myReplyReaction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.connection.cacheNote(note);
|
this.connection.cacheNote(note);
|
||||||
|
|
||||||
|
|
|
@ -60,25 +60,19 @@ class GlobalTimelineChannel extends Channel {
|
||||||
|
|
||||||
if (this.isNoteMutedOrBlocked(note)) return;
|
if (this.isNoteMutedOrBlocked(note)) return;
|
||||||
|
|
||||||
|
const reactionsToFetch = [];
|
||||||
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
|
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
|
||||||
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
|
if (note.renote) {
|
||||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService));
|
||||||
note.renote.myReaction = myRenoteReaction;
|
if (note.renote.reply) {
|
||||||
}
|
reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (this.user && note.reply) {
|
||||||
|
reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.user && note.reply) {
|
await Promise.all(reactionsToFetch);
|
||||||
if (Object.keys(note.reply.reactions).length > 0) {
|
|
||||||
const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
|
|
||||||
note.reply.myReaction = myReplyReaction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.connection.cacheNote(note);
|
this.connection.cacheNote(note);
|
||||||
|
|
||||||
|
|
|
@ -81,25 +81,19 @@ class HomeTimelineChannel extends Channel {
|
||||||
|
|
||||||
if (this.isNoteMutedOrBlocked(note)) return;
|
if (this.isNoteMutedOrBlocked(note)) return;
|
||||||
|
|
||||||
|
const reactionsToFetch = [];
|
||||||
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
|
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
|
||||||
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
|
if (note.renote) {
|
||||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService));
|
||||||
note.renote.myReaction = myRenoteReaction;
|
if (note.renote.reply) {
|
||||||
}
|
reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (this.user && note.reply) {
|
||||||
|
reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.user && note.reply) {
|
await Promise.all(reactionsToFetch);
|
||||||
if (Object.keys(note.reply.reactions).length > 0) {
|
|
||||||
const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
|
|
||||||
note.reply.myReaction = myReplyReaction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.connection.cacheNote(note);
|
this.connection.cacheNote(note);
|
||||||
|
|
||||||
|
|
|
@ -98,26 +98,19 @@ class HybridTimelineChannel extends Channel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.user && note.renoteId && !note.text) {
|
const reactionsToFetch = [];
|
||||||
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
|
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
|
||||||
console.log(note.renote.reactionAndUserPairCache);
|
if (note.renote) {
|
||||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService));
|
||||||
note.renote.myReaction = myRenoteReaction;
|
if (note.renote.reply) {
|
||||||
}
|
reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (this.user && note.reply) {
|
||||||
|
reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.user && note.reply) {
|
await Promise.all(reactionsToFetch);
|
||||||
if (Object.keys(note.reply.reactions).length > 0) {
|
|
||||||
const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
|
|
||||||
note.reply.myReaction = myReplyReaction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.connection.cacheNote(note);
|
this.connection.cacheNote(note);
|
||||||
|
|
||||||
|
|
|
@ -70,25 +70,19 @@ class LocalTimelineChannel extends Channel {
|
||||||
|
|
||||||
if (this.isNoteMutedOrBlocked(note)) return;
|
if (this.isNoteMutedOrBlocked(note)) return;
|
||||||
|
|
||||||
|
const reactionsToFetch = [];
|
||||||
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
|
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
|
||||||
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
|
if (note.renote) {
|
||||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService));
|
||||||
note.renote.myReaction = myRenoteReaction;
|
if (note.renote.reply) {
|
||||||
}
|
reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (this.user && note.reply) {
|
||||||
|
reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.user && note.reply) {
|
await Promise.all(reactionsToFetch);
|
||||||
if (Object.keys(note.reply.reactions).length > 0) {
|
|
||||||
const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
|
|
||||||
note.reply.myReaction = myReplyReaction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.connection.cacheNote(note);
|
this.connection.cacheNote(note);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue