diff
This commit is contained in:
parent
f083cbbeb2
commit
e59ed9008c
|
@ -330,7 +330,7 @@ export class NoteManager {
|
||||||
|
|
||||||
const note = this.notesSource.get(id);
|
const note = this.notesSource.get(id);
|
||||||
|
|
||||||
if (this.isDebuggerEnabled) console.log('NoteManager: onStreamNoteUpdated', noteData);
|
if (this.isDebuggerEnabled) console.log('NoteManager: onStreamNoteUpdated (recieved)', noteData);
|
||||||
|
|
||||||
if (!note || !note.value) {
|
if (!note || !note.value) {
|
||||||
if (this.isDebuggerEnabled) console.log('NoteManager: onStreamNoteUpdated (not found)', id, note?.value);
|
if (this.isDebuggerEnabled) console.log('NoteManager: onStreamNoteUpdated (not found)', id, note?.value);
|
||||||
|
@ -343,28 +343,24 @@ export class NoteManager {
|
||||||
if (this.isDebuggerEnabled) console.log('NoteManager: onStreamNoteUpdated (found)', id, note.value, { type, id, body });
|
if (this.isDebuggerEnabled) console.log('NoteManager: onStreamNoteUpdated (found)', id, note.value, { type, id, body });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const diff: Partial<OmittedNote> = {};
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'reacted': {
|
case 'reacted': {
|
||||||
const reaction = body.reaction;
|
const reaction = body.reaction;
|
||||||
|
|
||||||
if (body.emoji && !(body.emoji.name in note.value.reactionEmojis)) {
|
if (body.emoji && !(body.emoji.name in note.value.reactionEmojis)) {
|
||||||
note.value.reactionEmojis = {
|
diff.reactionEmojis = {
|
||||||
...note.value.reactionEmojis,
|
...note.value.reactionEmojis,
|
||||||
[body.emoji.name]: body.emoji.url,
|
[body.emoji.name]: body.emoji.url,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reaction in note.value.reactions) {
|
diff.reactions = { ...note.value.reactions };
|
||||||
note.value.reactions[reaction]++;
|
diff.reactions[reaction] = (note.value.reactions[reaction] ?? 0) + 1;
|
||||||
} else {
|
|
||||||
note.value.reactions = {
|
|
||||||
...note.value.reactions,
|
|
||||||
[reaction]: 1,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($i && (body.userId === $i.id)) {
|
if ($i && (body.userId === $i.id)) {
|
||||||
note.value.myReaction = reaction;
|
diff.myReaction = reaction;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -372,14 +368,16 @@ export class NoteManager {
|
||||||
case 'unreacted': {
|
case 'unreacted': {
|
||||||
const reaction = body.reaction;
|
const reaction = body.reaction;
|
||||||
|
|
||||||
// TODO: reactionsプロパティがない場合ってあったっけ? なければ || {} は消せる
|
diff.reactions = { ...note.value.reactions };
|
||||||
const currentCount = (note.value.reactions || {})[reaction] || 0;
|
const count = Math.max(0, (note.value.reactions[reaction] ?? 0) - 1);
|
||||||
|
if (count === 0) {
|
||||||
note.value.reactions[reaction] = Math.max(0, currentCount - 1);
|
delete diff.reactions[reaction];
|
||||||
if (note.value.reactions[reaction] === 0) delete note.value.reactions[reaction];
|
} else {
|
||||||
|
diff.reactions[reaction] = count;
|
||||||
|
}
|
||||||
|
|
||||||
if ($i && (body.userId === $i.id)) {
|
if ($i && (body.userId === $i.id)) {
|
||||||
note.value.myReaction = undefined;
|
diff.myReaction = undefined;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -396,7 +394,7 @@ export class NoteManager {
|
||||||
} : {}),
|
} : {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
note.value.poll!.choices = choices;
|
diff.poll = { ...note.value.poll!, choices };
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,6 +408,11 @@ export class NoteManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.isDebuggerEnabled) console.log('NoteManager: onStreamNoteUpdated (update)', id, type, diff);
|
||||||
|
if (type !== 'deleted') {
|
||||||
|
if (!note.value) throw new Error('NoteManager: onStreamNoteUpdated (update) note.value is null');
|
||||||
|
note.value = { ...note.value, ...diff };
|
||||||
|
}
|
||||||
this.updatedAt.set(id, Date.now());
|
this.updatedAt.set(id, Date.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue