Receive support for editing messages
This commit is contained in:
parent
2781e621ad
commit
36e21c0134
46 changed files with 2053 additions and 405 deletions
|
@ -31,7 +31,7 @@ import { normalizeUuid } from '../util/normalizeUuid';
|
|||
import { clearTimeoutIfNecessary } from '../util/clearTimeoutIfNecessary';
|
||||
import type { AttachmentType, ThumbnailType } from '../types/Attachment';
|
||||
import { toDayMillis } from '../util/timestamp';
|
||||
import { isGIF, isVoiceMessage } from '../types/Attachment';
|
||||
import { isVoiceMessage } from '../types/Attachment';
|
||||
import type { CallHistoryDetailsType } from '../types/Calling';
|
||||
import { CallMode } from '../types/Calling';
|
||||
import * as Conversation from '../types/Conversation';
|
||||
|
@ -73,7 +73,7 @@ import { sniffImageMimeType } from '../util/sniffImageMimeType';
|
|||
import { isValidE164 } from '../util/isValidE164';
|
||||
import { canConversationBeUnarchived } from '../util/canConversationBeUnarchived';
|
||||
import type { MIMEType } from '../types/MIME';
|
||||
import { IMAGE_JPEG, IMAGE_GIF, IMAGE_WEBP } from '../types/MIME';
|
||||
import { IMAGE_JPEG, IMAGE_WEBP } from '../types/MIME';
|
||||
import { UUID, UUIDKind } from '../types/UUID';
|
||||
import type { UUIDStringType } from '../types/UUID';
|
||||
import {
|
||||
|
@ -108,15 +108,7 @@ import { ReadStatus } from '../messages/MessageReadStatus';
|
|||
import { SendStatus } from '../messages/MessageSendState';
|
||||
import type { LinkPreviewType } from '../types/message/LinkPreviews';
|
||||
import { MINUTE, SECOND, DurationInSeconds } from '../util/durations';
|
||||
import {
|
||||
concat,
|
||||
filter,
|
||||
map,
|
||||
take,
|
||||
repeat,
|
||||
zipObject,
|
||||
collect,
|
||||
} from '../util/iterables';
|
||||
import { concat, filter, map, repeat, zipObject } from '../util/iterables';
|
||||
import * as universalExpireTimer from '../util/universalExpireTimer';
|
||||
import type { GroupNameCollisionsWithIdsByTitle } from '../util/groupMemberNameCollisions';
|
||||
import {
|
||||
|
@ -130,10 +122,8 @@ import { SignalService as Proto } from '../protobuf';
|
|||
import {
|
||||
getMessagePropStatus,
|
||||
hasErrors,
|
||||
isGiftBadge,
|
||||
isIncoming,
|
||||
isStory,
|
||||
isTapToView,
|
||||
} from '../state/selectors/message';
|
||||
import {
|
||||
conversationJobQueue,
|
||||
|
@ -162,6 +152,7 @@ import { removePendingMember } from '../util/removePendingMember';
|
|||
import { isMemberPending } from '../util/isMemberPending';
|
||||
import { imageToBlurHash } from '../util/imageToBlurHash';
|
||||
import { ReceiptType } from '../types/Receipt';
|
||||
import { getQuoteAttachment } from '../util/makeQuote';
|
||||
|
||||
const EMPTY_ARRAY: Readonly<[]> = [];
|
||||
const EMPTY_GROUP_COLLISIONS: GroupNameCollisionsWithIdsByTitle = {};
|
||||
|
@ -175,7 +166,6 @@ const {
|
|||
deleteAttachmentData,
|
||||
doesAttachmentExist,
|
||||
getAbsoluteAttachmentPath,
|
||||
loadAttachmentData,
|
||||
readStickerData,
|
||||
upgradeMessageSchema,
|
||||
writeNewAttachmentData,
|
||||
|
@ -3860,109 +3850,7 @@ export class ConversationModel extends window.Backbone
|
|||
thumbnail: ThumbnailType | null;
|
||||
}>
|
||||
> {
|
||||
if (attachments && attachments.length) {
|
||||
const attachmentsToUse = Array.from(take(attachments, 1));
|
||||
const isGIFQuote = isGIF(attachmentsToUse);
|
||||
|
||||
return Promise.all(
|
||||
map(attachmentsToUse, async attachment => {
|
||||
const { path, fileName, thumbnail, contentType } = attachment;
|
||||
|
||||
if (!path) {
|
||||
return {
|
||||
contentType: isGIFQuote ? IMAGE_GIF : contentType,
|
||||
// Our protos library complains about this field being undefined, so we
|
||||
// force it to null
|
||||
fileName: fileName || null,
|
||||
thumbnail: null,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
contentType: isGIFQuote ? IMAGE_GIF : contentType,
|
||||
// Our protos library complains about this field being undefined, so we force
|
||||
// it to null
|
||||
fileName: fileName || null,
|
||||
thumbnail: thumbnail
|
||||
? {
|
||||
...(await loadAttachmentData(thumbnail)),
|
||||
objectUrl: thumbnail.path
|
||||
? getAbsoluteAttachmentPath(thumbnail.path)
|
||||
: undefined,
|
||||
}
|
||||
: null,
|
||||
};
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (preview && preview.length) {
|
||||
const previewImages = collect(preview, prev => prev.image);
|
||||
const previewImagesToUse = take(previewImages, 1);
|
||||
|
||||
return Promise.all(
|
||||
map(previewImagesToUse, async image => {
|
||||
const { contentType } = image;
|
||||
|
||||
return {
|
||||
contentType,
|
||||
// Our protos library complains about this field being undefined, so we
|
||||
// force it to null
|
||||
fileName: null,
|
||||
thumbnail: image
|
||||
? {
|
||||
...(await loadAttachmentData(image)),
|
||||
objectUrl: image.path
|
||||
? getAbsoluteAttachmentPath(image.path)
|
||||
: undefined,
|
||||
}
|
||||
: null,
|
||||
};
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (sticker && sticker.data && sticker.data.path) {
|
||||
const { path, contentType } = sticker.data;
|
||||
|
||||
return [
|
||||
{
|
||||
contentType,
|
||||
// Our protos library complains about this field being undefined, so we
|
||||
// force it to null
|
||||
fileName: null,
|
||||
thumbnail: {
|
||||
...(await loadAttachmentData(sticker.data)),
|
||||
objectUrl: path ? getAbsoluteAttachmentPath(path) : undefined,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
async makeQuote(quotedMessage: MessageModel): Promise<QuotedMessageType> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const contact = getContact(quotedMessage.attributes)!;
|
||||
const attachments = quotedMessage.get('attachments');
|
||||
const preview = quotedMessage.get('preview');
|
||||
const sticker = quotedMessage.get('sticker');
|
||||
|
||||
return {
|
||||
authorUuid: contact.get('uuid'),
|
||||
attachments: isTapToView(quotedMessage.attributes)
|
||||
? [{ contentType: IMAGE_JPEG, fileName: null }]
|
||||
: await this.getQuoteAttachment(attachments, preview, sticker),
|
||||
payment: quotedMessage.get('payment'),
|
||||
bodyRanges: quotedMessage.get('bodyRanges'),
|
||||
id: quotedMessage.get('sent_at'),
|
||||
isViewOnce: isTapToView(quotedMessage.attributes),
|
||||
isGiftBadge: isGiftBadge(quotedMessage.attributes),
|
||||
messageId: quotedMessage.get('id'),
|
||||
referencedMessageNotFound: false,
|
||||
text: quotedMessage.getQuoteBodyText(),
|
||||
};
|
||||
return getQuoteAttachment(attachments, preview, sticker);
|
||||
}
|
||||
|
||||
async sendStickerMessage(packId: string, stickerId: number): Promise<void> {
|
||||
|
|
|
@ -80,7 +80,6 @@ import { migrateLegacySendAttributes } from '../messages/migrateLegacySendAttrib
|
|||
import { getOwn } from '../util/getOwn';
|
||||
import { markRead, markViewed } from '../services/MessageUpdater';
|
||||
import { scheduleOptimizeFTS } from '../services/ftsOptimizer';
|
||||
import { isMessageUnread } from '../util/isMessageUnread';
|
||||
import {
|
||||
isDirectConversation,
|
||||
isGroup,
|
||||
|
@ -181,78 +180,10 @@ import {
|
|||
} from '../util/attachmentDownloadQueue';
|
||||
import { getTitleNoDefault, getNumber } from '../util/getTitle';
|
||||
import dataInterface from '../sql/Client';
|
||||
|
||||
function isSameUuid(
|
||||
a: UUID | string | null | undefined,
|
||||
b: UUID | string | null | undefined
|
||||
): boolean {
|
||||
return a != null && b != null && String(a) === String(b);
|
||||
}
|
||||
|
||||
async function shouldReplyNotifyUser(
|
||||
message: MessageModel,
|
||||
conversation: ConversationModel
|
||||
): Promise<boolean> {
|
||||
// Don't notify if the message has already been read
|
||||
if (!isMessageUnread(message.attributes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const storyId = message.get('storyId');
|
||||
|
||||
// If this is not a reply to a story, always notify.
|
||||
if (storyId == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Always notify if this is not a group
|
||||
if (!isGroup(conversation.attributes)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const matchedStory = window.reduxStore
|
||||
.getState()
|
||||
.stories.stories.find(story => {
|
||||
return story.messageId === storyId;
|
||||
});
|
||||
|
||||
// If we can't find the story, don't notify
|
||||
if (matchedStory == null) {
|
||||
log.warn("Couldn't find story for reply");
|
||||
return false;
|
||||
}
|
||||
|
||||
const currentUserId = window.textsecure.storage.user.getUuid();
|
||||
const storySourceId = matchedStory.sourceUuid;
|
||||
|
||||
const currentUserIdSource = isSameUuid(storySourceId, currentUserId);
|
||||
|
||||
// If the story is from the current user, always notify
|
||||
if (currentUserIdSource) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the story is from a different user, only notify if the user has
|
||||
// replied or reacted to the story
|
||||
|
||||
const replies = await dataInterface.getOlderMessagesByConversation({
|
||||
conversationId: conversation.id,
|
||||
limit: 9000,
|
||||
storyId,
|
||||
includeStoryReplies: true,
|
||||
});
|
||||
|
||||
const prevCurrentUserReply = replies.find(replyMessage => {
|
||||
return replyMessage.type === 'outgoing';
|
||||
});
|
||||
|
||||
if (prevCurrentUserReply != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise don't notify
|
||||
return false;
|
||||
}
|
||||
import * as Edits from '../messageModifiers/Edits';
|
||||
import { handleEditMessage } from '../util/handleEditMessage';
|
||||
import { getQuoteBodyText } from '../util/getQuoteBodyText';
|
||||
import { shouldReplyNotifyUser } from '../util/shouldReplyNotifyUser';
|
||||
|
||||
/* eslint-disable more/no-then */
|
||||
|
||||
|
@ -1184,14 +1115,15 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
}
|
||||
|
||||
this.set({
|
||||
isErased: true,
|
||||
attachments: [],
|
||||
body: '',
|
||||
bodyRanges: undefined,
|
||||
attachments: [],
|
||||
quote: undefined,
|
||||
contact: [],
|
||||
sticker: undefined,
|
||||
editHistory: undefined,
|
||||
isErased: true,
|
||||
preview: [],
|
||||
quote: undefined,
|
||||
sticker: undefined,
|
||||
...additionalProperties,
|
||||
});
|
||||
this.getConversation()?.debouncedUpdateLastMessage?.();
|
||||
|
@ -2045,7 +1977,8 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
queryMessage = matchingMessage;
|
||||
} else {
|
||||
log.info('copyFromQuotedMessage: db lookup needed', id);
|
||||
const messages = await window.Signal.Data.getMessagesBySentAt(id);
|
||||
const messages =
|
||||
await window.Signal.Data.getMessagesIncludingEditedBySentAt(id);
|
||||
const found = messages.find(item =>
|
||||
isQuoteAMatch(item, conversationId, result)
|
||||
);
|
||||
|
@ -2065,18 +1998,6 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
return result;
|
||||
}
|
||||
|
||||
getQuoteBodyText(): string | undefined {
|
||||
const storyReactionEmoji = this.get('storyReaction')?.emoji;
|
||||
const body = this.get('body');
|
||||
const embeddedContact = this.get('contact');
|
||||
const embeddedContactName =
|
||||
embeddedContact && embeddedContact.length > 0
|
||||
? EmbeddedContact.getName(embeddedContact[0])
|
||||
: '';
|
||||
|
||||
return body || embeddedContactName || storyReactionEmoji;
|
||||
}
|
||||
|
||||
async copyQuoteContentFromOriginal(
|
||||
originalMessage: MessageModel,
|
||||
quote: QuotedMessageType
|
||||
|
@ -2125,7 +2046,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
quote.isViewOnce = false;
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
quote.text = originalMessage.getQuoteBodyText();
|
||||
quote.text = getQuoteBodyText(originalMessage.attributes, quote.id);
|
||||
if (firstAttachment) {
|
||||
firstAttachment.thumbnail = null;
|
||||
}
|
||||
|
@ -3338,6 +3259,16 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
})
|
||||
);
|
||||
|
||||
// We want to make sure the message is saved first before applying any edits
|
||||
if (!isFirstRun) {
|
||||
const edits = Edits.forMessage(message);
|
||||
await Promise.all(
|
||||
edits.map(editAttributes =>
|
||||
handleEditMessage(message.attributes, editAttributes)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (changed && !isFirstRun) {
|
||||
log.info(
|
||||
`modifyTargetMessage/${this.idForLogging()}: Changes in second run; saving.`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue