From 78ab0d483b1d4f49cd22976fab6317894791bf05 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Wed, 29 Jan 2020 14:58:28 +1100 Subject: [PATCH] Remove debug code --- .../environment/VersionMigrations.m | 9 ++-- SignalServiceKit/src/Contacts/TSThread.m | 14 ------ .../src/Messages/OWSMessageManager.m | 44 +++++++------------ .../src/Messages/OWSMessageSender.m | 26 +++-------- SignalServiceKit/src/Messages/TSGroupModel.m | 4 +- 5 files changed, 28 insertions(+), 69 deletions(-) diff --git a/SignalMessaging/environment/VersionMigrations.m b/SignalMessaging/environment/VersionMigrations.m index 6af82dbf7..c569b0173 100644 --- a/SignalMessaging/environment/VersionMigrations.m +++ b/SignalMessaging/environment/VersionMigrations.m @@ -177,10 +177,9 @@ NS_ASSUME_NONNULL_BEGIN TSGroupThread *thread = [TSGroupThread threadWithGroupId:[LKGroupUtilities getEncodedOpenGroupIDAsData:chat.id] transaction:transaction]; if (thread != nil) { [LKDatabaseUtilities setPublicChat:chat threadID:thread.uniqueId transaction:transaction]; - } - else { - //Update the group type and group id for private group chat version. - //If the thread is still using the old group id, it needs to be updated. + } else { + // Update the group type and group ID for private group chat version. + // If the thread is still using the old group ID, it needs to be updated. thread = [TSGroupThread threadWithGroupId:chat.idAsData transaction:transaction]; if (thread != nil) { thread.groupModel.groupType = openGroup; @@ -190,7 +189,7 @@ NS_ASSUME_NONNULL_BEGIN } } } - //Update rss feed here + // Update RSS feeds here LKRSSFeed *lokiNewsFeed = [[LKRSSFeed alloc] initWithId:@"loki.network.feed" server:@"https://loki.network/feed/" displayName:NSLocalizedString(@"Loki News", @"") isDeletable:true]; LKRSSFeed *lokiMessengerUpdatesFeed = [[LKRSSFeed alloc] initWithId:@"loki.network.messenger-updates.feed" server:@"https://loki.network/category/messenger-updates/feed/" displayName:NSLocalizedString(@"Loki Messenger Updates", @"") isDeletable:false]; NSArray *feeds = @[ lokiNewsFeed, lokiMessengerUpdatesFeed ]; diff --git a/SignalServiceKit/src/Contacts/TSThread.m b/SignalServiceKit/src/Contacts/TSThread.m index 5fbfd886f..e7520d8b3 100644 --- a/SignalServiceKit/src/Contacts/TSThread.m +++ b/SignalServiceKit/src/Contacts/TSThread.m @@ -230,20 +230,6 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa return NO; } -//- (BOOL)isPublicChat -//{ -// OWSAbstractMethod(); -// -// return NO; -//} -// -//- (BOOL)isRSSFeed -//{ -// OWSAbstractMethod(); -// -// return NO; -//} - // Override in ContactThread - (nullable NSString *)contactIdentifier { diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index eb113b46a..0226d65e3 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1367,34 +1367,27 @@ NS_ASSUME_NONNULL_BEGIN if (groupId.length > 0) { NSMutableSet *newMemberIds = [NSMutableSet setWithArray:dataMessage.group.members]; NSMutableSet *removedMemberIds = [NSMutableSet new]; - //Ryan TODO: validate the recipientId -// for (NSString *recipientId in newMemberIds) { -// if (!recipientId.isValidE164) { -// OWSLogVerbose( -// @"incoming group update has invalid group member: %@", [self descriptionForEnvelope:envelope]); -// OWSFailDebug(@"incoming group update has invalid group member"); -// return nil; -// } -// } + for (NSString *recipientId in newMemberIds) { + if (![ECKeyPair isValidHexEncodedPublicKeyWithCandidate:recipientId]) { + OWSLogVerbose( + @"incoming group update has invalid group member: %@", [self descriptionForEnvelope:envelope]); + OWSFailDebug(@"incoming group update has invalid group member"); + return nil; + } + } // Group messages create the group if it doesn't already exist. // // We distinguish between the old group state (if any) and the new group state. TSGroupThread *_Nullable oldGroupThread = [TSGroupThread threadWithGroupId:groupId transaction:transaction]; if (oldGroupThread) { - // Don't trust other clients; ensure all known group members remain in the - // group unless it is a "quit" message in which case we should only remove - // the quiting member below. - //[newMemberIds addObjectsFromArray:oldGroupThread.groupModel.groupMemberIds]; - - //Loki - Try to figure out removed members + // Loki: Try to figure out removed members removedMemberIds = [NSMutableSet setWithArray:oldGroupThread.groupModel.groupMemberIds]; [removedMemberIds minusSet:newMemberIds]; [removedMemberIds removeObject:envelope.source]; } NSString *hexEncodedPublicKey = ([LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in:transaction] ?: envelope.source); -// TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:hexEncodedPublicKey transaction:transaction]; // Only set the display name here, the logic for updating profile pictures is handled when we're setting profile key [self handleProfileNameUpdateIfNeeded:dataMessage recipientId:hexEncodedPublicKey transaction:transaction]; @@ -1402,7 +1395,7 @@ NS_ASSUME_NONNULL_BEGIN switch (dataMessage.group.type) { case SSKProtoGroupContextTypeUpdate: { if (oldGroupThread && ![oldGroupThread.groupModel.groupAdminIds containsObject:envelope.source]) { - OWSLogWarn(@"Loki - Received a group update message from a non-admin user for %@ %@", [LKGroupUtilities getEncodedGroupID:groupId], @". Ignoring."); + [LKLogger print:[NSString stringWithFormat:@"[Loki] Received a group update from a non-admin user for %@; ignoring.", [LKGroupUtilities getEncodedGroupID:groupId]]]; return nil; } // Ensures that the thread exists but doesn't update it. @@ -1421,7 +1414,7 @@ NS_ASSUME_NONNULL_BEGIN newGroupThread.groupModel = newGroupModel; [newGroupThread saveWithTransaction:transaction]; - //Loki - Try to establish session with members when a group is created or updated + // Loki: Try to establish sessions with all members when a group is created or updated [self establishSessionsWithMembersIfNeeded: newMemberIds.allObjects forThread:newGroupThread transaction:transaction]; [[OWSDisappearingMessagesJob sharedJob] becomeConsistentWithDisappearingDuration:dataMessage.expireTimer @@ -1674,14 +1667,9 @@ NS_ASSUME_NONNULL_BEGIN if ([member isEqualToString:userHexEncodedPublicKey] ) { continue; } __block BOOL hasSession; hasSession = [self.primaryStorage containsSession:member deviceId:1 protocolContext:transaction]; - if (!hasSession) { - OWSLogInfo(@"Try to build session with %@", member); - LKSessionRequestMessage *message = [[LKSessionRequestMessage alloc] initWithThread:thread]; - [self.messageSenderJobQueue addMessage:message transaction:transaction]; - } - else { - OWSLogInfo(@"There is session with %@", member); - } + if (hasSession) { continue; } + LKSessionRequestMessage *message = [[LKSessionRequestMessage alloc] initWithThread:thread]; + [self.messageSenderJobQueue addMessage:message transaction:transaction]; } } @@ -1718,14 +1706,12 @@ NS_ASSUME_NONNULL_BEGIN } - (void)handleFriendRequestMessageIfNeededWithEnvelope:(SSKProtoEnvelope *)envelope data:(SSKProtoDataMessage *)data message:(TSIncomingMessage *)message thread:(TSContactThread *)thread transaction:(YapDatabaseReadWriteTransaction *)transaction { - if (envelope.isGroupChatMessage) { return NSLog(@"[Loki] Ignoring friend request in group chat.", @""); } if (envelope.type != SSKProtoEnvelopeTypeFriendRequest) { return NSLog(@"[Loki] handleFriendRequestMessageIfNeededWithEnvelope:data:message:thread:transaction was called with an envelope that isn't of type SSKProtoEnvelopeTypeFriendRequest."); } - if ([self canFriendRequestBeAutoAcceptedForThread:thread transaction:transaction]) { [thread saveFriendRequestStatus:LKThreadFriendRequestStatusFriends withTransaction:transaction]; __block TSOutgoingMessage *existingFriendRequestMessage; @@ -1773,7 +1759,7 @@ NS_ASSUME_NONNULL_BEGIN // TODO: We'll need to fix this up if we ever start using sync messages // Currently this uses `envelope.source` but with sync messages we'll need to use the message sender ID TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction]; - // We shouldn't be able to skip from None -> Friends in normal circumstances. + // We shouldn't be able to skip from none to friends under normal circumstances if (thread.friendRequestStatus == LKThreadFriendRequestStatusNone) { return; } if (thread.isContactFriend) return; // Become happy friends and go on great adventures diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index cd518a022..93c314f71 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -518,15 +518,10 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; // TODO: Handle } }]; - } - //Maybe need to handle RssFeed - else { + } else { [recipientIds addObjectsFromArray:message.sendingRecipientIds]; - // Only send to members in the latest known group member list. + // Only send to members in the latest known group member list [recipientIds intersectSet:[NSSet setWithArray:groupThread.groupModel.groupMemberIds]]; -// for (NSString *recipientId in recipientIds) { -// -// } } } else if ([thread isKindOfClass:[TSContactThread class]]) { NSString *recipientContactId = ((TSContactThread *)thread).contactIdentifier; @@ -701,7 +696,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; if (thread.isGroupThread) { [self saveInfoMessageForGroupMessage:message inThread:thread]; - OWSLogInfo(@"group message save here %@ %@ %@", message.customMessage, message.recipientIds.lastObject, message.recipientIds.firstObject); } NSError *error; @@ -729,8 +723,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; } }]; } - - OWSLogInfo(@"recipient count: %d", recipientIds.count); if (recipientIds.count < 1) { // All recipients are already sent or can be skipped. @@ -986,9 +978,11 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; BOOL isDeviceLinkMessage = [message isKindOfClass:LKDeviceLinkMessage.class]; if (isPublicChatMessage || isDeviceLinkMessage) { [self sendMessage:messageSend]; - } - else if (isGroupMessage) { + } else if (isGroupMessage) { [self sendMessage:messageSend]; + + // TODO: Multi device? + // [[LKAPI getDestinationsFor:contactID] // .thenOn(OWSDispatch.sendingQueue, ^(NSArray *destinations) { // // Get master destination @@ -1025,8 +1019,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; // .catchOn(OWSDispatch.sendingQueue, ^(NSError *error) { // [self messageSendDidFail:messageSend deviceMessages:@{} statusCode:0 error:error responseData:nil]; // }) retainUntilComplete]; - } - else { + } else { BOOL isSilentMessage = message.isSilent || [message isKindOfClass:LKEphemeralMessage.class] || [message isKindOfClass:OWSOutgoingSyncMessage.class]; BOOL isFriendRequestMessage = [message isKindOfClass:LKFriendRequestMessage.class]; BOOL isSessionRequestMessage = [message isKindOfClass:LKSessionRequestMessage.class]; @@ -1683,8 +1676,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; }]; BOOL isPublicChatMessage = message.thread.isGroupThread && ((TSGroupThread *)message.thread).isPublicChat; - OWSLogInfo(@"Message recipient %d %@", [message.recipientIds count], message.recipientIds[0]); - OWSLogInfo(@"Try to figure out if it is a public chat message %d", isPublicChatMessage); BOOL shouldSendTranscript = (AreRecipientUpdatesEnabled() || !message.hasSyncedTranscript) && !isNoteToSelf && !isPublicChatMessage && !([message isKindOfClass:LKDeviceLinkMessage.class]); if (!shouldSendTranscript) { @@ -2117,19 +2108,16 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; OWSAssertDebug(thread); if (message.groupMetaMessage == TSGroupMetaMessageDeliver) { - OWSLogInfo(@"save for group message deliver"); // TODO: Why is this necessary? [message save]; } else if (message.groupMetaMessage == TSGroupMetaMessageQuit) { // MJK TODO - remove senderTimestamp - OWSLogInfo(@"save for group message quit: %@", message.customMessage); [[[TSInfoMessage alloc] initWithTimestamp:message.timestamp inThread:thread messageType:TSInfoMessageTypeGroupQuit customMessage:message.customMessage] save]; } else { // MJK TODO - remove senderTimestamp - OWSLogInfo(@"save for group message update: %@", message.customMessage); [[[TSInfoMessage alloc] initWithTimestamp:message.timestamp inThread:thread messageType:TSInfoMessageTypeGroupUpdate diff --git a/SignalServiceKit/src/Messages/TSGroupModel.m b/SignalServiceKit/src/Messages/TSGroupModel.m index 5f37780cb..0fcf59c9e 100644 --- a/SignalServiceKit/src/Messages/TSGroupModel.m +++ b/SignalServiceKit/src/Messages/TSGroupModel.m @@ -149,9 +149,9 @@ const int32_t kGroupIdLength = 16; [newMembersNames componentsJoinedByString:@", "]]]; } - if ([_removedMembers count] > 0) { + if (_removedMembers.count > 0) { NSString *masterDeviceHexEncodedPublicKey = [NSUserDefaults.standardUserDefaults stringForKey:@"masterDeviceHexEncodedPublicKey"]; - NSString *hexEncodedPublicKey = masterDeviceHexEncodedPublicKey != nil ? masterDeviceHexEncodedPublicKey : [TSAccountManager localNumber]; + NSString *hexEncodedPublicKey = masterDeviceHexEncodedPublicKey != nil ? masterDeviceHexEncodedPublicKey : TSAccountManager.localNumber; if ([_removedMembers containsObject:hexEncodedPublicKey]) { updatedGroupInfoString = [updatedGroupInfoString stringByAppendingString:NSLocalizedString(@"YOU_WERE_REMOVED", @"")];