Merge pull request #83 from loki-project/bug-fixes

Bug Fixes
pull/84/head
gmbnt 4 years ago committed by GitHub
commit 3c63f237c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,10 +4,16 @@ final class NewClosedGroupVC : UIViewController, UITableViewDataSource, UITableV
private lazy var contacts: [String] = {
var result: [String] = []
TSContactThread.enumerateCollectionObjects { object, _ in
guard let thread = object as? TSContactThread, thread.isContactFriend else { return }
let hexEncodedPublicKey = thread.contactIdentifier()
result.append(hexEncodedPublicKey)
let storage = OWSPrimaryStorage.shared()
storage.dbReadConnection.read { transaction in
TSContactThread.enumerateCollectionObjects(with: transaction) { object, _ in
guard let thread = object as? TSContactThread, thread.isContactFriend else { return }
let hexEncodedPublicKey = thread.contactIdentifier()
// We shouldn't be able to add slave devices to groups
if (storage.getMasterHexEncodedPublicKey(for: hexEncodedPublicKey, in: transaction) == nil) {
result.append(hexEncodedPublicKey)
}
}
}
func getDisplayName(for hexEncodedPublicKey: String) -> String {
return UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? "Unknown Contact"

@ -10,10 +10,12 @@ public enum GroupUtilities {
}
public static func getClosedGroupMembers(_ closedGroup: TSGroupThread, with transaction: YapDatabaseReadTransaction) -> [String] {
let storage = OWSPrimaryStorage.shared()
let userHexEncodedPublicKey = getUserHexEncodedPublicKey()
var linkedDeviceHexEncodedPublicKeys = LokiDatabaseUtilities.getLinkedDeviceHexEncodedPublicKeys(for: userHexEncodedPublicKey, in: transaction)
linkedDeviceHexEncodedPublicKeys.remove(userHexEncodedPublicKey) // Show the user as a member
return closedGroup.groupModel.groupMemberIds.filter { !linkedDeviceHexEncodedPublicKeys.contains($0) }
return closedGroup.groupModel.groupMemberIds.filter { member in
// Don't show any slave devices
return storage.getMasterHexEncodedPublicKey(for: member, in: transaction) == nil
}
}
public static func getClosedGroupMemberCount(_ closedGroup: TSGroupThread) -> Int {

@ -1402,6 +1402,8 @@ NS_ASSUME_NONNULL_BEGIN
return nil;
}
}
NSString *hexEncodedPublicKey = ([LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in:transaction] ?: envelope.source);
// Group messages create the group if it doesn't already exist.
//
@ -1411,17 +1413,15 @@ NS_ASSUME_NONNULL_BEGIN
// Loki: Try to figure out removed members
removedMemberIds = [NSMutableSet setWithArray:oldGroupThread.groupModel.groupMemberIds];
[removedMemberIds minusSet:newMemberIds];
[removedMemberIds removeObject:envelope.source];
[removedMemberIds removeObject:hexEncodedPublicKey];
}
NSString *hexEncodedPublicKey = ([LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in:transaction] ?: envelope.source);
// 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];
switch (dataMessage.group.type) {
case SSKProtoGroupContextTypeUpdate: {
if (oldGroupThread && ![oldGroupThread.groupModel.groupAdminIds containsObject:envelope.source]) {
if (oldGroupThread && ![oldGroupThread.groupModel.groupAdminIds containsObject:hexEncodedPublicKey]) {
[LKLogger print:[NSString stringWithFormat:@"[Loki] Received a group update from a non-admin user for %@; ignoring.", [LKGroupUtilities getEncodedGroupID:groupId]]];
return nil;
}
@ -1464,12 +1464,12 @@ NS_ASSUME_NONNULL_BEGIN
OWSLogWarn(@"ignoring quit group message from unknown group.");
return nil;
}
[newMemberIds removeObject:envelope.source];
[newMemberIds removeObject:hexEncodedPublicKey];
oldGroupThread.groupModel.groupMemberIds = [newMemberIds.allObjects mutableCopy];
[oldGroupThread saveWithTransaction:transaction];
NSString *nameString =
[self.contactsManager displayNameForPhoneIdentifier:envelope.source transaction:transaction];
[self.contactsManager displayNameForPhoneIdentifier:hexEncodedPublicKey transaction:transaction];
NSString *updateGroupInfo =
[NSString stringWithFormat:NSLocalizedString(@"GROUP_MEMBER_LEFT", @""), nameString];
// MJK TODO - should be safe to remove senderTimestamp
@ -1487,7 +1487,7 @@ NS_ASSUME_NONNULL_BEGIN
[[OWSDisappearingMessagesJob sharedJob] becomeConsistentWithDisappearingDuration:dataMessage.expireTimer
thread:oldGroupThread
createdByRemoteRecipientId:envelope.source
createdByRemoteRecipientId:hexEncodedPublicKey
createdInExistingGroup:NO
transaction:transaction];
@ -1514,7 +1514,7 @@ NS_ASSUME_NONNULL_BEGIN
TSIncomingMessage *incomingMessage =
[[TSIncomingMessage alloc] initIncomingMessageWithTimestamp:timestamp
inThread:oldGroupThread
authorId:envelope.source
authorId:hexEncodedPublicKey
sourceDeviceId:envelope.sourceDevice
messageBody:body
attachmentIds:@[]
@ -1540,7 +1540,7 @@ NS_ASSUME_NONNULL_BEGIN
// Loki: Don't process friend requests in group chats
if (body.length == 0 && attachmentPointers.count < 1 && !contact) {
OWSLogWarn(@"ignoring empty incoming message from: %@ for group: %@ with timestamp: %lu",
envelopeAddress(envelope),
hexEncodedPublicKey,
groupId,
(unsigned long)timestamp);
return nil;

Loading…
Cancel
Save