mirror of
https://github.com/fluxerapp/fluxer.git
synced 2026-09-02 21:04:06 +03:00
fix(message): always flag a message when a reaction is added (#2239)
This commit is contained in:
@@ -29,7 +29,6 @@ export abstract class IMessageInteractionRepository {
|
||||
emojiName: string,
|
||||
emojiId?: EmojiID,
|
||||
emojiAnimated?: boolean,
|
||||
knownHasReaction?: boolean | null,
|
||||
): Promise<MessageReaction>;
|
||||
|
||||
abstract removeReaction(
|
||||
|
||||
@@ -73,23 +73,25 @@ describe('MessageInteractionRepository has_reaction writes', () => {
|
||||
expect(executor.countHasReactionWrites()).toBe(1);
|
||||
expect(await loadHasReaction(channelId, messageId)).toBe(true);
|
||||
});
|
||||
it('skips the flag write when the message is already known to be flagged', async () => {
|
||||
it('flags the message on every reaction add', async () => {
|
||||
const channelId = createChannelID(10n);
|
||||
const messageId = createMessageID(100n);
|
||||
const repository = createRepository();
|
||||
await repository.addReaction(channelId, messageId, createUserID(1n), '🔥');
|
||||
await repository.addReaction(channelId, messageId, createUserID(2n), '🔥', undefined, false, true);
|
||||
expect(executor.countHasReactionWrites()).toBe(1);
|
||||
await repository.addReaction(channelId, messageId, createUserID(2n), '🔥');
|
||||
expect(executor.countHasReactionWrites()).toBe(2);
|
||||
expect(await repository.listMessageReactions(channelId, messageId)).toHaveLength(2);
|
||||
expect(await loadHasReaction(channelId, messageId)).toBe(true);
|
||||
});
|
||||
it('flags the message when the loaded flag is not already true', async () => {
|
||||
it('restores the flag when it was cleared after the message was read', async () => {
|
||||
const channelId = createChannelID(10n);
|
||||
const messageId = createMessageID(100n);
|
||||
const repository = createRepository();
|
||||
await repository.addReaction(channelId, messageId, createUserID(1n), '🔥', undefined, false, null);
|
||||
await repository.addReaction(channelId, messageId, createUserID(2n), '🔥', undefined, false, false);
|
||||
expect(executor.countHasReactionWrites()).toBe(2);
|
||||
await repository.addReaction(channelId, messageId, createUserID(1n), '🔥');
|
||||
await repository.setHasReaction(channelId, messageId, false);
|
||||
expect(await loadHasReaction(channelId, messageId)).toBe(false);
|
||||
await repository.addReaction(channelId, messageId, createUserID(2n), '🔥');
|
||||
expect(await loadHasReaction(channelId, messageId)).toBe(true);
|
||||
expect(await repository.listMessageReactions(channelId, messageId)).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -170,7 +170,6 @@ export class MessageInteractionRepository extends IMessageInteractionRepository
|
||||
emojiName: string,
|
||||
emojiId?: EmojiID,
|
||||
emojiAnimated: boolean = false,
|
||||
knownHasReaction?: boolean | null,
|
||||
): Promise<MessageReaction> {
|
||||
const bucket = BucketUtils.makeBucket(messageId);
|
||||
const normalizedEmojiId = emojiId ? emojiId : createEmojiID(0n);
|
||||
@@ -185,9 +184,7 @@ export class MessageInteractionRepository extends IMessageInteractionRepository
|
||||
created_at: new Date(),
|
||||
};
|
||||
await upsertOne(MessageReactions.upsertAll(reactionData));
|
||||
if (knownHasReaction !== true) {
|
||||
await this.setHasReaction(channelId, messageId, true);
|
||||
}
|
||||
await this.setHasReaction(channelId, messageId, true);
|
||||
return new MessageReaction(reactionData);
|
||||
}
|
||||
|
||||
|
||||
@@ -260,7 +260,6 @@ export class MessageReactionService extends MessageInteractionBase {
|
||||
parsedEmoji.name,
|
||||
emojiId,
|
||||
parsedEmoji.animated ?? false,
|
||||
message.hasReaction,
|
||||
);
|
||||
await this.dispatchMessageReactionAdd({
|
||||
channel,
|
||||
|
||||
Reference in New Issue
Block a user