work with session reset

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

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

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

@ -948,8 +948,17 @@ MessageReceiver.prototype.extend({
); );
return this.removeFromCache(envelope); return this.removeFromCache(envelope);
} }
if (!message.body) { if (!message.body) {
return null; // 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'); const ev = new Event('message');
@ -1001,7 +1010,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)
await this.handleDataMessage(envelope, content.dataMessage); return 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)
@ -1011,19 +1020,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
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; return null;
}, },
handleCallMessage(envelope) { handleCallMessage(envelope) {

Loading…
Cancel
Save