Storage Service: Fetch updates on any group record merge
This commit is contained in:
parent
a527b88867
commit
85cf445924
6 changed files with 153 additions and 97 deletions
|
@ -137,7 +137,7 @@ import {
|
|||
ViewSyncEvent,
|
||||
} from './messageReceiverEvents';
|
||||
import * as log from '../logging/log';
|
||||
import { areArraysMatchingSets } from '../util/areArraysMatchingSets';
|
||||
import { diffArraysAsSets } from '../util/diffArraysAsSets';
|
||||
import { generateBlurHash } from '../util/generateBlurHash';
|
||||
import { TEXT_ATTACHMENT } from '../types/MIME';
|
||||
import type { SendTypesType } from '../util/handleMessageSend';
|
||||
|
@ -2187,16 +2187,6 @@ export default class MessageReceiver
|
|||
}
|
||||
|
||||
const message = this.processDecrypted(envelope, msg);
|
||||
const groupId = this.getProcessedGroupId(message);
|
||||
const isBlocked = groupId ? this.isGroupBlocked(groupId) : false;
|
||||
|
||||
if (groupId && isBlocked) {
|
||||
log.warn(
|
||||
`Message ${getEnvelopeId(envelope)} ignored; destined for blocked group`
|
||||
);
|
||||
this.removeFromCache(envelope);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const ev = new SentEvent(
|
||||
{
|
||||
|
@ -3849,42 +3839,63 @@ export default class MessageReceiver
|
|||
await this.dispatchAndWait(logId, contactSync);
|
||||
}
|
||||
|
||||
// This function calls applyMessageRequestResponse before setting window.storage so
|
||||
// proper before/after logic can be applied within that function.
|
||||
private async handleBlocked(
|
||||
envelope: ProcessedEnvelope,
|
||||
blocked: Proto.SyncMessage.IBlocked
|
||||
): Promise<void> {
|
||||
const allIdentifiers = [];
|
||||
let changed = false;
|
||||
|
||||
const logId = `handleBlocked(${getEnvelopeId(envelope)})`;
|
||||
const messageRequestEnum = Proto.SyncMessage.MessageRequestResponse.Type;
|
||||
|
||||
logUnexpectedUrgentValue(envelope, 'blockSync');
|
||||
|
||||
function getAndApply(
|
||||
type: Proto.SyncMessage.MessageRequestResponse.Type
|
||||
): (value: string) => Promise<void> {
|
||||
return async item => {
|
||||
const conversation = window.ConversationController.getOrCreate(
|
||||
item,
|
||||
'private'
|
||||
);
|
||||
await conversation.applyMessageRequestResponse(type, {
|
||||
fromSync: true,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
if (blocked.numbers) {
|
||||
const previous = this.storage.get('blocked', []);
|
||||
|
||||
log.info(`${logId}: Blocking these numbers:`, blocked.numbers);
|
||||
await this.storage.put('blocked', blocked.numbers);
|
||||
|
||||
if (!areArraysMatchingSets(previous, blocked.numbers)) {
|
||||
changed = true;
|
||||
allIdentifiers.push(...previous);
|
||||
allIdentifiers.push(...blocked.numbers);
|
||||
const { added, removed } = diffArraysAsSets(previous, blocked.numbers);
|
||||
if (added.length) {
|
||||
await Promise.all(added.map(getAndApply(messageRequestEnum.BLOCK)));
|
||||
}
|
||||
if (removed.length) {
|
||||
await Promise.all(removed.map(getAndApply(messageRequestEnum.ACCEPT)));
|
||||
}
|
||||
|
||||
log.info(`${logId}: New e164 blocks:`, added);
|
||||
log.info(`${logId}: New e164 unblocks:`, removed);
|
||||
await this.storage.put('blocked', blocked.numbers);
|
||||
}
|
||||
if (blocked.acis) {
|
||||
const previous = this.storage.get('blocked-uuids', []);
|
||||
const acis = blocked.acis.map((aci, index) => {
|
||||
return normalizeAci(aci, `handleBlocked.acis.${index}`);
|
||||
});
|
||||
log.info(`${logId}: Blocking these acis:`, acis);
|
||||
await this.storage.put('blocked-uuids', acis);
|
||||
|
||||
if (!areArraysMatchingSets(previous, acis)) {
|
||||
changed = true;
|
||||
allIdentifiers.push(...previous);
|
||||
allIdentifiers.push(...blocked.acis);
|
||||
const { added, removed } = diffArraysAsSets(previous, acis);
|
||||
if (added.length) {
|
||||
await Promise.all(added.map(getAndApply(messageRequestEnum.BLOCK)));
|
||||
}
|
||||
if (removed.length) {
|
||||
await Promise.all(removed.map(getAndApply(messageRequestEnum.ACCEPT)));
|
||||
}
|
||||
|
||||
log.info(`${logId}: New aci blocks:`, added);
|
||||
log.info(`${logId}: New aci unblocks:`, removed);
|
||||
await this.storage.put('blocked-uuids', acis);
|
||||
}
|
||||
|
||||
if (blocked.groupIds) {
|
||||
|
@ -3898,27 +3909,55 @@ export default class MessageReceiver
|
|||
log.error(`${logId}: Received invalid groupId value`);
|
||||
}
|
||||
});
|
||||
log.info(
|
||||
`${logId}: Blocking these groups - v2:`,
|
||||
groupIds.map(groupId => `groupv2(${groupId})`)
|
||||
);
|
||||
|
||||
await this.storage.put('blocked-groups', groupIds);
|
||||
|
||||
if (!areArraysMatchingSets(previous, groupIds)) {
|
||||
changed = true;
|
||||
allIdentifiers.push(...previous);
|
||||
allIdentifiers.push(...groupIds);
|
||||
const { added, removed } = diffArraysAsSets(previous, groupIds);
|
||||
if (added.length) {
|
||||
await Promise.all(
|
||||
added.map(async item => {
|
||||
const conversation = window.ConversationController.get(item);
|
||||
if (!conversation) {
|
||||
log.warn(`${logId}: Group groupv2(${item}) not found!`);
|
||||
return;
|
||||
}
|
||||
await conversation.applyMessageRequestResponse(
|
||||
messageRequestEnum.BLOCK,
|
||||
{
|
||||
fromSync: true,
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
if (removed.length) {
|
||||
await Promise.all(
|
||||
removed.map(async item => {
|
||||
const conversation = window.ConversationController.get(item);
|
||||
if (!conversation) {
|
||||
log.warn(`${logId}: Group groupv2(${item}) not found!`);
|
||||
return;
|
||||
}
|
||||
await conversation.applyMessageRequestResponse(
|
||||
messageRequestEnum.ACCEPT,
|
||||
{
|
||||
fromSync: true,
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
log.info(
|
||||
`${logId}: New groupId blocks:`,
|
||||
added.map(groupId => `groupv2(${groupId})`)
|
||||
);
|
||||
log.info(
|
||||
`${logId}: New groupId unblocks:`,
|
||||
removed.map(groupId => `groupv2(${groupId})`)
|
||||
);
|
||||
await this.storage.put('blocked-groups', groupIds);
|
||||
}
|
||||
|
||||
this.removeFromCache(envelope);
|
||||
|
||||
if (changed) {
|
||||
log.info(`${logId}: Block list changed, forcing re-render.`);
|
||||
const uniqueIdentifiers = Array.from(new Set(allIdentifiers));
|
||||
void window.ConversationController.forceRerender(uniqueIdentifiers);
|
||||
}
|
||||
}
|
||||
|
||||
private isBlocked(number: string): boolean {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue