Merge pull request #788 from Mikunj/session-request

Fix session request messages
pull/789/head
Maxim Shishmarev 5 years ago committed by GitHub
commit 9104144922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1891,7 +1891,8 @@
const authorisation = await libloki.storage.getGrantAuthorisationForSecondaryPubKey( const authorisation = await libloki.storage.getGrantAuthorisationForSecondaryPubKey(
source source
); );
if (initialMessage.group) { const isGroupMessage = !!initialMessage.group;
if (isGroupMessage) {
conversationId = initialMessage.group.id; conversationId = initialMessage.group.id;
} else if (source !== ourNumber && authorisation) { } else if (source !== ourNumber && authorisation) {
// Ignore auth from our devices // Ignore auth from our devices
@ -1982,16 +1983,16 @@
Date.now(), Date.now(),
undefined, undefined,
undefined, undefined,
{ messageType: 'friend-request', backgroundFriendReq: true } { messageType: 'friend-request', sessionRequest: true }
); );
}); });
} }
}); });
} }
const backgroundFrReq = const isSessionRequest =
initialMessage.flags === initialMessage.flags ===
textsecure.protobuf.DataMessage.Flags.BACKGROUND_FRIEND_REQUEST; textsecure.protobuf.DataMessage.Flags.SESSION_REQUEST;
if ( if (
// eslint-disable-next-line no-bitwise // eslint-disable-next-line no-bitwise
@ -2002,7 +2003,7 @@
this.set({ endSessionType: 'ongoing' }); this.set({ endSessionType: 'ongoing' });
} }
if (message.isFriendRequest() && backgroundFrReq) { if (message.isFriendRequest() && isSessionRequest) {
// Check if the contact is a member in one of our private groups: // Check if the contact is a member in one of our private groups:
const groupMember = window const groupMember = window
.getConversations() .getConversations()
@ -2308,39 +2309,44 @@
} }
let autoAccept = false; let autoAccept = false;
if (message.get('type') === 'friend-request') { // Make sure friend request logic doesn't trigger on messages aimed at groups
/* if (!isGroupMessage) {
Here is the before and after state diagram for the operation before. if (message.get('type') === 'friend-request') {
/*
None -> RequestReceived Here is the before and after state diagram for the operation before.
PendingSend -> RequestReceived
RequestReceived -> RequestReceived None -> RequestReceived
Sent -> Friends PendingSend -> RequestReceived
Expired -> Friends RequestReceived -> RequestReceived
Friends -> Friends Sent -> Friends
Expired -> Friends
The cases where we auto accept are the following: Friends -> Friends
- We sent the user a friend request and that user sent us a friend request.
- We are friends with the user, and that user just sent us a friend request. The cases where we auto accept are the following:
*/ - We sent the user a friend request,
const isFriend = sendingDeviceConversation.isFriend(); and that user sent us a friend request.
const hasSentFriendRequest = sendingDeviceConversation.hasSentFriendRequest(); - We are friends with the user,
autoAccept = isFriend || hasSentFriendRequest; and that user just sent us a friend request.
*/
if (autoAccept) { const isFriend = sendingDeviceConversation.isFriend();
message.set({ friendStatus: 'accepted' }); const hasSentFriendRequest = sendingDeviceConversation.hasSentFriendRequest();
} autoAccept = isFriend || hasSentFriendRequest;
if (autoAccept) {
message.set({ friendStatus: 'accepted' });
}
if (isFriend) { if (isFriend) {
window.Whisper.events.trigger('endSession', source); window.Whisper.events.trigger('endSession', source);
} else if (hasSentFriendRequest) { } else if (hasSentFriendRequest) {
await sendingDeviceConversation.onFriendRequestAccepted();
} else {
await sendingDeviceConversation.onFriendRequestReceived();
}
} else if (message.get('type') !== 'outgoing') {
// Ignore 'outgoing' messages because they are sync messages
await sendingDeviceConversation.onFriendRequestAccepted(); await sendingDeviceConversation.onFriendRequestAccepted();
} else {
await sendingDeviceConversation.onFriendRequestReceived();
} }
} else if (message.get('type') !== 'outgoing') {
// Ignore 'outgoing' messages because they are sync messages
await sendingDeviceConversation.onFriendRequestAccepted();
} }
const id = await window.Signal.Data.saveMessage(message.attributes, { const id = await window.Signal.Data.saveMessage(message.attributes, {
Message: Whisper.Message, Message: Whisper.Message,

@ -496,7 +496,9 @@ class LokiAppDotNetServerAPI {
)); ));
} else { } else {
// disable check for .loki // disable check for .loki
process.env.NODE_TLS_REJECT_UNAUTHORIZED = endpoint.match(/\.loki\//) ? 0 : 1; process.env.NODE_TLS_REJECT_UNAUTHORIZED = endpoint.match(/\.loki\//)
? 0
: 1;
result = await nodeFetch(url, fetchOptions); result = await nodeFetch(url, fetchOptions);
// always make sure this check is enabled // always make sure this check is enabled
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 1; process.env.NODE_TLS_REJECT_UNAUTHORIZED = 1;
@ -505,7 +507,12 @@ class LokiAppDotNetServerAPI {
} }
} catch (e) { } catch (e) {
if (txtResponse) { if (txtResponse) {
log.info(`serverRequest ${mode} error`, e.code, e.message, `json: ${txtResponse}`); log.info(
`serverRequest ${mode} error`,
e.code,
e.message,
`json: ${txtResponse}`
);
} else { } else {
log.info(`serverRequest ${mode} error`, e.code, e.message); log.info(`serverRequest ${mode} error`, e.code, e.message);
} }

@ -1848,7 +1848,7 @@ MessageReceiver.prototype.extend({
} else if (decrypted.flags & FLAGS.PROFILE_KEY_UPDATE) { } else if (decrypted.flags & FLAGS.PROFILE_KEY_UPDATE) {
decrypted.body = null; decrypted.body = null;
decrypted.attachments = []; decrypted.attachments = [];
} else if (decrypted.flags & FLAGS.BACKGROUND_FRIEND_REQUEST) { } else if (decrypted.flags & FLAGS.SESSION_REQUEST) {
// do nothing // do nothing
} else if (decrypted.flags & FLAGS.SESSION_RESTORE) { } else if (decrypted.flags & FLAGS.SESSION_RESTORE) {
// do nothing // do nothing

@ -950,8 +950,8 @@ MessageSender.prototype = {
) { ) {
const profile = this.getOurProfile(); const profile = this.getOurProfile();
const flags = options.backgroundFriendReq const flags = options.sessionRequest
? textsecure.protobuf.DataMessage.Flags.BACKGROUND_FRIEND_REQUEST ? textsecure.protobuf.DataMessage.Flags.SESSION_REQUEST
: undefined; : undefined;
const { groupInvitation, sessionRestoration } = options; const { groupInvitation, sessionRestoration } = options;

@ -107,7 +107,7 @@ message DataMessage {
PROFILE_KEY_UPDATE = 4; PROFILE_KEY_UPDATE = 4;
SESSION_RESTORE = 64; SESSION_RESTORE = 64;
UNPAIRING_REQUEST = 128; UNPAIRING_REQUEST = 128;
BACKGROUND_FRIEND_REQUEST = 256; SESSION_REQUEST = 256;
} }
message Quote { message Quote {

Loading…
Cancel
Save