Merge branch 'development' of github.com:loki-project/loki-messenger into development

pull/147/head
Beaudan 6 years ago
commit c07a2dc2fb

@ -653,7 +653,9 @@
await this.respondToAllPendingFriendRequests({ await this.respondToAllPendingFriendRequests({
response: 'accepted', response: 'accepted',
}); });
return true;
} }
return false;
}, },
async onFriendRequestTimeout() { async onFriendRequestTimeout() {
// Unset the timer // Unset the timer

@ -5,33 +5,48 @@
window.libloki = window.libloki || {}; window.libloki = window.libloki || {};
async function sendFriendRequestAccepted(pubKey) { async function sendFriendRequestAccepted(pubKey) {
return sendEmptyMessage(pubKey); return sendEmptyMessage(pubKey, true);
} }
async function sendEmptyMessage(pubKey) { async function sendEmptyMessage(pubKey, sendContentMessage = false) {
// empty content message
const content = new textsecure.protobuf.Content();
// will be called once the transmission succeeded or failed
const callback = res => {
if (res.errors.length > 0) {
res.errors.forEach(error => log.error(error));
} else {
log.info('empty message sent successfully');
}
};
const options = {}; const options = {};
// send an empty message. The logic in ougoing_message will attach the prekeys. // send an empty message.
const outgoingMessage = new textsecure.OutgoingMessage( if (sendContentMessage) {
null, // server // The logic downstream will attach the prekeys and our profile.
Date.now(), // timestamp, await textsecure.messaging.sendMessageToNumber(
[pubKey], // numbers pubKey, // number
content, // message null, // messageText
true, // silent [], // attachments
callback, // callback null, // quote
options Date.now(), // timestamp
); null, // expireTimer
await outgoingMessage.sendToNumber(pubKey); null, // profileKey
options
);
} else {
// empty content message
const content = new textsecure.protobuf.Content();
// will be called once the transmission succeeded or failed
const callback = res => {
if (res.errors.length > 0) {
res.errors.forEach(error => log.error(error));
} else {
log.info('empty message sent successfully');
}
};
// send an empty message. The logic in ougoing_message will attach the prekeys.
const outgoingMessage = new textsecure.OutgoingMessage(
null, // server
Date.now(), // timestamp,
[pubKey], // numbers
content, // message
true, // silent
callback, // callback
options
);
await outgoingMessage.sendToNumber(pubKey);
}
} }
window.libloki.api = { window.libloki.api = {

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

Loading…
Cancel
Save