Send profile along with friend request accept message

pull/150/head
sachaaaaa 7 years ago
parent 73d2ad28a3
commit 1238cbc4e6

@ -1,4 +1,4 @@
/* global window, textsecure, log */
/* global window, textsecure */
// eslint-disable-next-line func-names
(function() {
@ -9,29 +9,19 @@
}
async function sendEmptyMessage(pubKey) {
// 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 = {};
// 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
// send an empty message.
// The logic downstream will attach the prekeys and our profile.
await textsecure.messaging.sendMessageToNumber(
pubKey, // number
null, // messageText
[], // attachments
null, // quote
Date.now(), // timestamp
null, // expireTimer
null, // profileKey
options
);
await outgoingMessage.sendToNumber(pubKey);
}
window.libloki.api = {

@ -909,11 +909,14 @@ MessageReceiver.prototype.extend({
p = this.handleEndSession(envelope.source);
}
return p.then(() =>
this.processDecrypted(envelope, msg, envelope.source).then(message => {
this.processDecrypted(envelope, msg, envelope.source).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 conversation = window.ConversationController.get(
envelope.source
);
const isLeavingGroup = Boolean(
message.group &&
message.group.type === textsecure.protobuf.GroupContext.Type.QUIT
@ -929,7 +932,7 @@ MessageReceiver.prototype.extend({
}
// Update the conversation
conversation.setProfile(profile);
await conversation.setProfile(profile);
}
if (friendRequest && isMe) {
@ -945,6 +948,9 @@ MessageReceiver.prototype.extend({
);
return this.removeFromCache(envelope);
}
if (!message.body) {
return null;
}
const ev = new Event('message');
ev.confirm = this.removeFromCache.bind(this, envelope);
@ -958,7 +964,8 @@ MessageReceiver.prototype.extend({
message,
};
return this.dispatchAndWait(ev);
})
}
)
);
},
handleLegacyMessage(envelope) {
@ -994,7 +1001,7 @@ MessageReceiver.prototype.extend({
if (content.syncMessage)
return this.handleSyncMessage(envelope, content.syncMessage);
if (content.dataMessage)
return this.handleDataMessage(envelope, content.dataMessage);
await this.handleDataMessage(envelope, content.dataMessage);
if (content.nullMessage)
return this.handleNullMessage(envelope, content.nullMessage);
if (content.callMessage)
@ -1004,13 +1011,19 @@ MessageReceiver.prototype.extend({
if (content.typingMessage)
return this.handleTypingMessage(envelope, content.typingMessage);
// Trigger conversation friend request event for empty message
// Trigger conversation friend request event
if (
envelope.type === textsecure.protobuf.Envelope.Type.PREKEY_BUNDLE &&
(content.dataMessage === null || content.dataMessage.flags === null)
) {
const conversation = window.ConversationController.get(envelope.source);
if (conversation) {
conversation.onFriendRequestAccepted();
conversation.notifyFriendRequest(envelope.source, 'accepted');
}
this.removeFromCache(envelope);
}
return null;
},
handleCallMessage(envelope) {

Loading…
Cancel
Save