Handle friend request messages before they're discarded by Signal

pull/16/head
Niels Andriesse 6 years ago
parent cd03dfd4c6
commit 4c6d09aa29

@ -1372,6 +1372,9 @@ NS_ASSUME_NONNULL_BEGIN
[incomingMessage.attachmentIds addObject:pointer.uniqueId];
}
// Loki: Do this before the check below
[self handleFriendRequestIfNeededWithEnvelope: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",
envelopeAddress(envelope),
@ -1439,6 +1442,9 @@ NS_ASSUME_NONNULL_BEGIN
[incomingMessage.attachmentIds addObject:pointer.uniqueId];
}
// Loki: Do this before the check below
[self handleFriendRequestIfNeededWithEnvelope:envelope message:incomingMessage thread:thread transaction:transaction];
if (body.length == 0 && attachmentPointers.count < 1 && !contact) {
OWSLogWarn(@"ignoring empty incoming message from: %@ with timestamp: %lu",
envelopeAddress(envelope),
@ -1454,30 +1460,8 @@ NS_ASSUME_NONNULL_BEGIN
}
}
- (void)finalizeIncomingMessage:(TSIncomingMessage *)incomingMessage
thread:(TSThread *)thread
envelope:(SSKProtoEnvelope *)envelope
transaction:(YapDatabaseReadWriteTransaction *)transaction
- (void)handleFriendRequestIfNeededWithEnvelope:(SSKProtoEnvelope *)envelope message:(TSIncomingMessage *)message thread:(TSThread *)thread transaction:(YapDatabaseReadWriteTransaction *)transaction
{
if (!envelope) {
OWSFailDebug(@"Missing envelope.");
return;
}
if (!thread) {
OWSFailDebug(@"Missing thread.");
return;
}
if (!incomingMessage) {
OWSFailDebug(@"Missing incomingMessage.");
return;
}
if (!transaction) {
OWSFail(@"Missing transaction.");
return;
}
// Loki:
// ========
if (envelope.type == SSKProtoEnvelopeTypeFriendRequest) {
if (thread.hasCurrentUserSentFriendRequest) {
// This can happen if Alice sent Bob a friend request, Bob declined, but then Bob changed his
@ -1492,8 +1476,8 @@ NS_ASSUME_NONNULL_BEGIN
// TSThreadFriendRequestStatusRequestSent.
[thread setFriendRequestStatus:TSThreadFriendRequestStatusFriends withTransaction:transaction];
// The two lines below are equivalent to calling [ThreadUtil enqueueAcceptFriendRequestMessageInThread:thread]
TSOutgoingMessage *message = [TSOutgoingMessage createEmptyOutgoingMessageInThread:thread];
[self.messageSenderJobQueue addMessage:message transaction:transaction];
TSOutgoingMessage *acceptFriendRequestMessage = [TSOutgoingMessage createEmptyOutgoingMessageInThread:thread];
[self.messageSenderJobQueue addMessage:acceptFriendRequestMessage transaction:transaction];
} else if (!thread.isContactFriend) {
// Checking that the sender of the message isn't already a friend is necessary because otherwise
// the following situation can occur: Alice and Bob are friends. Bob loses his database and his
@ -1501,14 +1485,36 @@ NS_ASSUME_NONNULL_BEGIN
// request. Alice's thread's friend request status is reset to
// TSThreadFriendRequestStatusRequestReceived.
[thread setFriendRequestStatus:TSThreadFriendRequestStatusRequestReceived withTransaction:transaction];
incomingMessage.isFriendRequest = YES; // Saved below
message.isFriendRequest = YES; // Saved below
}
} else if (!thread.isContactFriend) {
// If the thread's friend request status is not TSThreadFriendRequestStatusFriends, but we're receiving a message,
// it must be a friend request accepted message. Declining a friend request doesn't send a message.
[thread setFriendRequestStatus:TSThreadFriendRequestStatusFriends withTransaction:transaction];
}
// ========
}
- (void)finalizeIncomingMessage:(TSIncomingMessage *)incomingMessage
thread:(TSThread *)thread
envelope:(SSKProtoEnvelope *)envelope
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
if (!envelope) {
OWSFailDebug(@"Missing envelope.");
return;
}
if (!thread) {
OWSFailDebug(@"Missing thread.");
return;
}
if (!incomingMessage) {
OWSFailDebug(@"Missing incomingMessage.");
return;
}
if (!transaction) {
OWSFail(@"Missing transaction.");
return;
}
[incomingMessage saveWithTransaction:transaction];

Loading…
Cancel
Save