|
|
|
@ -297,9 +297,13 @@ export async function handleDataMessage(
|
|
|
|
|
|
|
|
|
|
const message = await processDecrypted(envelope, dataMessage);
|
|
|
|
|
const ourPubKey = window.textsecure.storage.user.getNumber();
|
|
|
|
|
const source = envelope.source;
|
|
|
|
|
const senderPubKey = envelope.senderIdentity || envelope.source;
|
|
|
|
|
const isMe = senderPubKey === ourPubKey;
|
|
|
|
|
const conversation = ConversationController.getInstance().get(senderPubKey);
|
|
|
|
|
const senderConversation = await ConversationController.getInstance().getOrCreateAndWait(
|
|
|
|
|
senderPubKey,
|
|
|
|
|
'private'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { UNPAIRING_REQUEST } = SignalService.DataMessage.Flags;
|
|
|
|
|
|
|
|
|
@ -311,18 +315,22 @@ export async function handleDataMessage(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if we need to update any profile names
|
|
|
|
|
if (!isMe && conversation && message.profile) {
|
|
|
|
|
await updateProfile(conversation, message.profile, message.profileKey);
|
|
|
|
|
if (!isMe && senderConversation && message.profile) {
|
|
|
|
|
await updateProfile(
|
|
|
|
|
senderConversation,
|
|
|
|
|
message.profile,
|
|
|
|
|
message.profileKey
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (isMessageEmpty(message)) {
|
|
|
|
|
window.log.warn(`Message ${getEnvelopeId(envelope)} ignored; it was empty`);
|
|
|
|
|
return removeFromCache(envelope);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const source = envelope.senderIdentity || senderPubKey;
|
|
|
|
|
const ownDevice = await MultiDeviceProtocol.isOurDevice(source);
|
|
|
|
|
const ownDevice = await MultiDeviceProtocol.isOurDevice(senderPubKey);
|
|
|
|
|
|
|
|
|
|
const ownMessage = conversation?.isMediumGroup() && ownDevice;
|
|
|
|
|
const sourceConversation = ConversationController.getInstance().get(source);
|
|
|
|
|
const ownMessage = sourceConversation?.isMediumGroup() && ownDevice;
|
|
|
|
|
|
|
|
|
|
const ev: any = {};
|
|
|
|
|
if (ownMessage) {
|
|
|
|
@ -342,7 +350,7 @@ export async function handleDataMessage(
|
|
|
|
|
|
|
|
|
|
ev.confirm = () => removeFromCache(envelope);
|
|
|
|
|
ev.data = {
|
|
|
|
|
source,
|
|
|
|
|
source: senderPubKey,
|
|
|
|
|
sourceDevice: envelope.sourceDevice,
|
|
|
|
|
timestamp: _.toNumber(envelope.timestamp),
|
|
|
|
|
receivedAt: envelope.receivedAt,
|
|
|
|
@ -599,20 +607,14 @@ export async function handleMessageEvent(event: MessageEvent): Promise<void> {
|
|
|
|
|
? ConversationType.GROUP
|
|
|
|
|
: ConversationType.PRIVATE;
|
|
|
|
|
|
|
|
|
|
const { PROFILE_KEY_UPDATE } = SignalService.DataMessage.Flags;
|
|
|
|
|
|
|
|
|
|
// tslint:disable-next-line: no-bitwise
|
|
|
|
|
const isProfileUpdate = Boolean(message.flags & PROFILE_KEY_UPDATE);
|
|
|
|
|
let conversationId = isIncoming ? source : destination;
|
|
|
|
|
if (isProfileUpdate) {
|
|
|
|
|
if (message.profileKey?.length) {
|
|
|
|
|
await handleProfileUpdate(
|
|
|
|
|
message.profileKey,
|
|
|
|
|
conversationId,
|
|
|
|
|
type,
|
|
|
|
|
isIncoming
|
|
|
|
|
);
|
|
|
|
|
confirm();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const msg = createMessage(data, isIncoming);
|
|
|
|
|