mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Merge pull request #154 from loki-project/closed-group-fixes
Closed group fixes
This commit is contained in:
commit
3b103450b6
|
@ -424,6 +424,10 @@ typedef enum : NSUInteger {
|
||||||
selector:@selector(handleThreadSessionRestoreDevicesChangedNotifiaction:)
|
selector:@selector(handleThreadSessionRestoreDevicesChangedNotifiaction:)
|
||||||
name:NSNotification.threadSessionRestoreDevicesChanged
|
name:NSNotification.threadSessionRestoreDevicesChanged
|
||||||
object:nil];
|
object:nil];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(handleGroupThreadUpdatedNotification:)
|
||||||
|
name:NSNotification.groupThreadUpdated
|
||||||
|
object:nil];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(handleCalculatingPoWNotification:)
|
selector:@selector(handleCalculatingPoWNotification:)
|
||||||
name:NSNotification.calculatingPoW
|
name:NSNotification.calculatingPoW
|
||||||
|
@ -507,6 +511,20 @@ typedef enum : NSUInteger {
|
||||||
[self ensureBannerState];
|
[self ensureBannerState];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)handleGroupThreadUpdatedNotification:(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
|
- (void)handleThreadFriendRequestStatusChangedNotification:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
// Check thread
|
// Check thread
|
||||||
|
@ -687,7 +705,7 @@ typedef enum : NSUInteger {
|
||||||
|
|
||||||
if (self.thread.isGroupThread) {
|
if (self.thread.isGroupThread) {
|
||||||
TSGroupThread *thread = (TSGroupThread *)self.thread;
|
TSGroupThread *thread = (TSGroupThread *)self.thread;
|
||||||
if (thread.isRSSFeed) { return; }
|
if (!thread.isPublicChat) { return; }
|
||||||
__block LKPublicChat *publicChat;
|
__block LKPublicChat *publicChat;
|
||||||
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||||
publicChat = [LKDatabaseUtilities getPublicChatForThreadID:thread.uniqueId transaction:transaction];
|
publicChat = [LKDatabaseUtilities getPublicChatForThreadID:thread.uniqueId transaction:transaction];
|
||||||
|
|
|
@ -45,6 +45,7 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId;
|
||||||
+ (NSArray<TSGroupThread *> *)groupThreadsWithRecipientId:(NSString *)recipientId
|
+ (NSArray<TSGroupThread *> *)groupThreadsWithRecipientId:(NSString *)recipientId
|
||||||
transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||||
|
|
||||||
|
- (void)setGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||||
- (void)leaveGroupWithSneakyTransaction;
|
- (void)leaveGroupWithSneakyTransaction;
|
||||||
- (void)leaveGroupWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
- (void)leaveGroupWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||||
|
|
||||||
|
|
|
@ -232,6 +232,16 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific
|
||||||
return NSLocalizedString(@"NEW_GROUP_DEFAULT_TITLE", @"");
|
return NSLocalizedString(@"NEW_GROUP_DEFAULT_TITLE", @"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||||
|
{
|
||||||
|
self.groupModel = newGroupModel;
|
||||||
|
[self saveWithTransaction:transaction];
|
||||||
|
|
||||||
|
[transaction addCompletionQueue:dispatch_get_main_queue() completionBlock:^{
|
||||||
|
[NSNotificationCenter.defaultCenter postNotificationName:NSNotification.groupThreadUpdated object:self.uniqueId];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)leaveGroupWithSneakyTransaction
|
- (void)leaveGroupWithSneakyTransaction
|
||||||
{
|
{
|
||||||
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||||
|
@ -249,6 +259,10 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific
|
||||||
}
|
}
|
||||||
self.groupModel.groupMemberIds = newGroupMemberIDs.allObjects;
|
self.groupModel.groupMemberIds = newGroupMemberIDs.allObjects;
|
||||||
[self saveWithTransaction:transaction];
|
[self saveWithTransaction:transaction];
|
||||||
|
|
||||||
|
[transaction addCompletionQueue:dispatch_get_main_queue() completionBlock:^{
|
||||||
|
[NSNotificationCenter.defaultCenter postNotificationName:NSNotification.groupThreadUpdated object:self.uniqueId];
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)softDeleteGroupThreadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
- (void)softDeleteGroupThreadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||||
|
|
|
@ -4,6 +4,7 @@ public extension Notification.Name {
|
||||||
// State changes
|
// State changes
|
||||||
public static let contactOnlineStatusChanged = Notification.Name("contactOnlineStatusChanged")
|
public static let contactOnlineStatusChanged = Notification.Name("contactOnlineStatusChanged")
|
||||||
public static let threadFriendRequestStatusChanged = Notification.Name("threadFriendRequestStatusChanged")
|
public static let threadFriendRequestStatusChanged = Notification.Name("threadFriendRequestStatusChanged")
|
||||||
|
public static let groupThreadUpdated = Notification.Name("groupThreadUpdated")
|
||||||
public static let messageFriendRequestStatusChanged = Notification.Name("messageFriendRequestStatusChanged")
|
public static let messageFriendRequestStatusChanged = Notification.Name("messageFriendRequestStatusChanged")
|
||||||
public static let threadDeleted = Notification.Name("threadDeleted")
|
public static let threadDeleted = Notification.Name("threadDeleted")
|
||||||
public static let threadSessionRestoreDevicesChanged = Notification.Name("threadSessionRestoreDevicesChanged")
|
public static let threadSessionRestoreDevicesChanged = Notification.Name("threadSessionRestoreDevicesChanged")
|
||||||
|
@ -26,6 +27,7 @@ public extension Notification.Name {
|
||||||
// State changes
|
// State changes
|
||||||
@objc public static let contactOnlineStatusChanged = Notification.Name.contactOnlineStatusChanged.rawValue as NSString
|
@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 threadFriendRequestStatusChanged = Notification.Name.threadFriendRequestStatusChanged.rawValue as NSString
|
||||||
|
@objc public static let groupThreadUpdated = Notification.Name.groupThreadUpdated.rawValue as NSString
|
||||||
@objc public static let messageFriendRequestStatusChanged = Notification.Name.messageFriendRequestStatusChanged.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 threadDeleted = Notification.Name.threadDeleted.rawValue as NSString
|
||||||
@objc public static let threadSessionRestoreDevicesChanged = Notification.Name.threadSessionRestoreDevicesChanged.rawValue as NSString
|
@objc public static let threadSessionRestoreDevicesChanged = Notification.Name.threadSessionRestoreDevicesChanged.rawValue as NSString
|
||||||
|
|
|
@ -589,6 +589,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
[TSGroupThread threadWithGroupId:dataMessage.group.id transaction:transaction];
|
[TSGroupThread threadWithGroupId:dataMessage.group.id transaction:transaction];
|
||||||
|
|
||||||
if (groupThread) {
|
if (groupThread) {
|
||||||
|
BOOL isClosedGroup = (groupThread.groupModel.groupType == closedGroup);
|
||||||
|
if (isClosedGroup && dataMessage.group.type == SSKProtoGroupContextTypeDeliver) {
|
||||||
|
// Only allow messages from group members
|
||||||
|
if (![groupThread isUserInGroup:envelope.source transaction:transaction]) { return; }
|
||||||
|
}
|
||||||
|
|
||||||
if (dataMessage.group.type != SSKProtoGroupContextTypeUpdate) {
|
if (dataMessage.group.type != SSKProtoGroupContextTypeUpdate) {
|
||||||
if (![groupThread isLocalUserInGroupWithTransaction:transaction]) {
|
if (![groupThread isLocalUserInGroupWithTransaction:transaction]) {
|
||||||
OWSLogInfo(@"Ignoring messages for left group.");
|
OWSLogInfo(@"Ignoring messages for left group.");
|
||||||
|
@ -1455,6 +1461,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString *hexEncodedPublicKey = ([LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in:transaction] ?: envelope.source);
|
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.
|
// Group messages create the group if it doesn't already exist.
|
||||||
//
|
//
|
||||||
|
@ -1464,7 +1472,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
// Loki: Determine removed members
|
// Loki: Determine removed members
|
||||||
removedMemberIds = [NSMutableSet setWithArray:oldGroupThread.groupModel.groupMemberIds];
|
removedMemberIds = [NSMutableSet setWithArray:oldGroupThread.groupModel.groupMemberIds];
|
||||||
[removedMemberIds minusSet:newMemberIds];
|
[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
|
// Only set the display name here, the logic for updating profile pictures is handled when we're setting profile key
|
||||||
|
@ -1489,11 +1496,14 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
newGroupModel.removedMembers = removedMemberIds;
|
newGroupModel.removedMembers = removedMemberIds;
|
||||||
NSString *updateGroupInfo = [newGroupThread.groupModel getInfoStringAboutUpdateTo:newGroupModel
|
NSString *updateGroupInfo = [newGroupThread.groupModel getInfoStringAboutUpdateTo:newGroupModel
|
||||||
contactsManager:self.contactsManager];
|
contactsManager:self.contactsManager];
|
||||||
newGroupThread.groupModel = newGroupModel;
|
|
||||||
[newGroupThread saveWithTransaction:transaction];
|
[newGroupThread setGroupModel:newGroupModel withTransaction:transaction];
|
||||||
|
|
||||||
// Loki: Try to establish sessions with all members when a group is created or updated
|
BOOL wasCurrentUserRemovedFromGroup = [removedMemberIds containsObject:ourHexEncodedPublicKey];
|
||||||
[self establishSessionsWithMembersIfNeeded: newMemberIds.allObjects forThread:newGroupThread transaction:transaction];
|
if (!wasCurrentUserRemovedFromGroup) {
|
||||||
|
// 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
|
[[OWSDisappearingMessagesJob sharedJob] becomeConsistentWithDisappearingDuration:dataMessage.expireTimer
|
||||||
thread:newGroupThread
|
thread:newGroupThread
|
||||||
|
@ -1508,11 +1518,16 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
customMessage:updateGroupInfo];
|
customMessage:updateGroupInfo];
|
||||||
[infoMessage saveWithTransaction:transaction];
|
[infoMessage saveWithTransaction:transaction];
|
||||||
|
|
||||||
|
// If we were the one that was removed then we need to leave the group
|
||||||
|
if (wasCurrentUserRemovedFromGroup) {
|
||||||
|
[newGroupThread leaveGroupWithTransaction:transaction];
|
||||||
|
}
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
case SSKProtoGroupContextTypeQuit: {
|
case SSKProtoGroupContextTypeQuit: {
|
||||||
if (!oldGroupThread) {
|
if (!oldGroupThread) {
|
||||||
OWSLogWarn(@"ignoring quit group message from unknown group.");
|
OWSLogWarn(@"Ignoring quit group message from unknown group.");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
newMemberIds = [NSMutableSet setWithArray:oldGroupThread.groupModel.groupMemberIds];
|
newMemberIds = [NSMutableSet setWithArray:oldGroupThread.groupModel.groupMemberIds];
|
||||||
|
@ -1529,6 +1544,13 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
inThread:oldGroupThread
|
inThread:oldGroupThread
|
||||||
messageType:TSInfoMessageTypeGroupUpdate
|
messageType:TSInfoMessageTypeGroupUpdate
|
||||||
customMessage:updateGroupInfo] saveWithTransaction:transaction];
|
customMessage:updateGroupInfo] saveWithTransaction:transaction];
|
||||||
|
|
||||||
|
// If we were the one that quit then we need to leave the group (only relevant for slave
|
||||||
|
// devices in a multi device context)
|
||||||
|
if ([newMemberIds containsObject:ourHexEncodedPublicKey]) {
|
||||||
|
[oldGroupThread leaveGroupWithTransaction:transaction];
|
||||||
|
}
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
case SSKProtoGroupContextTypeDeliver: {
|
case SSKProtoGroupContextTypeDeliver: {
|
||||||
|
|
|
@ -128,7 +128,7 @@ const int32_t kGroupIdLength = 16;
|
||||||
|
|
||||||
NSMutableSet *membersWhoLeft = [NSMutableSet setWithSet:oldMembers];
|
NSMutableSet *membersWhoLeft = [NSMutableSet setWithSet:oldMembers];
|
||||||
[membersWhoLeft minusSet:newMembers];
|
[membersWhoLeft minusSet:newMembers];
|
||||||
[membersWhoLeft minusSet:_removedMembers];
|
[membersWhoLeft minusSet:newModel.removedMembers];
|
||||||
|
|
||||||
|
|
||||||
if ([membersWhoLeft count] > 0) {
|
if ([membersWhoLeft count] > 0) {
|
||||||
|
@ -145,15 +145,15 @@ const int32_t kGroupIdLength = 16;
|
||||||
updatedGroupInfoString = @"New members joined";
|
updatedGroupInfoString = @"New members joined";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_removedMembers.count > 0) {
|
if (newModel.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 ([newModel.removedMembers containsObject:hexEncodedPublicKey]) {
|
||||||
updatedGroupInfoString = [updatedGroupInfoString
|
updatedGroupInfoString = [updatedGroupInfoString
|
||||||
stringByAppendingString:NSLocalizedString(@"YOU_WERE_REMOVED", @"")];
|
stringByAppendingString:NSLocalizedString(@"YOU_WERE_REMOVED", @"")];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
NSArray *removedMembersNames = [[_removedMembers allObjects] map:^NSString*(NSString* item) {
|
NSArray *removedMembersNames = [[newModel.removedMembers allObjects] map:^NSString*(NSString* item) {
|
||||||
return [contactsManager displayNameForPhoneIdentifier:item];
|
return [contactsManager displayNameForPhoneIdentifier:item];
|
||||||
}];
|
}];
|
||||||
if ([removedMembersNames count] > 1) {
|
if ([removedMembersNames count] > 1) {
|
||||||
|
|
Loading…
Reference in a new issue