Fix incorrect message being shown when user was removed from the group.
Hide input bar correctly when we leave a group.
This commit is contained in:
parent
85a4dd0546
commit
8c26e16ef0
|
@ -424,6 +424,10 @@ typedef enum : NSUInteger {
|
|||
selector:@selector(handleThreadSessionRestoreDevicesChangedNotifiaction:)
|
||||
name:NSNotification.threadSessionRestoreDevicesChanged
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(handleGroupThreadLeftNotification:)
|
||||
name:NSNotification.groupThreadLeft
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(handleCalculatingPoWNotification:)
|
||||
name:NSNotification.calculatingPoW
|
||||
|
@ -507,6 +511,20 @@ typedef enum : NSUInteger {
|
|||
[self ensureBannerState];
|
||||
}
|
||||
|
||||
- (void)handleGroupThreadLeftNotification:(NSNotification *)notification
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
// Check thread
|
||||
NSString *threadID = (NSString *)notification.object;
|
||||
if (![threadID isEqualToString:self.thread.uniqueId]) { return; }
|
||||
// Ensure thread instance is up to date
|
||||
[self.thread reload];
|
||||
// Update UI
|
||||
[self hideInputIfNeeded];
|
||||
[self resetContentAndLayout];
|
||||
}
|
||||
|
||||
- (void)handleThreadFriendRequestStatusChangedNotification:(NSNotification *)notification
|
||||
{
|
||||
// Check thread
|
||||
|
@ -687,7 +705,7 @@ typedef enum : NSUInteger {
|
|||
|
||||
if (self.thread.isGroupThread) {
|
||||
TSGroupThread *thread = (TSGroupThread *)self.thread;
|
||||
if (thread.isRSSFeed) { return; }
|
||||
if (!thread.isPublicChat) { return; }
|
||||
__block LKPublicChat *publicChat;
|
||||
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
publicChat = [LKDatabaseUtilities getPublicChatForThreadID:thread.uniqueId transaction:transaction];
|
||||
|
|
|
@ -249,6 +249,11 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific
|
|||
}
|
||||
self.groupModel.groupMemberIds = newGroupMemberIDs.allObjects;
|
||||
[self saveWithTransaction:transaction];
|
||||
|
||||
[transaction addCompletionQueue:dispatch_get_main_queue()
|
||||
completionBlock:^{
|
||||
[NSNotificationCenter.defaultCenter postNotificationName:NSNotification.groupThreadLeft object:self.uniqueId];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)softDeleteGroupThreadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
|
|
|
@ -4,6 +4,7 @@ public extension Notification.Name {
|
|||
// State changes
|
||||
public static let contactOnlineStatusChanged = Notification.Name("contactOnlineStatusChanged")
|
||||
public static let threadFriendRequestStatusChanged = Notification.Name("threadFriendRequestStatusChanged")
|
||||
public static let groupThreadLeft = Notification.Name("groupThreadLeft")
|
||||
public static let messageFriendRequestStatusChanged = Notification.Name("messageFriendRequestStatusChanged")
|
||||
public static let threadDeleted = Notification.Name("threadDeleted")
|
||||
public static let threadSessionRestoreDevicesChanged = Notification.Name("threadSessionRestoreDevicesChanged")
|
||||
|
@ -26,6 +27,7 @@ public extension Notification.Name {
|
|||
// State changes
|
||||
@objc public static let contactOnlineStatusChanged = Notification.Name.contactOnlineStatusChanged.rawValue as NSString
|
||||
@objc public static let threadFriendRequestStatusChanged = Notification.Name.threadFriendRequestStatusChanged.rawValue as NSString
|
||||
@objc public static let groupThreadLeft = Notification.Name.groupThreadLeft.rawValue as NSString
|
||||
@objc public static let messageFriendRequestStatusChanged = Notification.Name.messageFriendRequestStatusChanged.rawValue as NSString
|
||||
@objc public static let threadDeleted = Notification.Name.threadDeleted.rawValue as NSString
|
||||
@objc public static let threadSessionRestoreDevicesChanged = Notification.Name.threadSessionRestoreDevicesChanged.rawValue as NSString
|
||||
|
|
|
@ -1455,6 +1455,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
|
||||
NSString *hexEncodedPublicKey = ([LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in:transaction] ?: envelope.source);
|
||||
NSString *localHexEncodedPublicKey = OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey;
|
||||
NSString *ourHexEncodedPublicKey = ([LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:localHexEncodedPublicKey in:transaction] ?: localHexEncodedPublicKey);
|
||||
|
||||
// Group messages create the group if it doesn't already exist.
|
||||
//
|
||||
|
@ -1464,7 +1466,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
// Loki: Determine removed members
|
||||
removedMemberIds = [NSMutableSet setWithArray:oldGroupThread.groupModel.groupMemberIds];
|
||||
[removedMemberIds minusSet:newMemberIds];
|
||||
[removedMemberIds removeObject:hexEncodedPublicKey];
|
||||
}
|
||||
|
||||
// Only set the display name here, the logic for updating profile pictures is handled when we're setting profile key
|
||||
|
@ -1508,6 +1509,11 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
customMessage:updateGroupInfo];
|
||||
[infoMessage saveWithTransaction:transaction];
|
||||
|
||||
// If we were the one that was removed then we need to leave the group
|
||||
if ([removedMemberIds containsObject:ourHexEncodedPublicKey]) {
|
||||
[newGroupThread leaveGroupWithTransaction:transaction];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
case SSKProtoGroupContextTypeQuit: {
|
||||
|
@ -1529,6 +1535,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
inThread:oldGroupThread
|
||||
messageType:TSInfoMessageTypeGroupUpdate
|
||||
customMessage:updateGroupInfo] saveWithTransaction:transaction];
|
||||
|
||||
// If we were the one that quit then we need to leave the group
|
||||
if ([newMemberIds containsObject:ourHexEncodedPublicKey]) {
|
||||
[oldGroupThread leaveGroupWithTransaction:transaction];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
case SSKProtoGroupContextTypeDeliver: {
|
||||
|
|
|
@ -128,7 +128,7 @@ const int32_t kGroupIdLength = 16;
|
|||
|
||||
NSMutableSet *membersWhoLeft = [NSMutableSet setWithSet:oldMembers];
|
||||
[membersWhoLeft minusSet:newMembers];
|
||||
[membersWhoLeft minusSet:_removedMembers];
|
||||
[membersWhoLeft minusSet:newModel.removedMembers];
|
||||
|
||||
|
||||
if ([membersWhoLeft count] > 0) {
|
||||
|
@ -145,15 +145,15 @@ const int32_t kGroupIdLength = 16;
|
|||
updatedGroupInfoString = @"New members joined";
|
||||
}
|
||||
|
||||
if (_removedMembers.count > 0) {
|
||||
if (newModel.removedMembers.count > 0) {
|
||||
NSString *masterDeviceHexEncodedPublicKey = [NSUserDefaults.standardUserDefaults stringForKey:@"masterDeviceHexEncodedPublicKey"];
|
||||
NSString *hexEncodedPublicKey = masterDeviceHexEncodedPublicKey != nil ? masterDeviceHexEncodedPublicKey : TSAccountManager.localNumber;
|
||||
if ([_removedMembers containsObject:hexEncodedPublicKey]) {
|
||||
if ([newModel.removedMembers containsObject:hexEncodedPublicKey]) {
|
||||
updatedGroupInfoString = [updatedGroupInfoString
|
||||
stringByAppendingString:NSLocalizedString(@"YOU_WERE_REMOVED", @"")];
|
||||
}
|
||||
else {
|
||||
NSArray *removedMembersNames = [[_removedMembers allObjects] map:^NSString*(NSString* item) {
|
||||
NSArray *removedMembersNames = [[newModel.removedMembers allObjects] map:^NSString*(NSString* item) {
|
||||
return [contactsManager displayNameForPhoneIdentifier:item];
|
||||
}];
|
||||
if ([removedMembersNames count] > 1) {
|
||||
|
|
Loading…
Reference in New Issue