Send profile along with friend request accept message

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

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

@ -909,56 +909,63 @@ 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 (!message.body) {
return null;
}
if (groupId && isBlocked && !(isMe && isLeavingGroup)) { const ev = new Event('message');
window.log.warn( ev.confirm = this.removeFromCache.bind(this, envelope);
`Message ${this.getEnvelopeId( ev.data = {
envelope friendRequest,
)} ignored; destined for blocked group` source: envelope.source,
); sourceDevice: envelope.sourceDevice,
return this.removeFromCache(envelope); timestamp: envelope.timestamp.toNumber(),
receivedAt: envelope.receivedAt,
unidentifiedDeliveryReceived: envelope.unidentifiedDeliveryReceived,
message,
};
return this.dispatchAndWait(ev);
} }
)
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,
message,
};
return this.dispatchAndWait(ev);
})
); );
}, },
handleLegacyMessage(envelope) { handleLegacyMessage(envelope) {
@ -994,7 +1001,7 @@ MessageReceiver.prototype.extend({
if (content.syncMessage) if (content.syncMessage)
return this.handleSyncMessage(envelope, content.syncMessage); return this.handleSyncMessage(envelope, content.syncMessage);
if (content.dataMessage) if (content.dataMessage)
return this.handleDataMessage(envelope, content.dataMessage); await this.handleDataMessage(envelope, content.dataMessage);
if (content.nullMessage) if (content.nullMessage)
return this.handleNullMessage(envelope, content.nullMessage); return this.handleNullMessage(envelope, content.nullMessage);
if (content.callMessage) if (content.callMessage)
@ -1004,13 +1011,19 @@ 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 // Trigger conversation friend request event
const conversation = window.ConversationController.get(envelope.source); if (
if (conversation) { envelope.type === textsecure.protobuf.Envelope.Type.PREKEY_BUNDLE &&
conversation.onFriendRequestAccepted(); (content.dataMessage === null || content.dataMessage.flags === null)
conversation.notifyFriendRequest(envelope.source, 'accepted'); ) {
const conversation = window.ConversationController.get(envelope.source);
if (conversation) {
conversation.onFriendRequestAccepted();
conversation.notifyFriendRequest(envelope.source, 'accepted');
}
this.removeFromCache(envelope);
} }
this.removeFromCache(envelope);
return null; return null;
}, },
handleCallMessage(envelope) { handleCallMessage(envelope) {

Loading…
Cancel
Save