fix: repaired reaction notifications for 1-1s

pull/2454/head
William Grant 3 years ago
parent dde61bb35b
commit f309bf40f8

@ -22,6 +22,7 @@ import { appendFetchAvatarAndProfileJob } from './userProfileImageUpdates';
import { toLogFormat } from '../types/attachments/Errors'; import { toLogFormat } from '../types/attachments/Errors';
import { ConversationTypeEnum } from '../models/conversationAttributes'; import { ConversationTypeEnum } from '../models/conversationAttributes';
import { handleMessageReaction } from '../util/reactions'; import { handleMessageReaction } from '../util/reactions';
import { Action, Reaction } from '../types/Reaction';
function cleanAttachment(attachment: any) { function cleanAttachment(attachment: any) {
return { return {
@ -326,6 +327,15 @@ async function handleSwarmMessage(
msgModel.get('source'), msgModel.get('source'),
isUsFromCache(msgModel.get('source')) isUsFromCache(msgModel.get('source'))
); );
if (
convoToAddMessageTo.isPrivate() &&
msgModel.get('unread') &&
rawDataMessage.reaction.action === Action.REACT
) {
msgModel.set('reaction', rawDataMessage.reaction as Reaction);
convoToAddMessageTo.throttledNotify(msgModel);
}
confirm(); confirm();
return; return;
} }

@ -16,7 +16,6 @@ import { GoogleChrome } from '../util';
import { appendFetchAvatarAndProfileJob } from './userProfileImageUpdates'; import { appendFetchAvatarAndProfileJob } from './userProfileImageUpdates';
import { ConversationTypeEnum } from '../models/conversationAttributes'; import { ConversationTypeEnum } from '../models/conversationAttributes';
import { getUsBlindedInThatServer } from '../session/apis/open_group_api/sogsv3/knownBlindedkeys'; import { getUsBlindedInThatServer } from '../session/apis/open_group_api/sogsv3/knownBlindedkeys';
import { Action, Reaction } from '../types/Reaction';
function contentTypeSupported(type: string): boolean { function contentTypeSupported(type: string): boolean {
const Chrome = GoogleChrome; const Chrome = GoogleChrome;
@ -339,116 +338,103 @@ export async function handleMessageJob(
) || messageModel.get('timestamp')} in conversation ${conversation.idForLogging()}` ) || messageModel.get('timestamp')} in conversation ${conversation.idForLogging()}`
); );
if (!messageModel.get('isPublic') && regularDataMessage.reaction) { const sendingDeviceConversation = await getConversationController().getOrCreateAndWait(
if ( source,
regularDataMessage.reaction.action === Action.REACT && ConversationTypeEnum.PRIVATE
conversation.isPrivate() && );
messageModel.get('unread') try {
) { messageModel.set({ flags: regularDataMessage.flags });
messageModel.set('reaction', regularDataMessage.reaction as Reaction); if (messageModel.isExpirationTimerUpdate()) {
conversation.throttledNotify(messageModel); const { expireTimer } = regularDataMessage;
} const oldValue = conversation.get('expireTimer');
if (expireTimer === oldValue) {
confirm?.(); confirm?.();
} else { window?.log?.info(
const sendingDeviceConversation = await getConversationController().getOrCreateAndWait( 'Dropping ExpireTimerUpdate message as we already have the same one set.'
source,
ConversationTypeEnum.PRIVATE
);
try {
messageModel.set({ flags: regularDataMessage.flags });
if (messageModel.isExpirationTimerUpdate()) {
const { expireTimer } = regularDataMessage;
const oldValue = conversation.get('expireTimer');
if (expireTimer === oldValue) {
confirm?.();
window?.log?.info(
'Dropping ExpireTimerUpdate message as we already have the same one set.'
);
return;
}
await handleExpirationTimerUpdateNoCommit(conversation, messageModel, source, expireTimer);
} else {
// this does not commit to db nor UI unless we need to approve a convo
await handleRegularMessage(
conversation,
sendingDeviceConversation,
messageModel,
regularDataMessage,
source,
messageHash
); );
return;
} }
await handleExpirationTimerUpdateNoCommit(conversation, messageModel, source, expireTimer);
} else {
// this does not commit to db nor UI unless we need to approve a convo
await handleRegularMessage(
conversation,
sendingDeviceConversation,
messageModel,
regularDataMessage,
source,
messageHash
);
}
// save the message model to the db and it save the messageId generated to our in-memory copy // save the message model to the db and it save the messageId generated to our in-memory copy
const id = await messageModel.commit(); const id = await messageModel.commit();
messageModel.set({ id }); messageModel.set({ id });
// Note that this can save the message again, if jobs were queued. We need to
// call it after we have an id for this message, because the jobs refer back
// to their source message.
const unreadCount = await conversation.getUnreadCount();
conversation.set({ unreadCount });
conversation.set({
active_at: Math.max(conversation.attributes.active_at, messageModel.get('sent_at') || 0),
});
// this is a throttled call and will only run once every 1 sec at most
conversation.updateLastMessage();
await conversation.commit();
if (conversation.id !== sendingDeviceConversation.id) {
await sendingDeviceConversation.commit();
}
void queueAttachmentDownloads(messageModel, conversation); // Note that this can save the message again, if jobs were queued. We need to
// Check if we need to update any profile names // call it after we have an id for this message, because the jobs refer back
// the only profile we don't update with what is coming here is ours, // to their source message.
// as our profile is shared accross our devices with a ConfigurationMessage
if (messageModel.isIncoming() && regularDataMessage.profile) {
void appendFetchAvatarAndProfileJob(
sendingDeviceConversation,
regularDataMessage.profile,
regularDataMessage.profileKey
);
}
// even with all the warnings, I am very sus about if this is usefull or not const unreadCount = await conversation.getUnreadCount();
// try { conversation.set({ unreadCount });
// // We go to the database here because, between the message save above and conversation.set({
// // the previous line's trigger() call, we might have marked all messages active_at: Math.max(conversation.attributes.active_at, messageModel.get('sent_at') || 0),
// // unread in the database. This message might already be read! });
// const fetched = await getMessageById(messageModel.get('id')); // this is a throttled call and will only run once every 1 sec at most
conversation.updateLastMessage();
// const previousUnread = messageModel.get('unread'); await conversation.commit();
// // Important to update message with latest read state from database if (conversation.id !== sendingDeviceConversation.id) {
// messageModel.merge(fetched); await sendingDeviceConversation.commit();
}
// if (previousUnread !== messageModel.get('unread')) {
// window?.log?.warn( void queueAttachmentDownloads(messageModel, conversation);
// 'Caught race condition on new message read state! ' + 'Manually starting timers.' // Check if we need to update any profile names
// ); // the only profile we don't update with what is coming here is ours,
// // We call markRead() even though the message is already // as our profile is shared accross our devices with a ConfigurationMessage
// // marked read because we need to start expiration if (messageModel.isIncoming() && regularDataMessage.profile) {
// // timers, etc. void appendFetchAvatarAndProfileJob(
// await messageModel.markRead(Date.now()); sendingDeviceConversation,
// } regularDataMessage.profile,
// } catch (error) { regularDataMessage.profileKey
// window?.log?.warn( );
// 'handleMessageJob: Message', }
// messageModel.idForLogging(),
// 'was deleted' // even with all the warnings, I am very sus about if this is usefull or not
// ); // try {
// } // // We go to the database here because, between the message save above and
// // the previous line's trigger() call, we might have marked all messages
if (messageModel.get('unread')) { // // unread in the database. This message might already be read!
conversation.throttledNotify(messageModel); // const fetched = await getMessageById(messageModel.get('id'));
}
confirm?.(); // const previousUnread = messageModel.get('unread');
} catch (error) {
const errorForLog = error && error.stack ? error.stack : error; // // Important to update message with latest read state from database
window?.log?.error('handleMessageJob', messageModel.idForLogging(), 'error:', errorForLog); // messageModel.merge(fetched);
// if (previousUnread !== messageModel.get('unread')) {
// window?.log?.warn(
// 'Caught race condition on new message read state! ' + 'Manually starting timers.'
// );
// // We call markRead() even though the message is already
// // marked read because we need to start expiration
// // timers, etc.
// await messageModel.markRead(Date.now());
// }
// } catch (error) {
// window?.log?.warn(
// 'handleMessageJob: Message',
// messageModel.idForLogging(),
// 'was deleted'
// );
// }
if (messageModel.get('unread')) {
conversation.throttledNotify(messageModel);
} }
confirm?.();
} catch (error) {
const errorForLog = error && error.stack ? error.stack : error;
window?.log?.error('handleMessageJob', messageModel.idForLogging(), 'error:', errorForLog);
} }
} }

@ -125,10 +125,11 @@ export const sendMessageReaction = async (messageId: string, emoji: string) => {
emoji, emoji,
'reaction for message', 'reaction for message',
id, id,
found.get('isPublic') && found.get('isPublic')
`on ${conversationModel.toOpenGroupV2().serverUrl}/${ ? `on ${conversationModel.toOpenGroupV2().serverUrl}/${
conversationModel.toOpenGroupV2().roomId conversationModel.toOpenGroupV2().roomId
}` }`
: ''
); );
return reaction; return reaction;
} else { } else {

Loading…
Cancel
Save