This commit is contained in:
Mikunj 2019-04-17 12:01:19 +10:00
parent e343a04eea
commit 57195017f9
5 changed files with 72 additions and 68 deletions

View file

@ -8,7 +8,15 @@ const { remove: removeUserConfig } = require('./user_config');
const pify = require('pify');
const uuidv4 = require('uuid/v4');
const { map, isString, fromPairs, forEach, last, isEmpty, isObject } = require('lodash');
const {
map,
isString,
fromPairs,
forEach,
last,
isEmpty,
isObject,
} = require('lodash');
// To get long stack traces
// https://github.com/mapbox/node-sqlite3/wiki/API#sqlite3verbose

View file

@ -1342,7 +1342,7 @@
// Add the message sending on another queue so that our UI doesn't get blocked
this.queueMessageSend(async () => {
message.send(this.wrapSend(promise))
message.send(this.wrapSend(promise));
});
return true;

View file

@ -23,7 +23,7 @@
Contact,
PhoneNumber,
Attachment,
Errors
Errors,
} = Signal.Types;
const {

View file

@ -1021,74 +1021,71 @@ MessageReceiver.prototype.extend({
}
return p.then(() =>
this.processDecrypted(envelope, msg).then(async message => {
const groupId = message.group && message.group.id;
const isBlocked = this.isGroupBlocked(groupId);
const isMe = envelope.source === textsecure.storage.user.getNumber();
const conversation = window.ConversationController.get(
envelope.source
);
const isLeavingGroup = Boolean(
message.group &&
message.group.type === textsecure.protobuf.GroupContext.Type.QUIT
);
const friendRequest =
envelope.type === textsecure.protobuf.Envelope.Type.FRIEND_REQUEST;
const groupId = message.group && message.group.id;
const isBlocked = this.isGroupBlocked(groupId);
const isMe = envelope.source === textsecure.storage.user.getNumber();
const conversation = window.ConversationController.get(envelope.source);
const isLeavingGroup = Boolean(
message.group &&
message.group.type === textsecure.protobuf.GroupContext.Type.QUIT
);
const friendRequest =
envelope.type === textsecure.protobuf.Envelope.Type.FRIEND_REQUEST;
// Check if we need to update any profile names
if (!isMe && conversation) {
let profile = null;
if (message.profile) {
profile = JSON.parse(message.profile.encodeJSON());
}
// Update the conversation
await conversation.setProfile(profile);
// Check if we need to update any profile names
if (!isMe && conversation) {
let profile = null;
if (message.profile) {
profile = JSON.parse(message.profile.encodeJSON());
}
if (friendRequest && isMe) {
window.log.info('refusing to add a friend request to ourselves');
throw new Error('Cannot add a friend request for ourselves!');
}
if (groupId && isBlocked && !(isMe && isLeavingGroup)) {
window.log.warn(
`Message ${this.getEnvelopeId(
envelope
)} ignored; destined for blocked group`
);
return this.removeFromCache(envelope);
}
if (!message.body) {
// Trigger conversation friend request event for empty message
if (conversation && !message.flags) {
const isFriendRequestAccept = await conversation.onFriendRequestAccepted();
if (isFriendRequestAccept) {
await conversation.notifyFriendRequest(
envelope.source,
'accepted'
);
}
}
this.removeFromCache(envelope);
return null;
}
const ev = new Event('message');
ev.confirm = this.removeFromCache.bind(this, envelope);
ev.data = {
friendRequest,
source: envelope.source,
sourceDevice: envelope.sourceDevice,
timestamp: envelope.timestamp.toNumber(),
receivedAt: envelope.receivedAt,
unidentifiedDeliveryReceived: envelope.unidentifiedDeliveryReceived,
isP2p: envelope.isP2p,
message,
};
return this.dispatchAndWait(ev);
// Update the conversation
await conversation.setProfile(profile);
}
)
if (friendRequest && isMe) {
window.log.info('refusing to add a friend request to ourselves');
throw new Error('Cannot add a friend request for ourselves!');
}
if (groupId && isBlocked && !(isMe && isLeavingGroup)) {
window.log.warn(
`Message ${this.getEnvelopeId(
envelope
)} ignored; destined for blocked group`
);
return this.removeFromCache(envelope);
}
if (!message.body) {
// Trigger conversation friend request event for empty message
if (conversation && !message.flags) {
const isFriendRequestAccept = await conversation.onFriendRequestAccepted();
if (isFriendRequestAccept) {
await conversation.notifyFriendRequest(
envelope.source,
'accepted'
);
}
}
this.removeFromCache(envelope);
return null;
}
const ev = new Event('message');
ev.confirm = this.removeFromCache.bind(this, envelope);
ev.data = {
friendRequest,
source: envelope.source,
sourceDevice: envelope.sourceDevice,
timestamp: envelope.timestamp.toNumber(),
receivedAt: envelope.receivedAt,
unidentifiedDeliveryReceived: envelope.unidentifiedDeliveryReceived,
isP2p: envelope.isP2p,
message,
};
return this.dispatchAndWait(ev);
})
);
},
handleLegacyMessage(envelope) {

View file

@ -31,7 +31,6 @@ interface Props {
showFriendRequestIndicator?: boolean;
isBlocked: boolean;
isOnline: boolean;
isMe: boolean;
hasNickname: boolean;
i18n: Localizer;