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:)
|
||||
name:NSNotification.threadSessionRestoreDevicesChanged
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(handleGroupThreadUpdatedNotification:)
|
||||
name:NSNotification.groupThreadUpdated
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(handleCalculatingPoWNotification:)
|
||||
name:NSNotification.calculatingPoW
|
||||
|
@ -507,6 +511,20 @@ typedef enum : NSUInteger {
|
|||
[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
|
||||
{
|
||||
// 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];
|
||||
|
|
|
@ -45,6 +45,7 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId;
|
|||
+ (NSArray<TSGroupThread *> *)groupThreadsWithRecipientId:(NSString *)recipientId
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
- (void)setGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
- (void)leaveGroupWithSneakyTransaction;
|
||||
- (void)leaveGroupWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
|
|
|
@ -232,6 +232,16 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific
|
|||
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
|
||||
{
|
||||
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
|
@ -249,6 +259,10 @@ 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.groupThreadUpdated 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 groupThreadUpdated = Notification.Name("groupThreadUpdated")
|
||||
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 groupThreadUpdated = Notification.Name.groupThreadUpdated.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
|
||||
|
|
|
@ -589,6 +589,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[TSGroupThread threadWithGroupId:dataMessage.group.id transaction:transaction];
|
||||
|
||||
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 (![groupThread isLocalUserInGroupWithTransaction:transaction]) {
|
||||
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 *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 +1472,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
|
||||
|
@ -1489,11 +1496,14 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
newGroupModel.removedMembers = removedMemberIds;
|
||||
NSString *updateGroupInfo = [newGroupThread.groupModel getInfoStringAboutUpdateTo:newGroupModel
|
||||
contactsManager:self.contactsManager];
|
||||
newGroupThread.groupModel = newGroupModel;
|
||||
[newGroupThread saveWithTransaction:transaction];
|
||||
|
||||
// Loki: Try to establish sessions with all members when a group is created or updated
|
||||
[self establishSessionsWithMembersIfNeeded: newMemberIds.allObjects forThread:newGroupThread transaction:transaction];
|
||||
|
||||
[newGroupThread setGroupModel:newGroupModel withTransaction:transaction];
|
||||
|
||||
BOOL wasCurrentUserRemovedFromGroup = [removedMemberIds containsObject:ourHexEncodedPublicKey];
|
||||
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
|
||||
thread:newGroupThread
|
||||
|
@ -1508,11 +1518,16 @@ 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 (wasCurrentUserRemovedFromGroup) {
|
||||
[newGroupThread leaveGroupWithTransaction:transaction];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
case SSKProtoGroupContextTypeQuit: {
|
||||
if (!oldGroupThread) {
|
||||
OWSLogWarn(@"ignoring quit group message from unknown group.");
|
||||
OWSLogWarn(@"Ignoring quit group message from unknown group.");
|
||||
return nil;
|
||||
}
|
||||
newMemberIds = [NSMutableSet setWithArray:oldGroupThread.groupModel.groupMemberIds];
|
||||
|
@ -1529,6 +1544,13 @@ 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 (only relevant for slave
|
||||
// devices in a multi device context)
|
||||
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 a new issue