shallow clone
This commit is contained in:
parent
b8e361e03c
commit
5fc9c1c8cd
6 changed files with 47 additions and 85 deletions
|
@ -9,8 +9,8 @@ import { isUserRelated } from '@/misc/is-user-related.js';
|
||||||
import { isRenotePacked, isQuotePacked } from '@/misc/is-renote.js';
|
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 { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
||||||
|
import type Connection from './Connection.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stream channel
|
* Stream channel
|
||||||
|
@ -103,13 +103,40 @@ export default abstract class Channel {
|
||||||
|
|
||||||
public onMessage?(type: string, body: JsonValue): void;
|
public onMessage?(type: string, body: JsonValue): void;
|
||||||
|
|
||||||
public async assignMyReaction(note: Packed<'Note'>, noteEntityService: NoteEntityService) {
|
public async assignMyReaction(note: Packed<'Note'>, noteEntityService: NoteEntityService): Promise<Packed<'Note'>> {
|
||||||
if (this.user && Object.keys(note.reactions).length > 0) {
|
let changed = false;
|
||||||
const myReaction = await noteEntityService.populateMyReaction(note, this.user.id);
|
const clonedNote = { ...note };
|
||||||
note.myReaction = myReaction;
|
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
|
||||||
|
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
|
||||||
|
const myReaction = await noteEntityService.populateMyReaction(note.renote, this.user.id);
|
||||||
|
if (myReaction) {
|
||||||
|
changed = true;
|
||||||
|
clonedNote.renote = { ...note.renote };
|
||||||
|
clonedNote.renote.myReaction = myReaction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.user && note.renote?.reply && Object.keys(note.renote.reply.reactions).length > 0) {
|
||||||
|
const myReaction = await noteEntityService.populateMyReaction(note.renote.reply, this.user.id);
|
||||||
|
if (myReaction) {
|
||||||
|
changed = true;
|
||||||
|
clonedNote.renote = { ...note.renote };
|
||||||
|
clonedNote.renote.reply = { ...note.renote.reply };
|
||||||
|
clonedNote.renote.reply.myReaction = myReaction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.user && note.reply && Object.keys(note.reply.reactions).length > 0) {
|
||||||
|
const myReaction = await noteEntityService.populateMyReaction(note.reply, this.user.id);
|
||||||
|
if (myReaction) {
|
||||||
|
changed = true;
|
||||||
|
clonedNote.reply = { ...note.reply };
|
||||||
|
clonedNote.reply.myReaction = myReaction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changed ? clonedNote : note;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export type MiChannelService<T extends boolean> = {
|
export type MiChannelService<T extends boolean> = {
|
||||||
shouldShare: boolean;
|
shouldShare: boolean;
|
||||||
|
|
|
@ -65,24 +65,11 @@ class BubbleTimelineChannel extends Channel {
|
||||||
|
|
||||||
if (this.isNoteMutedOrBlocked(note)) return;
|
if (this.isNoteMutedOrBlocked(note)) return;
|
||||||
|
|
||||||
const reactionsToFetch = [];
|
const clonedNote = await this.assignMyReaction(note, this.noteEntityService);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.user && note.reply) {
|
|
||||||
reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(reactionsToFetch);
|
this.connection.cacheNote(clonedNote);
|
||||||
|
|
||||||
this.connection.cacheNote(note);
|
this.send('note', clonedNote);
|
||||||
|
|
||||||
this.send('note', note);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
|
|
@ -60,24 +60,11 @@ class GlobalTimelineChannel extends Channel {
|
||||||
|
|
||||||
if (this.isNoteMutedOrBlocked(note)) return;
|
if (this.isNoteMutedOrBlocked(note)) return;
|
||||||
|
|
||||||
const reactionsToFetch = [];
|
const clonedNote = await this.assignMyReaction(note, this.noteEntityService);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.user && note.reply) {
|
|
||||||
reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(reactionsToFetch);
|
this.connection.cacheNote(clonedNote);
|
||||||
|
|
||||||
this.connection.cacheNote(note);
|
this.send('note', clonedNote);
|
||||||
|
|
||||||
this.send('note', note);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
|
|
@ -81,24 +81,11 @@ class HomeTimelineChannel extends Channel {
|
||||||
|
|
||||||
if (this.isNoteMutedOrBlocked(note)) return;
|
if (this.isNoteMutedOrBlocked(note)) return;
|
||||||
|
|
||||||
const reactionsToFetch = [];
|
const clonedNote = await this.assignMyReaction(note, this.noteEntityService);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.user && note.reply) {
|
|
||||||
reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(reactionsToFetch);
|
this.connection.cacheNote(clonedNote);
|
||||||
|
|
||||||
this.connection.cacheNote(note);
|
this.send('note', clonedNote);
|
||||||
|
|
||||||
this.send('note', note);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
|
|
@ -98,24 +98,11 @@ class HybridTimelineChannel extends Channel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const reactionsToFetch = [];
|
const clonedNote = await this.assignMyReaction(note, this.noteEntityService);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.user && note.reply) {
|
|
||||||
reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(reactionsToFetch);
|
this.connection.cacheNote(clonedNote);
|
||||||
|
|
||||||
this.connection.cacheNote(note);
|
this.send('note', clonedNote);
|
||||||
|
|
||||||
this.send('note', note);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
|
|
@ -70,24 +70,11 @@ class LocalTimelineChannel extends Channel {
|
||||||
|
|
||||||
if (this.isNoteMutedOrBlocked(note)) return;
|
if (this.isNoteMutedOrBlocked(note)) return;
|
||||||
|
|
||||||
const reactionsToFetch = [];
|
const clonedNote = await this.assignMyReaction(note, this.noteEntityService);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.user && note.reply) {
|
|
||||||
reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService));
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(reactionsToFetch);
|
this.connection.cacheNote(clonedNote);
|
||||||
|
|
||||||
this.connection.cacheNote(note);
|
this.send('note', clonedNote);
|
||||||
|
|
||||||
this.send('note', note);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
|
Loading…
Add table
Reference in a new issue