Fixes story reaction notification text
This commit is contained in:
parent
0888b57744
commit
712c9597c5
3 changed files with 79 additions and 61 deletions
|
@ -7303,10 +7303,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Quote__story-reaction--yours": {
|
|
||||||
"message": "Reacted to your story",
|
|
||||||
"description": "Label for when a person reacts to your story"
|
|
||||||
},
|
|
||||||
"Quote__story-reaction--single": {
|
"Quote__story-reaction--single": {
|
||||||
"message": "Reacted to a story",
|
"message": "Reacted to a story",
|
||||||
"description": "Used whenever we can't find a user's first name"
|
"description": "Used whenever we can't find a user's first name"
|
||||||
|
|
|
@ -4,11 +4,15 @@
|
||||||
/* eslint-disable max-classes-per-file */
|
/* eslint-disable max-classes-per-file */
|
||||||
|
|
||||||
import { Collection, Model } from 'backbone';
|
import { Collection, Model } from 'backbone';
|
||||||
import * as log from '../logging/log';
|
import type { ConversationModel } from '../models/conversations';
|
||||||
import type { MessageModel } from '../models/messages';
|
import type { MessageModel } from '../models/messages';
|
||||||
import type { ReactionAttributesType } from '../model-types.d';
|
import type {
|
||||||
|
MessageAttributesType,
|
||||||
|
ReactionAttributesType,
|
||||||
|
} from '../model-types.d';
|
||||||
|
import * as log from '../logging/log';
|
||||||
import { getContactId, getContact } from '../messages/helpers';
|
import { getContactId, getContact } from '../messages/helpers';
|
||||||
import { isDirectConversation } from '../util/whatTypeOfConversation';
|
import { isDirectConversation, isMe } from '../util/whatTypeOfConversation';
|
||||||
import { isOutgoing, isStory } from '../state/selectors/message';
|
import { isOutgoing, isStory } from '../state/selectors/message';
|
||||||
|
|
||||||
export class ReactionModel extends Model<ReactionAttributesType> {}
|
export class ReactionModel extends Model<ReactionAttributesType> {}
|
||||||
|
@ -56,6 +60,26 @@ export class Reactions extends Collection<ReactionModel> {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async findMessage(
|
||||||
|
targetTimestamp: number,
|
||||||
|
targetConversationId: string
|
||||||
|
): Promise<MessageAttributesType | undefined> {
|
||||||
|
const messages = await window.Signal.Data.getMessagesBySentAt(
|
||||||
|
targetTimestamp
|
||||||
|
);
|
||||||
|
|
||||||
|
return messages.find(m => {
|
||||||
|
const contact = getContact(m);
|
||||||
|
|
||||||
|
if (!contact) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mcid = contact.get('id');
|
||||||
|
return mcid === targetConversationId;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async onReaction(
|
async onReaction(
|
||||||
reaction: ReactionModel,
|
reaction: ReactionModel,
|
||||||
generatedMessage: MessageModel
|
generatedMessage: MessageModel
|
||||||
|
@ -73,11 +97,41 @@ export class Reactions extends Collection<ReactionModel> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetConversation =
|
const fromConversation = window.ConversationController.get(
|
||||||
await window.ConversationController.getConversationForTargetMessage(
|
generatedMessage.get('conversationId')
|
||||||
targetConversationId,
|
);
|
||||||
|
|
||||||
|
let targetConversation: ConversationModel | undefined | null;
|
||||||
|
|
||||||
|
const targetMessageCheck = await this.findMessage(
|
||||||
|
reaction.get('targetTimestamp'),
|
||||||
|
targetConversationId
|
||||||
|
);
|
||||||
|
if (!targetMessageCheck) {
|
||||||
|
log.info(
|
||||||
|
'No message for reaction',
|
||||||
|
reaction.get('targetAuthorUuid'),
|
||||||
reaction.get('targetTimestamp')
|
reaction.get('targetTimestamp')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
fromConversation &&
|
||||||
|
isStory(targetMessageCheck) &&
|
||||||
|
isDirectConversation(fromConversation.attributes) &&
|
||||||
|
!isMe(fromConversation.attributes)
|
||||||
|
) {
|
||||||
|
targetConversation = fromConversation;
|
||||||
|
} else {
|
||||||
|
targetConversation =
|
||||||
|
await window.ConversationController.getConversationForTargetMessage(
|
||||||
|
targetConversationId,
|
||||||
|
reaction.get('targetTimestamp')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!targetConversation) {
|
if (!targetConversation) {
|
||||||
log.info(
|
log.info(
|
||||||
'No target conversation for reaction',
|
'No target conversation for reaction',
|
||||||
|
@ -91,44 +145,19 @@ export class Reactions extends Collection<ReactionModel> {
|
||||||
await targetConversation.queueJob('Reactions.onReaction', async () => {
|
await targetConversation.queueJob('Reactions.onReaction', async () => {
|
||||||
log.info('Handling reaction for', reaction.get('targetTimestamp'));
|
log.info('Handling reaction for', reaction.get('targetTimestamp'));
|
||||||
|
|
||||||
const messages = await window.Signal.Data.getMessagesBySentAt(
|
// Thanks TS.
|
||||||
reaction.get('targetTimestamp')
|
if (!targetConversation) {
|
||||||
);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Message is fetched inside the conversation queue so we have the
|
// Message is fetched inside the conversation queue so we have the
|
||||||
// most recent data
|
// most recent data
|
||||||
const targetMessage = messages.find(m => {
|
const targetMessage = await this.findMessage(
|
||||||
const contact = getContact(m);
|
reaction.get('targetTimestamp'),
|
||||||
|
targetConversationId
|
||||||
if (!contact) {
|
);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mcid = contact.get('id');
|
|
||||||
const recid = window.ConversationController.ensureContactIds({
|
|
||||||
uuid: reaction.get('targetAuthorUuid'),
|
|
||||||
});
|
|
||||||
return mcid === recid;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!targetMessage) {
|
if (!targetMessage) {
|
||||||
log.info(
|
|
||||||
'No message for reaction',
|
|
||||||
reaction.get('targetAuthorUuid'),
|
|
||||||
reaction.get('targetTimestamp')
|
|
||||||
);
|
|
||||||
|
|
||||||
// Since we haven't received the message for which we are removing a
|
|
||||||
// reaction, we can just remove those pending reactions
|
|
||||||
if (reaction.get('remove')) {
|
|
||||||
this.remove(reaction);
|
|
||||||
const oldReaction = this.where({
|
|
||||||
targetAuthorUuid: reaction.get('targetAuthorUuid'),
|
|
||||||
targetTimestamp: reaction.get('targetTimestamp'),
|
|
||||||
emoji: reaction.get('emoji'),
|
|
||||||
});
|
|
||||||
oldReaction.forEach(r => this.remove(r));
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,22 +177,22 @@ export class Reactions extends Collection<ReactionModel> {
|
||||||
storyReactionEmoji: reaction.get('emoji'),
|
storyReactionEmoji: reaction.get('emoji'),
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all([
|
const [generatedMessageId] = await Promise.all([
|
||||||
window.Signal.Data.saveMessage(generatedMessage.attributes, {
|
window.Signal.Data.saveMessage(generatedMessage.attributes, {
|
||||||
ourUuid: window.textsecure.storage.user
|
ourUuid: window.textsecure.storage.user
|
||||||
.getCheckedUuid()
|
.getCheckedUuid()
|
||||||
.toString(),
|
.toString(),
|
||||||
forceSave: true,
|
|
||||||
}),
|
}),
|
||||||
generatedMessage.hydrateStoryContext(message),
|
generatedMessage.hydrateStoryContext(message),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
targetConversation.addSingleMessage(
|
generatedMessage.set({ id: generatedMessageId });
|
||||||
window.MessageController.register(
|
|
||||||
generatedMessage.id,
|
const messageToAdd = window.MessageController.register(
|
||||||
generatedMessage
|
generatedMessageId,
|
||||||
)
|
generatedMessage
|
||||||
);
|
);
|
||||||
|
targetConversation.addSingleMessage(messageToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
await message.handleReaction(reaction);
|
await message.handleReaction(reaction);
|
||||||
|
|
|
@ -826,18 +826,11 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
const { attributes } = this;
|
const { attributes } = this;
|
||||||
|
|
||||||
if (attributes.storyReactionEmoji) {
|
if (attributes.storyReactionEmoji) {
|
||||||
const conversation = this.getConversation();
|
if (!window.Signal.OS.isLinux()) {
|
||||||
const firstName = conversation?.attributes.profileName;
|
return attributes.storyReactionEmoji;
|
||||||
|
|
||||||
if (!conversation || !firstName) {
|
|
||||||
return window.i18n('Quote__story-reaction--single');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMe(conversation.attributes)) {
|
return window.i18n('Quote__story-reaction--single');
|
||||||
return window.i18n('Quote__story-reaction--yours');
|
|
||||||
}
|
|
||||||
|
|
||||||
return window.i18n('Quote__story-reaction', [firstName]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let modifiedText = text;
|
let modifiedText = text;
|
||||||
|
|
Loading…
Reference in a new issue