fix: fix synced messages sometimes not appearing

This commit is contained in:
Audric Ackermann 2023-09-05 16:40:16 +10:00
parent 82e079832d
commit e98c9720c8
1 changed files with 22 additions and 6 deletions

View File

@ -35,6 +35,7 @@ import { getAllCachedECKeyPair, sentAtMoreRecentThanWrapper } from './closedGrou
import { ConfigMessageHandler } from './configMessage'; import { ConfigMessageHandler } from './configMessage';
import { ECKeyPair } from './keypairs'; import { ECKeyPair } from './keypairs';
import { ContactsWrapperActions } from '../webworker/workers/browser/libsession_worker_interface'; import { ContactsWrapperActions } from '../webworker/workers/browser/libsession_worker_interface';
import { isUsFromCache } from '../session/utils/User';
export async function handleSwarmContentMessage(envelope: EnvelopePlus, messageHash: string) { export async function handleSwarmContentMessage(envelope: EnvelopePlus, messageHash: string) {
try { try {
@ -292,27 +293,42 @@ async function decrypt(envelope: EnvelopePlus): Promise<any> {
return plaintext; return plaintext;
} }
async function shouldDropIncomingPrivateMessage(sentAtTimestamp: number, envelope: EnvelopePlus) { async function shouldDropIncomingPrivateMessage(
sentAtTimestamp: number,
envelope: EnvelopePlus,
content: SignalService.Content
) {
// sentAtMoreRecentThanWrapper is going to be true, if the latest contact wrapper we processed was roughly more recent that this message timestamp // sentAtMoreRecentThanWrapper is going to be true, if the latest contact wrapper we processed was roughly more recent that this message timestamp
const moreRecentOrNah = await sentAtMoreRecentThanWrapper(sentAtTimestamp, 'ContactsConfig'); const moreRecentOrNah = await sentAtMoreRecentThanWrapper(sentAtTimestamp, 'ContactsConfig');
const isSyncedMessage = isUsFromCache(envelope.source);
if (moreRecentOrNah === 'wrapper_more_recent') { if (moreRecentOrNah === 'wrapper_more_recent') {
// we need to check if that conversation is already in the wrapper, and if yes // we need to check if that conversation is already in the wrapper
try { try {
const privateConvoInWrapper = await ContactsWrapperActions.get(envelope.source); // let's check if the corresponding conversation is hidden in the contacts wrapper or not.
// the corresponding conversation is syncTarget when this is a synced message only, so we need to rely on it first, then the envelope.source.
const syncTargetOrSource = isSyncedMessage
? content.dataMessage?.syncTarget || undefined
: envelope.source;
if (!syncTargetOrSource) {
return false;
}
const privateConvoInWrapper = await ContactsWrapperActions.get(syncTargetOrSource);
if ( if (
!privateConvoInWrapper || !privateConvoInWrapper ||
privateConvoInWrapper.priority <= CONVERSATION_PRIORITIES.hidden privateConvoInWrapper.priority <= CONVERSATION_PRIORITIES.hidden
) { ) {
// the wrapper is more recent that this message and there is no such private conversation. Just drop this incoming message. // the wrapper is more recent that this message and there is no such private conversation. Just drop this incoming message.
window.log.info( window.log.info(
`received message from contact ${envelope.source} which appears to be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. Dropping it` `received message on conversation ${syncTargetOrSource} which appears to be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. Dropping it`
); );
return true; return true;
} }
window.log.info( window.log.info(
`received message from contact ${envelope.source} which appears to NOT be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. ` `received message on conversation ${syncTargetOrSource} which appears to NOT be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. `
); );
} catch (e) { } catch (e) {
window.log.warn( window.log.warn(
@ -409,7 +425,7 @@ export async function innerHandleSwarmContentMessage(
const isPrivateConversationMessage = !envelope.senderIdentity; const isPrivateConversationMessage = !envelope.senderIdentity;
if (isPrivateConversationMessage) { if (isPrivateConversationMessage) {
if (await shouldDropIncomingPrivateMessage(sentAtTimestamp, envelope)) { if (await shouldDropIncomingPrivateMessage(sentAtTimestamp, envelope, content)) {
await removeFromCache(envelope); await removeFromCache(envelope);
return; return;
} }