fallback to envelope timestamp if dataMessage.timestamp is 0

pull/1608/head
Audric Ackermann 4 years ago
parent e10a3cd4a9
commit e6d78d5830
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -752,6 +752,7 @@
initAPIs(); initAPIs();
await initSpecialConversations(); await initSpecialConversations();
messageReceiver = new textsecure.MessageReceiver(); messageReceiver = new textsecure.MessageReceiver();
// those handleMessageEvent calls are only used by opengroupv1
messageReceiver.addEventListener('message', window.DataMessageReceiver.handleMessageEvent); messageReceiver.addEventListener('message', window.DataMessageReceiver.handleMessageEvent);
messageReceiver.addEventListener('sent', window.DataMessageReceiver.handleMessageEvent); messageReceiver.addEventListener('sent', window.DataMessageReceiver.handleMessageEvent);
messageReceiver.addEventListener('reconnect', onReconnect); messageReceiver.addEventListener('reconnect', onReconnect);

@ -230,6 +230,11 @@ export async function processDecrypted(
cleanAttachments(decrypted); cleanAttachments(decrypted);
// if the decrypted dataMessage timestamp is not set, copy the one from the envelope
if (!_.toNumber(decrypted?.timestamp)) {
decrypted.timestamp = envelope.timestamp;
}
return decrypted as SignalService.DataMessage; return decrypted as SignalService.DataMessage;
/* tslint:disable:no-bitwise */ /* tslint:disable:no-bitwise */
} }
@ -325,6 +330,7 @@ export async function handleDataMessage(
} }
ev.confirm = () => removeFromCache(envelope); ev.confirm = () => removeFromCache(envelope);
ev.data = { ev.data = {
source: senderPubKey, source: senderPubKey,
destination: isMe ? message.syncTarget : undefined, destination: isMe ? message.syncTarget : undefined,
@ -416,17 +422,13 @@ export const isDuplicate = (
) => { ) => {
// The username in this case is the users pubKey // The username in this case is the users pubKey
const sameUsername = m.attributes.source === source; const sameUsername = m.attributes.source === source;
// testedMessage.id is needed as long as we support opengroupv1
const sameServerId =
m.attributes.serverId !== undefined &&
(testedMessage.serverId || testedMessage.id) === m.attributes.serverId;
const sameText = m.attributes.body === testedMessage.body; const sameText = m.attributes.body === testedMessage.body;
// Don't filter out messages that are too far apart from each other // Don't filter out messages that are too far apart from each other
const timestampsSimilar = const timestampsSimilar =
Math.abs(m.attributes.sent_at - testedMessage.timestamp) <= Math.abs(m.attributes.sent_at - testedMessage.timestamp) <=
PUBLICCHAT_MIN_TIME_BETWEEN_DUPLICATE_MESSAGES; PUBLICCHAT_MIN_TIME_BETWEEN_DUPLICATE_MESSAGES;
return sameUsername && sameText && (timestampsSimilar || sameServerId); return sameUsername && sameText && timestampsSimilar;
}; };
async function handleProfileUpdate( async function handleProfileUpdate(

@ -273,6 +273,10 @@ async function handleDecryptedEnvelope(envelope: EnvelopePlus, plaintext: ArrayB
} }
} }
/**
* Only used for opengroupv1 it seems.
* To be removed soon
*/
export async function handlePublicMessage(messageData: any) { export async function handlePublicMessage(messageData: any) {
const { source } = messageData; const { source } = messageData;
const { group, profile, profileKey } = messageData.message; const { group, profile, profileKey } = messageData.message;
@ -302,7 +306,7 @@ export async function handlePublicMessage(messageData: any) {
}, },
}; };
await handleMessageEvent(ev); // open groups await handleMessageEvent(ev); // open groups v1
} }
export async function handleOpenGroupV2Message( export async function handleOpenGroupV2Message(

Loading…
Cancel
Save