Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(message): always flag a message when a reaction is added (#2239)

Hampus7f448b1cabe9
diff --git a/fluxer_api/src/api/channel/repositories/IMessageInteractionRepository.ts b/fluxer_api/src/api/channel/repositories/IMessageInteractionRepository.ts
index 26ad1b952..43cecd99c 100644
--- a/fluxer_api/src/api/channel/repositories/IMessageInteractionRepository.ts
+++ b/fluxer_api/src/api/channel/repositories/IMessageInteractionRepository.ts
@@ -29,7 +29,6 @@ export abstract class IMessageInteractionRepository {
emojiName: string,
emojiId?: EmojiID,
emojiAnimated?: boolean,
- knownHasReaction?: boolean | null,
): Promise<MessageReaction>;
abstract removeReaction(
diff --git a/fluxer_api/src/api/channel/repositories/MessageInteractionRepository.test.ts b/fluxer_api/src/api/channel/repositories/MessageInteractionRepository.test.ts
index 080b9e33b..3fc7d1646 100644
--- a/fluxer_api/src/api/channel/repositories/MessageInteractionRepository.test.ts
+++ b/fluxer_api/src/api/channel/repositories/MessageInteractionRepository.test.ts
@@ -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);
});
});
diff --git a/fluxer_api/src/api/channel/repositories/MessageInteractionRepository.ts b/fluxer_api/src/api/channel/repositories/MessageInteractionRepository.ts
index 8b99ac034..aee1348ad 100644
--- a/fluxer_api/src/api/channel/repositories/MessageInteractionRepository.ts
+++ b/fluxer_api/src/api/channel/repositories/MessageInteractionRepository.ts
@@ -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);
}
diff --git a/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts b/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts
index ea43d8295..191ffb0f3 100644
--- a/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts
+++ b/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts
@@ -260,7 +260,6 @@ export class MessageReactionService extends MessageInteractionBase {
parsedEmoji.name,
emojiId,
parsedEmoji.animated ?? false,
- message.hasReaction,
);
await this.dispatchMessageReactionAdd({
channel,