use conversation and conversationOrigin instead sendingConversation in message.js

pull/1137/head
Audric Ackermann 5 years ago
parent 93581874b8
commit 3c9bf34648
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -448,7 +448,7 @@
// If you don't have a profile name for this device, and profileName is set,
// add profileName to conversation.
const primaryDevicePubKey =
(await libloki.storage.getPrimaryDeviceFor(devicePubKey)) ||
(await window.Signal.Data.getPrimaryDeviceFor(devicePubKey)) ||
devicePubKey;
const primaryConversation = allConversationsWithUser.find(
c => c.id === primaryDevicePubKey
@ -2247,12 +2247,10 @@
return null;
}
}
const conversation = conversationPrimary;
// source = primarySource;
return conversation.queueJob(async () => {
return conversationPrimary.queueJob(async () => {
window.log.info(
`Starting handleDataMessage for message ${message.idForLogging()} in conversation ${conversation.idForLogging()}`
`Starting handleDataMessage for message ${message.idForLogging()} in conversation ${conversationPrimary.idForLogging()}`
);
const GROUP_TYPES = textsecure.protobuf.GroupContext.Type;
const type = message.get('type');
@ -2265,7 +2263,7 @@
try {
const now = new Date().getTime();
let attributes = {
...conversation.attributes,
...conversationPrimary.attributes,
};
if (dataMessage.group) {
@ -2283,18 +2281,18 @@
};
groupUpdate =
conversation.changedAttributes(
conversationPrimary.changedAttributes(
_.pick(dataMessage.group, 'name', 'avatar')
) || {};
const addedMembers = _.difference(
attributes.members,
conversation.get('members')
conversationPrimary.get('members')
);
if (addedMembers.length > 0) {
groupUpdate.joined = addedMembers;
}
if (conversation.get('left')) {
if (conversationPrimary.get('left')) {
// TODO: Maybe we shouldn't assume this message adds us:
// we could maybe still get this message by mistake
window.log.warn('re-added to a left group');
@ -2308,7 +2306,7 @@
// Check if anyone got kicked:
const removedMembers = _.difference(
conversation.get('members'),
conversationPrimary.get('members'),
attributes.members
);
@ -2330,7 +2328,7 @@
groupUpdate = { left: source };
}
attributes.members = _.without(
conversation.get('members'),
conversationPrimary.get('members'),
source
);
}
@ -2363,7 +2361,7 @@
attachments: dataMessage.attachments,
body: dataMessage.body,
contact: dataMessage.contact,
conversationId: conversation.id,
conversationId: conversationPrimary.id,
decrypted_at: now,
errors: [],
flags: dataMessage.flags,
@ -2377,7 +2375,7 @@
if (type === 'outgoing') {
const receipts = Whisper.DeliveryReceipts.forMessage(
conversation,
conversationPrimary,
message
);
receipts.forEach(receipt =>
@ -2390,10 +2388,10 @@
);
}
attributes.active_at = now;
conversation.set(attributes);
conversationPrimary.set(attributes);
// Re-enable typing if re-joined the group
conversation.updateTextInputState();
conversationPrimary.updateTextInputState();
if (message.isExpirationTimerUpdate()) {
message.set({
@ -2402,7 +2400,7 @@
expireTimer: dataMessage.expireTimer,
},
});
conversation.set({ expireTimer: dataMessage.expireTimer });
conversationPrimary.set({ expireTimer: dataMessage.expireTimer });
} else if (dataMessage.expireTimer) {
message.set({ expireTimer: dataMessage.expireTimer });
}
@ -2414,7 +2412,7 @@
message.isExpirationTimerUpdate() || expireTimer;
if (shouldLogExpireTimerChange) {
window.log.info("Update conversation 'expireTimer'", {
id: conversation.idForLogging(),
id: conversationPrimary.idForLogging(),
expireTimer,
source: 'handleDataMessage',
});
@ -2422,8 +2420,8 @@
if (!message.isEndSession()) {
if (dataMessage.expireTimer) {
if (dataMessage.expireTimer !== conversation.get('expireTimer')) {
conversation.updateExpirationTimer(
if (dataMessage.expireTimer !== conversationPrimary.get('expireTimer')) {
conversationPrimary.updateExpirationTimer(
dataMessage.expireTimer,
source,
message.get('received_at'),
@ -2433,18 +2431,18 @@
);
}
} else if (
conversation.get('expireTimer') &&
conversationPrimary.get('expireTimer') &&
// We only turn off timers if it's not a group update
!message.isGroupUpdate()
) {
conversation.updateExpirationTimer(
conversationPrimary.updateExpirationTimer(
null,
source,
message.get('received_at')
);
}
} else {
const endSessionType = conversation.isSessionResetReceived()
const endSessionType = conversationPrimary.isSessionResetReceived()
? 'ongoing'
: 'done';
this.set({ endSessionType });
@ -2476,11 +2474,11 @@
message.attributes.body &&
message.attributes.body.indexOf(`@${ourNumber}`) !== -1
) {
conversation.set({ mentionedUs: true });
conversationPrimary.set({ mentionedUs: true });
}
conversation.set({
unreadCount: conversation.get('unreadCount') + 1,
conversationPrimary.set({
unreadCount: conversationPrimary.get('unreadCount') + 1,
isArchived: false,
});
}
@ -2488,7 +2486,7 @@
if (type === 'outgoing') {
const reads = Whisper.ReadReceipts.forMessage(
conversation,
conversationPrimary,
message
);
if (reads.length) {
@ -2499,39 +2497,35 @@
}
// A sync'd message to ourself is automatically considered read and delivered
if (conversation.isMe()) {
if (conversationPrimary.isMe()) {
message.set({
read_by: conversation.getRecipients(),
delivered_to: conversation.getRecipients(),
read_by: conversationPrimary.getRecipients(),
delivered_to: conversationPrimary.getRecipients(),
});
}
message.set({ recipients: conversation.getRecipients() });
message.set({ recipients: conversationPrimary.getRecipients() });
}
const conversationTimestamp = conversation.get('timestamp');
const conversationTimestamp = conversationPrimary.get('timestamp');
if (
!conversationTimestamp ||
message.get('sent_at') > conversationTimestamp
) {
conversation.lastMessage = message.getNotificationText();
conversation.set({
conversationPrimary.lastMessage = message.getNotificationText();
conversationPrimary.set({
timestamp: message.get('sent_at'),
});
}
const sendingDeviceConversation = await ConversationController.getOrCreateAndWait(
primarySource,
'private'
);
if (dataMessage.profileKey) {
const profileKey = dataMessage.profileKey.toString('base64');
if (source === textsecure.storage.user.getNumber()) {
conversation.set({ profileSharing: true });
} else if (conversation.isPrivate()) {
conversation.setProfileKey(profileKey);
conversationPrimary.set({ profileSharing: true });
} else if (conversationPrimary.isPrivate()) {
conversationPrimary.setProfileKey(profileKey);
} else {
sendingDeviceConversation.setProfileKey(profileKey);
conversationOrigin.setProfileKey(profileKey);
}
}
@ -2558,8 +2552,8 @@
and that user just sent us a friend request.
*/
const isFriend = sendingDeviceConversation.isFriend();
const hasSentFriendRequest = sendingDeviceConversation.hasSentFriendRequest();
const isFriend = conversationOrigin.isFriend();
const hasSentFriendRequest = conversationOrigin.hasSentFriendRequest();
autoAccept = isFriend || hasSentFriendRequest;
if (autoAccept) {
@ -2573,13 +2567,13 @@
if (isFriend) {
window.Whisper.events.trigger('endSession', source);
} else if (hasSentFriendRequest) {
await sendingDeviceConversation.onFriendRequestAccepted();
await conversationOrigin.onFriendRequestAccepted();
} else {
await sendingDeviceConversation.onFriendRequestReceived();
await conversationOrigin.onFriendRequestReceived();
}
} else if (message.get('type') !== 'outgoing') {
// Ignore 'outgoing' messages because they are sync messages
await sendingDeviceConversation.onFriendRequestAccepted();
await conversationOrigin.onFriendRequestAccepted();
}
}
@ -2601,11 +2595,11 @@
await window.Signal.Data.updateConversation(
conversationId,
conversation.attributes,
conversationPrimary.attributes,
{ Conversation: Whisper.Conversation }
);
conversation.trigger('newmessage', message);
conversationPrimary.trigger('newmessage', message);
try {
// We go to the database here because, between the message save above and
@ -2643,9 +2637,9 @@
if (message.get('unread')) {
// Need to do this here because the conversation has already changed states
if (autoAccept) {
await conversation.notifyFriendRequest(source, 'accepted');
await conversationPrimary.notifyFriendRequest(source, 'accepted');
} else {
await conversation.notify(message);
await conversationPrimary.notify(message);
}
}

Loading…
Cancel
Save