mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-05-01 02:56:59 +00:00
improve readability and conciseness
This commit is contained in:
parent
9828562e57
commit
e5312da6fe
1 changed files with 25 additions and 59 deletions
|
@ -528,58 +528,28 @@ export class NoteEntityService implements OnModuleInit {
|
||||||
// パフォーマンスのためノートが作成されてから2秒以上経っていない場合はリアクションを取得しない
|
// パフォーマンスのためノートが作成されてから2秒以上経っていない場合はリアクションを取得しない
|
||||||
const oldId = this.idService.gen(Date.now() - 2000);
|
const oldId = this.idService.gen(Date.now() - 2000);
|
||||||
|
|
||||||
|
const targetNotes: MiNote[] = [];
|
||||||
for (const note of notes) {
|
for (const note of notes) {
|
||||||
// get my reaction for a renote.
|
|
||||||
if (isPureRenote(note)) {
|
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);
|
// we may need to fetch 'my reaction' for renote target.
|
||||||
if (reactionsCount === 0) {
|
targetNotes.push(note.renote);
|
||||||
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);
|
|
||||||
}
|
|
||||||
// get my reaction for OP if this is a renote of a reply.
|
|
||||||
if (note.renote.reply) {
|
if (note.renote.reply) {
|
||||||
const reactionsCount = Object.values(this.reactionsBufferingService.mergeReactions(note.renote.reply.reactions, bufferedReactions?.get(note.renote.reply.id)?.deltas ?? {})).reduce((a, b) => a + b, 0);
|
// idem if the renote is also a reply.
|
||||||
if (reactionsCount === 0) {
|
targetNotes.push(note.renote.reply);
|
||||||
myReactionsMap.set(note.renote.reply.id, null);
|
|
||||||
} else if (reactionsCount <= note.renote.reply.reactionAndUserPairCache.length + (bufferedReactions?.get(note.renote.reply.id)?.pairs.length ?? 0)) {
|
|
||||||
const pairInBuffer = bufferedReactions?.get(note.renote.reply.id)?.pairs.find(p => p[0] === meId);
|
|
||||||
if (pairInBuffer) {
|
|
||||||
myReactionsMap.set(note.renote.reply.id, pairInBuffer[1]);
|
|
||||||
} else {
|
|
||||||
const pair = note.renote.reply.reactionAndUserPairCache.find(p => p.startsWith(meId));
|
|
||||||
myReactionsMap.set(note.renote.reply.id, pair ? pair.split('/')[1] : null);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
idsNeedFetchMyReaction.add(note.renote.reply.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// get my reaction for OP if this is a reply.
|
|
||||||
} else if (note.reply) {
|
} else if (note.reply) {
|
||||||
const reactionsCount = Object.values(this.reactionsBufferingService.mergeReactions(note.reply.reactions, bufferedReactions?.get(note.reply.id)?.deltas ?? {})).reduce((a, b) => a + b, 0);
|
// idem for OP of a regular reply.
|
||||||
if (reactionsCount === 0) {
|
targetNotes.push(note.reply);
|
||||||
myReactionsMap.set(note.reply.id, null);
|
|
||||||
} else if (reactionsCount <= note.reply.reactionAndUserPairCache.length + (bufferedReactions?.get(note.reply.id)?.pairs.length ?? 0)) {
|
|
||||||
const pairInBuffer = bufferedReactions?.get(note.reply.id)?.pairs.find(p => p[0] === meId);
|
|
||||||
if (pairInBuffer) {
|
|
||||||
myReactionsMap.set(note.reply.id, pairInBuffer[1]);
|
|
||||||
} else {
|
|
||||||
const pair = note.reply.reactionAndUserPairCache.find(p => p.startsWith(meId));
|
|
||||||
myReactionsMap.set(note.reply.id, pair ? pair.split('/')[1] : null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
idsNeedFetchMyReaction.add(note.reply.id);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (note.id < oldId) {
|
if (note.id < oldId) {
|
||||||
|
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);
|
const reactionsCount = Object.values(this.reactionsBufferingService.mergeReactions(note.reactions, bufferedReactions?.get(note.id)?.deltas ?? {})).reduce((a, b) => a + b, 0);
|
||||||
if (reactionsCount === 0) {
|
if (reactionsCount === 0) {
|
||||||
myReactionsMap.set(note.id, null);
|
myReactionsMap.set(note.id, null);
|
||||||
|
@ -594,10 +564,6 @@ export class NoteEntityService implements OnModuleInit {
|
||||||
} else {
|
} else {
|
||||||
idsNeedFetchMyReaction.add(note.id);
|
idsNeedFetchMyReaction.add(note.id);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
myReactionsMap.set(note.id, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const myReactions = idsNeedFetchMyReaction.size > 0 ? await this.noteReactionsRepository.findBy({
|
const myReactions = idsNeedFetchMyReaction.size > 0 ? await this.noteReactionsRepository.findBy({
|
||||||
|
|
Loading…
Add table
Reference in a new issue