Remove debug code

pull/80/head
Niels Andriesse 5 years ago
parent e8c44937e3
commit 78ab0d483b

@ -177,10 +177,9 @@ NS_ASSUME_NONNULL_BEGIN
TSGroupThread *thread = [TSGroupThread threadWithGroupId:[LKGroupUtilities getEncodedOpenGroupIDAsData:chat.id] transaction:transaction]; TSGroupThread *thread = [TSGroupThread threadWithGroupId:[LKGroupUtilities getEncodedOpenGroupIDAsData:chat.id] transaction:transaction];
if (thread != nil) { if (thread != nil) {
[LKDatabaseUtilities setPublicChat:chat threadID:thread.uniqueId transaction:transaction]; [LKDatabaseUtilities setPublicChat:chat threadID:thread.uniqueId transaction:transaction];
} } else {
else { // Update the group type and group ID for private group chat version.
//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.
//If the thread is still using the old group id, it needs to be updated.
thread = [TSGroupThread threadWithGroupId:chat.idAsData transaction:transaction]; thread = [TSGroupThread threadWithGroupId:chat.idAsData transaction:transaction];
if (thread != nil) { if (thread != nil) {
thread.groupModel.groupType = openGroup; 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 *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]; 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 ]; NSArray *feeds = @[ lokiNewsFeed, lokiMessengerUpdatesFeed ];

@ -230,20 +230,6 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
return NO; return NO;
} }
//- (BOOL)isPublicChat
//{
// OWSAbstractMethod();
//
// return NO;
//}
//
//- (BOOL)isRSSFeed
//{
// OWSAbstractMethod();
//
// return NO;
//}
// Override in ContactThread // Override in ContactThread
- (nullable NSString *)contactIdentifier - (nullable NSString *)contactIdentifier
{ {

@ -1367,34 +1367,27 @@ NS_ASSUME_NONNULL_BEGIN
if (groupId.length > 0) { if (groupId.length > 0) {
NSMutableSet *newMemberIds = [NSMutableSet setWithArray:dataMessage.group.members]; NSMutableSet *newMemberIds = [NSMutableSet setWithArray:dataMessage.group.members];
NSMutableSet *removedMemberIds = [NSMutableSet new]; NSMutableSet *removedMemberIds = [NSMutableSet new];
//Ryan TODO: validate the recipientId for (NSString *recipientId in newMemberIds) {
// for (NSString *recipientId in newMemberIds) { if (![ECKeyPair isValidHexEncodedPublicKeyWithCandidate:recipientId]) {
// if (!recipientId.isValidE164) { OWSLogVerbose(
// OWSLogVerbose( @"incoming group update has invalid group member: %@", [self descriptionForEnvelope:envelope]);
// @"incoming group update has invalid group member: %@", [self descriptionForEnvelope:envelope]); OWSFailDebug(@"incoming group update has invalid group member");
// OWSFailDebug(@"incoming group update has invalid group member"); return nil;
// return nil; }
// } }
// }
// Group messages create the group if it doesn't already exist. // 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. // We distinguish between the old group state (if any) and the new group state.
TSGroupThread *_Nullable oldGroupThread = [TSGroupThread threadWithGroupId:groupId transaction:transaction]; TSGroupThread *_Nullable oldGroupThread = [TSGroupThread threadWithGroupId:groupId transaction:transaction];
if (oldGroupThread) { if (oldGroupThread) {
// Don't trust other clients; ensure all known group members remain in the // Loki: Try to figure out removed members
// 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
removedMemberIds = [NSMutableSet setWithArray:oldGroupThread.groupModel.groupMemberIds]; removedMemberIds = [NSMutableSet setWithArray:oldGroupThread.groupModel.groupMemberIds];
[removedMemberIds minusSet:newMemberIds]; [removedMemberIds minusSet:newMemberIds];
[removedMemberIds removeObject:envelope.source]; [removedMemberIds removeObject:envelope.source];
} }
NSString *hexEncodedPublicKey = ([LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in:transaction] ?: 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 // 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]; [self handleProfileNameUpdateIfNeeded:dataMessage recipientId:hexEncodedPublicKey transaction:transaction];
@ -1402,7 +1395,7 @@ NS_ASSUME_NONNULL_BEGIN
switch (dataMessage.group.type) { switch (dataMessage.group.type) {
case SSKProtoGroupContextTypeUpdate: { case SSKProtoGroupContextTypeUpdate: {
if (oldGroupThread && ![oldGroupThread.groupModel.groupAdminIds containsObject:envelope.source]) { 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; return nil;
} }
// Ensures that the thread exists but doesn't update it. // Ensures that the thread exists but doesn't update it.
@ -1421,7 +1414,7 @@ NS_ASSUME_NONNULL_BEGIN
newGroupThread.groupModel = newGroupModel; newGroupThread.groupModel = newGroupModel;
[newGroupThread saveWithTransaction:transaction]; [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]; [self establishSessionsWithMembersIfNeeded: newMemberIds.allObjects forThread:newGroupThread transaction:transaction];
[[OWSDisappearingMessagesJob sharedJob] becomeConsistentWithDisappearingDuration:dataMessage.expireTimer [[OWSDisappearingMessagesJob sharedJob] becomeConsistentWithDisappearingDuration:dataMessage.expireTimer
@ -1674,14 +1667,9 @@ NS_ASSUME_NONNULL_BEGIN
if ([member isEqualToString:userHexEncodedPublicKey] ) { continue; } if ([member isEqualToString:userHexEncodedPublicKey] ) { continue; }
__block BOOL hasSession; __block BOOL hasSession;
hasSession = [self.primaryStorage containsSession:member deviceId:1 protocolContext:transaction]; hasSession = [self.primaryStorage containsSession:member deviceId:1 protocolContext:transaction];
if (!hasSession) { if (hasSession) { continue; }
OWSLogInfo(@"Try to build session with %@", member); LKSessionRequestMessage *message = [[LKSessionRequestMessage alloc] initWithThread:thread];
LKSessionRequestMessage *message = [[LKSessionRequestMessage alloc] initWithThread:thread]; [self.messageSenderJobQueue addMessage:message transaction:transaction];
[self.messageSenderJobQueue addMessage:message transaction:transaction];
}
else {
OWSLogInfo(@"There is session with %@", member);
}
} }
} }
@ -1718,14 +1706,12 @@ NS_ASSUME_NONNULL_BEGIN
} }
- (void)handleFriendRequestMessageIfNeededWithEnvelope:(SSKProtoEnvelope *)envelope data:(SSKProtoDataMessage *)data message:(TSIncomingMessage *)message thread:(TSContactThread *)thread transaction:(YapDatabaseReadWriteTransaction *)transaction { - (void)handleFriendRequestMessageIfNeededWithEnvelope:(SSKProtoEnvelope *)envelope data:(SSKProtoDataMessage *)data message:(TSIncomingMessage *)message thread:(TSContactThread *)thread transaction:(YapDatabaseReadWriteTransaction *)transaction {
if (envelope.isGroupChatMessage) { if (envelope.isGroupChatMessage) {
return NSLog(@"[Loki] Ignoring friend request in group chat.", @""); return NSLog(@"[Loki] Ignoring friend request in group chat.", @"");
} }
if (envelope.type != SSKProtoEnvelopeTypeFriendRequest) { if (envelope.type != SSKProtoEnvelopeTypeFriendRequest) {
return NSLog(@"[Loki] handleFriendRequestMessageIfNeededWithEnvelope:data:message:thread:transaction was called with an envelope that isn't of 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]) { if ([self canFriendRequestBeAutoAcceptedForThread:thread transaction:transaction]) {
[thread saveFriendRequestStatus:LKThreadFriendRequestStatusFriends withTransaction:transaction]; [thread saveFriendRequestStatus:LKThreadFriendRequestStatusFriends withTransaction:transaction];
__block TSOutgoingMessage *existingFriendRequestMessage; __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 // 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 // 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]; 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.friendRequestStatus == LKThreadFriendRequestStatusNone) { return; }
if (thread.isContactFriend) return; if (thread.isContactFriend) return;
// Become happy friends and go on great adventures // Become happy friends and go on great adventures

@ -518,15 +518,10 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// TODO: Handle // TODO: Handle
} }
}]; }];
} } else {
//Maybe need to handle RssFeed
else {
[recipientIds addObjectsFromArray:message.sendingRecipientIds]; [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]]; [recipientIds intersectSet:[NSSet setWithArray:groupThread.groupModel.groupMemberIds]];
// for (NSString *recipientId in recipientIds) {
//
// }
} }
} else if ([thread isKindOfClass:[TSContactThread class]]) { } else if ([thread isKindOfClass:[TSContactThread class]]) {
NSString *recipientContactId = ((TSContactThread *)thread).contactIdentifier; NSString *recipientContactId = ((TSContactThread *)thread).contactIdentifier;
@ -701,7 +696,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
if (thread.isGroupThread) { if (thread.isGroupThread) {
[self saveInfoMessageForGroupMessage:message inThread:thread]; [self saveInfoMessageForGroupMessage:message inThread:thread];
OWSLogInfo(@"group message save here %@ %@ %@", message.customMessage, message.recipientIds.lastObject, message.recipientIds.firstObject);
} }
NSError *error; NSError *error;
@ -729,8 +723,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
} }
}]; }];
} }
OWSLogInfo(@"recipient count: %d", recipientIds.count);
if (recipientIds.count < 1) { if (recipientIds.count < 1) {
// All recipients are already sent or can be skipped. // All recipients are already sent or can be skipped.
@ -986,9 +978,11 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
BOOL isDeviceLinkMessage = [message isKindOfClass:LKDeviceLinkMessage.class]; BOOL isDeviceLinkMessage = [message isKindOfClass:LKDeviceLinkMessage.class];
if (isPublicChatMessage || isDeviceLinkMessage) { if (isPublicChatMessage || isDeviceLinkMessage) {
[self sendMessage:messageSend]; [self sendMessage:messageSend];
} } else if (isGroupMessage) {
else if (isGroupMessage) {
[self sendMessage:messageSend]; [self sendMessage:messageSend];
// TODO: Multi device?
// [[LKAPI getDestinationsFor:contactID] // [[LKAPI getDestinationsFor:contactID]
// .thenOn(OWSDispatch.sendingQueue, ^(NSArray<LKDestination *> *destinations) { // .thenOn(OWSDispatch.sendingQueue, ^(NSArray<LKDestination *> *destinations) {
// // Get master destination // // Get master destination
@ -1025,8 +1019,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// .catchOn(OWSDispatch.sendingQueue, ^(NSError *error) { // .catchOn(OWSDispatch.sendingQueue, ^(NSError *error) {
// [self messageSendDidFail:messageSend deviceMessages:@{} statusCode:0 error:error responseData:nil]; // [self messageSendDidFail:messageSend deviceMessages:@{} statusCode:0 error:error responseData:nil];
// }) retainUntilComplete]; // }) retainUntilComplete];
} } else {
else {
BOOL isSilentMessage = message.isSilent || [message isKindOfClass:LKEphemeralMessage.class] || [message isKindOfClass:OWSOutgoingSyncMessage.class]; BOOL isSilentMessage = message.isSilent || [message isKindOfClass:LKEphemeralMessage.class] || [message isKindOfClass:OWSOutgoingSyncMessage.class];
BOOL isFriendRequestMessage = [message isKindOfClass:LKFriendRequestMessage.class]; BOOL isFriendRequestMessage = [message isKindOfClass:LKFriendRequestMessage.class];
BOOL isSessionRequestMessage = [message isKindOfClass:LKSessionRequestMessage.class]; BOOL isSessionRequestMessage = [message isKindOfClass:LKSessionRequestMessage.class];
@ -1683,8 +1676,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
}]; }];
BOOL isPublicChatMessage = message.thread.isGroupThread && ((TSGroupThread *)message.thread).isPublicChat; 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]); BOOL shouldSendTranscript = (AreRecipientUpdatesEnabled() || !message.hasSyncedTranscript) && !isNoteToSelf && !isPublicChatMessage && !([message isKindOfClass:LKDeviceLinkMessage.class]);
if (!shouldSendTranscript) { if (!shouldSendTranscript) {
@ -2117,19 +2108,16 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
OWSAssertDebug(thread); OWSAssertDebug(thread);
if (message.groupMetaMessage == TSGroupMetaMessageDeliver) { if (message.groupMetaMessage == TSGroupMetaMessageDeliver) {
OWSLogInfo(@"save for group message deliver");
// TODO: Why is this necessary? // TODO: Why is this necessary?
[message save]; [message save];
} else if (message.groupMetaMessage == TSGroupMetaMessageQuit) { } else if (message.groupMetaMessage == TSGroupMetaMessageQuit) {
// MJK TODO - remove senderTimestamp // MJK TODO - remove senderTimestamp
OWSLogInfo(@"save for group message quit: %@", message.customMessage);
[[[TSInfoMessage alloc] initWithTimestamp:message.timestamp [[[TSInfoMessage alloc] initWithTimestamp:message.timestamp
inThread:thread inThread:thread
messageType:TSInfoMessageTypeGroupQuit messageType:TSInfoMessageTypeGroupQuit
customMessage:message.customMessage] save]; customMessage:message.customMessage] save];
} else { } else {
// MJK TODO - remove senderTimestamp // MJK TODO - remove senderTimestamp
OWSLogInfo(@"save for group message update: %@", message.customMessage);
[[[TSInfoMessage alloc] initWithTimestamp:message.timestamp [[[TSInfoMessage alloc] initWithTimestamp:message.timestamp
inThread:thread inThread:thread
messageType:TSInfoMessageTypeGroupUpdate messageType:TSInfoMessageTypeGroupUpdate

@ -149,9 +149,9 @@ const int32_t kGroupIdLength = 16;
[newMembersNames componentsJoinedByString:@", "]]]; [newMembersNames componentsJoinedByString:@", "]]];
} }
if ([_removedMembers count] > 0) { if (_removedMembers.count > 0) {
NSString *masterDeviceHexEncodedPublicKey = [NSUserDefaults.standardUserDefaults stringForKey:@"masterDeviceHexEncodedPublicKey"]; NSString *masterDeviceHexEncodedPublicKey = [NSUserDefaults.standardUserDefaults stringForKey:@"masterDeviceHexEncodedPublicKey"];
NSString *hexEncodedPublicKey = masterDeviceHexEncodedPublicKey != nil ? masterDeviceHexEncodedPublicKey : [TSAccountManager localNumber]; NSString *hexEncodedPublicKey = masterDeviceHexEncodedPublicKey != nil ? masterDeviceHexEncodedPublicKey : TSAccountManager.localNumber;
if ([_removedMembers containsObject:hexEncodedPublicKey]) { if ([_removedMembers containsObject:hexEncodedPublicKey]) {
updatedGroupInfoString = [updatedGroupInfoString updatedGroupInfoString = [updatedGroupInfoString
stringByAppendingString:NSLocalizedString(@"YOU_WERE_REMOVED", @"")]; stringByAppendingString:NSLocalizedString(@"YOU_WERE_REMOVED", @"")];

Loading…
Cancel
Save