Update friend request handling.

pull/33/head
Mikunj 6 years ago
parent 40edf1992a
commit d1e02848e6

@ -414,6 +414,9 @@ NS_ASSUME_NONNULL_BEGIN
return;
}
// Loki: Handle any friend request accepts if we need to
[self handleFriendRequestAcceptIfNeededWithEnvelope:envelope transaction:transaction];
if (envelope.content != nil) {
NSError *error;
SSKProtoContent *_Nullable contentProto = [SSKProtoContent parseData:plaintextData error:&error];
@ -1383,7 +1386,7 @@ NS_ASSUME_NONNULL_BEGIN
}
// Loki: Do this before the check below
[self handleFriendRequestIfNeededWithEnvelope:envelope message:incomingMessage thread:oldGroupThread transaction:transaction];
[self handleFriendRequestMessageIfNeededWithEnvelope:envelope message:incomingMessage thread:oldGroupThread transaction:transaction];
if (body.length == 0 && attachmentPointers.count < 1 && !contact) {
OWSLogWarn(@"ignoring empty incoming message from: %@ for group: %@ with timestamp: %lu",
@ -1458,7 +1461,7 @@ NS_ASSUME_NONNULL_BEGIN
}
// Loki: Do this before the check below
[self handleFriendRequestIfNeededWithEnvelope:envelope message:incomingMessage thread:thread transaction:transaction];
[self handleFriendRequestMessageIfNeededWithEnvelope:envelope message:incomingMessage thread:thread transaction:transaction];
if (body.length == 0 && attachmentPointers.count < 1 && !contact) {
OWSLogWarn(@"ignoring empty incoming message from: %@ with timestamp: %lu",
@ -1486,9 +1489,12 @@ NS_ASSUME_NONNULL_BEGIN
}
}
- (void)handleFriendRequestIfNeededWithEnvelope:(SSKProtoEnvelope *)envelope message:(TSIncomingMessage *)message thread:(TSThread *)thread transaction:(YapDatabaseReadWriteTransaction *)transaction
{
if (envelope.type == SSKProtoEnvelopeTypeFriendRequest) {
// The difference between this function and `handleFriendRequestAcceptIfNeededWithEnvelope:` is that this will setup the incoming message for display to the user
// While `handleFriendRequestAcceptIfNeededWithEnvelope:` handles friend request accepting logic and doesn't need a message
- (void)handleFriendRequestMessageIfNeededWithEnvelope:(SSKProtoEnvelope *)envelope message:(TSIncomingMessage *)message thread:(TSThread *)thread transaction:(YapDatabaseReadWriteTransaction *)transaction {
// Check if it's a friend request message
if (envelope.type != SSKProtoEnvelopeTypeFriendRequest) return;
if (thread.hasCurrentUserSentFriendRequest) {
// This can happen if Alice sent Bob a friend request, Bob declined, but then Bob changed his
// mind and sent a friend request to Alice. In this case we want Alice to auto-accept the request
@ -1517,9 +1523,18 @@ NS_ASSUME_NONNULL_BEGIN
[thread saveFriendRequestStatus:LKThreadFriendRequestStatusRequestReceived withTransaction:transaction];
message.friendRequestStatus = LKMessageFriendRequestStatusPending; // Don't save yet. This is done in finalizeIncomingMessage:thread:envelope:transaction.
}
} else if (!thread.isContactFriend) {
// If the thread's friend request status is not LKThreadFriendRequestStatusFriends, but we're receiving a message,
// it must be a friend request accepted message. Declining a friend request doesn't send a message.
}
- (void)handleFriendRequestAcceptIfNeededWithEnvelope:(SSKProtoEnvelope *)envelope transaction:(YapDatabaseReadWriteTransaction *)transaction {
// If we get any other envelope type then we can assume that we had to use signal cipher decryption
// and that means we must have a session with the other person.
if (envelope.type == SSKProtoEnvelopeTypeFriendRequest) return;
// If we're already friends then there's no point in continuing
TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];
if (thread.isContactFriend) return;
// Become happy friends and go on great adventures
[thread saveFriendRequestStatus:LKThreadFriendRequestStatusFriends withTransaction:transaction];
TSOutgoingMessage *existingFriendRequestMessage = (TSOutgoingMessage *)[thread.lastInteraction as:TSOutgoingMessage.class];
if (existingFriendRequestMessage != nil && existingFriendRequestMessage.isFriendRequest) {
@ -1530,7 +1545,6 @@ NS_ASSUME_NONNULL_BEGIN
if (onlineMessage != nil) {
[self.messageSenderJobQueue addMessage:onlineMessage transaction:transaction];
}
}
}
- (void)finalizeIncomingMessage:(TSIncomingMessage *)incomingMessage

Loading…
Cancel
Save