Merge pull request #1448 from Bilb/fix-profile-updates-forc-onvo

fix profile updates when flag is set (do not drop message)
pull/1449/head
Audric Ackermann 4 years ago committed by GitHub
commit b4c71c419a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -23,7 +23,7 @@ function MessageReceiver() {
// bind events
lokiPublicChatAPI.on(
'publicMessage',
window.NewReceiver.handleUnencryptedMessage
window.NewReceiver.handlePublicMessage
);
openGroupBound = true;
}

@ -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);

@ -276,7 +276,7 @@ async function handleDecryptedEnvelope(
}
}
export async function handleUnencryptedMessage({ message: outerMessage }: any) {
export async function handlePublicMessage({ message: outerMessage }: any) {
const { source } = outerMessage;
const { group, profile, profileKey } = outerMessage.message;
@ -295,9 +295,15 @@ export async function handleUnencryptedMessage({ message: outerMessage }: any) {
const isPublicChatMessage =
group && group.id && !!group.id.match(/^publicChat:/);
if (!isPublicChatMessage) {
throw new Error(
'handlePublicMessage Should only be called with public message groups'
);
}
const ev = {
// Public chat messages from ourselves should be outgoing
type: isPublicChatMessage && isOurDevice ? 'sent' : 'message',
type: isOurDevice ? 'sent' : 'message',
data: outerMessage,
confirm: () => {
/* do nothing */

Loading…
Cancel
Save