fix: fix synced messages sometimes not appearing
This commit is contained in:
parent
82e079832d
commit
e98c9720c8
|
@ -35,6 +35,7 @@ import { getAllCachedECKeyPair, sentAtMoreRecentThanWrapper } from './closedGrou
|
|||
import { ConfigMessageHandler } from './configMessage';
|
||||
import { ECKeyPair } from './keypairs';
|
||||
import { ContactsWrapperActions } from '../webworker/workers/browser/libsession_worker_interface';
|
||||
import { isUsFromCache } from '../session/utils/User';
|
||||
|
||||
export async function handleSwarmContentMessage(envelope: EnvelopePlus, messageHash: string) {
|
||||
try {
|
||||
|
@ -292,27 +293,42 @@ async function decrypt(envelope: EnvelopePlus): Promise<any> {
|
|||
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
|
||||
const moreRecentOrNah = await sentAtMoreRecentThanWrapper(sentAtTimestamp, 'ContactsConfig');
|
||||
const isSyncedMessage = isUsFromCache(envelope.source);
|
||||
|
||||
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 {
|
||||
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 (
|
||||
!privateConvoInWrapper ||
|
||||
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.
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
window.log.warn(
|
||||
|
@ -409,7 +425,7 @@ export async function innerHandleSwarmContentMessage(
|
|||
const isPrivateConversationMessage = !envelope.senderIdentity;
|
||||
|
||||
if (isPrivateConversationMessage) {
|
||||
if (await shouldDropIncomingPrivateMessage(sentAtTimestamp, envelope)) {
|
||||
if (await shouldDropIncomingPrivateMessage(sentAtTimestamp, envelope, content)) {
|
||||
await removeFromCache(envelope);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue