Improve handling of DOE sync messages for stories
This commit is contained in:
parent
9d8ad21819
commit
d1b505d580
3 changed files with 40 additions and 10 deletions
|
@ -3564,7 +3564,12 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
del: DeleteModel,
|
del: DeleteModel,
|
||||||
shouldPersist = true
|
shouldPersist = true
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
if (this.deletingForEveryone || this.get('deletedForEveryone')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
log.info('Handling DOE.', {
|
log.info('Handling DOE.', {
|
||||||
|
messageId: this.id,
|
||||||
fromId: del.get('fromId'),
|
fromId: del.get('fromId'),
|
||||||
targetSentTimestamp: del.get('targetSentTimestamp'),
|
targetSentTimestamp: del.get('targetSentTimestamp'),
|
||||||
messageServerTimestamp: this.get('serverTimestamp'),
|
messageServerTimestamp: this.get('serverTimestamp'),
|
||||||
|
|
|
@ -5,18 +5,27 @@ import type { DeleteModel } from '../messageModifiers/Deletes';
|
||||||
import type { MessageModel } from '../models/messages';
|
import type { MessageModel } from '../models/messages';
|
||||||
import * as log from '../logging/log';
|
import * as log from '../logging/log';
|
||||||
import { DAY } from './durations';
|
import { DAY } from './durations';
|
||||||
|
import { isMe } from './whatTypeOfConversation';
|
||||||
import { getContactId } from '../messages/helpers';
|
import { getContactId } from '../messages/helpers';
|
||||||
|
import { isStory } from '../state/selectors/message';
|
||||||
|
|
||||||
export async function deleteForEveryone(
|
export async function deleteForEveryone(
|
||||||
message: MessageModel,
|
message: MessageModel,
|
||||||
doe: DeleteModel,
|
doe: DeleteModel,
|
||||||
shouldPersist = true
|
shouldPersist = true
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (message.deletingForEveryone || message.get('deletedForEveryone')) {
|
if (isDeletionByMe(message, doe)) {
|
||||||
|
const conversation = message.getConversation();
|
||||||
|
|
||||||
|
// Our 1:1 stories are deleted through ts/util/onStoryRecipientUpdate.ts
|
||||||
|
if (
|
||||||
|
isStory(message.attributes) &&
|
||||||
|
conversation &&
|
||||||
|
isMe(conversation.attributes)
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDeletionByMe(message, doe)) {
|
|
||||||
await message.handleDeleteForEveryone(doe, shouldPersist);
|
await message.handleDeleteForEveryone(doe, shouldPersist);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,13 @@ import { isEqual } from 'lodash';
|
||||||
import type { DeleteAttributesType } from '../messageModifiers/Deletes';
|
import type { DeleteAttributesType } from '../messageModifiers/Deletes';
|
||||||
import type { StoryRecipientUpdateEvent } from '../textsecure/messageReceiverEvents';
|
import type { StoryRecipientUpdateEvent } from '../textsecure/messageReceiverEvents';
|
||||||
import * as log from '../logging/log';
|
import * as log from '../logging/log';
|
||||||
import { Deletes } from '../messageModifiers/Deletes';
|
import { DeleteModel } from '../messageModifiers/Deletes';
|
||||||
import { SendStatus } from '../messages/MessageSendState';
|
import { SendStatus } from '../messages/MessageSendState';
|
||||||
import { deleteForEveryone } from './deleteForEveryone';
|
|
||||||
import { getConversationIdForLogging } from './idForLogging';
|
import { getConversationIdForLogging } from './idForLogging';
|
||||||
import { isStory } from '../state/selectors/message';
|
import { isStory } from '../state/selectors/message';
|
||||||
import { normalizeUuid } from './normalizeUuid';
|
import { normalizeUuid } from './normalizeUuid';
|
||||||
import { queueUpdateMessage } from './messageBatcher';
|
import { queueUpdateMessage } from './messageBatcher';
|
||||||
|
import { isMe } from './whatTypeOfConversation';
|
||||||
|
|
||||||
export async function onStoryRecipientUpdate(
|
export async function onStoryRecipientUpdate(
|
||||||
event: StoryRecipientUpdateEvent
|
event: StoryRecipientUpdateEvent
|
||||||
|
@ -25,7 +25,12 @@ export async function onStoryRecipientUpdate(
|
||||||
const logId = `onStoryRecipientUpdate(${destinationUuid}, ${timestamp})`;
|
const logId = `onStoryRecipientUpdate(${destinationUuid}, ${timestamp})`;
|
||||||
|
|
||||||
if (!conversation) {
|
if (!conversation) {
|
||||||
log.info(`${logId}: no conversation`);
|
log.warn(`${logId}: no conversation`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isMe(conversation.attributes)) {
|
||||||
|
log.warn(`${logId}: story recipient update on invalid conversation`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +52,13 @@ export async function onStoryRecipientUpdate(
|
||||||
const isAllowedToReply = new Map<string, boolean>();
|
const isAllowedToReply = new Map<string, boolean>();
|
||||||
const distributionListIdToConversationIds = new Map<string, Set<string>>();
|
const distributionListIdToConversationIds = new Map<string, Set<string>>();
|
||||||
data.storyMessageRecipients.forEach(item => {
|
data.storyMessageRecipients.forEach(item => {
|
||||||
const convo = window.ConversationController.get(item.destinationUuid);
|
if (!item.destinationUuid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const convo = window.ConversationController.get(
|
||||||
|
normalizeUuid(item.destinationUuid, `${logId}.destinationUuid`)
|
||||||
|
);
|
||||||
|
|
||||||
if (!convo || !item.distributionListIds) {
|
if (!convo || !item.distributionListIds) {
|
||||||
return;
|
return;
|
||||||
|
@ -161,11 +172,16 @@ export async function onStoryRecipientUpdate(
|
||||||
serverTimestamp: Number(item.serverTimestamp),
|
serverTimestamp: Number(item.serverTimestamp),
|
||||||
targetSentTimestamp: item.timestamp,
|
targetSentTimestamp: item.timestamp,
|
||||||
};
|
};
|
||||||
const doe = Deletes.getSingleton().add(delAttributes);
|
const doe = new DeleteModel(delAttributes);
|
||||||
|
|
||||||
// There are no longer any remaining members for this message so lets
|
// There are no longer any remaining members for this message so lets
|
||||||
// run it through deleteForEveryone which marks the message as
|
// run it through deleteForEveryone which marks the message as
|
||||||
// deletedForEveryone locally.
|
// deletedForEveryone locally.
|
||||||
deleteForEveryone(message, doe);
|
//
|
||||||
|
// NOTE: We don't call `Deletes.onDelete()` so the message lookup by
|
||||||
|
// sent timestamp doesn't happen (it would return all copies of the
|
||||||
|
// story, not just the one we want to delete).
|
||||||
|
message.handleDeleteForEveryone(doe);
|
||||||
} else {
|
} else {
|
||||||
message.set({
|
message.set({
|
||||||
sendStateByConversationId: nextSendStateByConversationId,
|
sendStateByConversationId: nextSendStateByConversationId,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue