mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
3.4 KiB
Objective-C
91 lines
3.4 KiB
Objective-C
//
|
|
// GroupModel.m
|
|
// Signal
|
|
//
|
|
// Created by Frederic Jacobs on 13/11/14.
|
|
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
#import "TSGroupModel.h"
|
|
|
|
NSString * const TSAttachementGroupAvatarFileRelationshipEdge = @"TSAttachementGroupAvatarFileEdge";
|
|
|
|
@implementation TSGroupModel
|
|
|
|
-(instancetype)initWithTitle:(NSString*)title memberIds:(NSMutableArray*)memberIds image:(UIImage*)image groupId:(NSData *)groupId associatedAttachmentId:(NSString*)attachmentId {
|
|
_groupName = title;
|
|
_groupMemberIds = [memberIds copy];
|
|
_groupImage = image;
|
|
_associatedAttachmentId = attachmentId;
|
|
_groupId = groupId;
|
|
|
|
return self;
|
|
}
|
|
|
|
- (BOOL)isEqual:(id)other {
|
|
if (other == self) {
|
|
return YES;
|
|
}
|
|
if (!other || ![other isKindOfClass:[self class]]) {
|
|
return NO;
|
|
}
|
|
return [self isEqualToGroupModel:other];
|
|
}
|
|
|
|
- (BOOL)isEqualToGroupModel:(TSGroupModel *)other {
|
|
if (self == other)
|
|
return YES;
|
|
if(![_groupId isEqualToData:other.groupId] ) {
|
|
return NO;
|
|
}
|
|
if (![_groupName isEqual:other.groupName]) {
|
|
return NO;
|
|
}
|
|
if( !(_groupImage!=nil && other.groupImage!=nil && [UIImagePNGRepresentation(_groupImage) isEqualToData:UIImagePNGRepresentation(other.groupImage)])) {
|
|
return NO;
|
|
}
|
|
NSMutableArray* compareMyGroupMemberIds = [NSMutableArray arrayWithArray:_groupMemberIds];
|
|
[compareMyGroupMemberIds removeObjectsInArray:other.groupMemberIds];
|
|
if([compareMyGroupMemberIds count] > 0 ) {
|
|
return NO;
|
|
}
|
|
return YES;
|
|
}
|
|
|
|
- (NSString*) getInfoStringAboutUpdateTo:(TSGroupModel*)newModel {
|
|
NSString* updatedGroupInfoString = @"";
|
|
if (self == newModel) {
|
|
return NSLocalizedString(@"GROUP_UPDATED", @"");
|
|
}
|
|
if (![_groupName isEqual:newModel.groupName]) {
|
|
updatedGroupInfoString = [updatedGroupInfoString stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"GROUP_TITLE_CHANGED", @""),newModel.groupName]];
|
|
}
|
|
if(_groupImage!=nil && newModel.groupImage!=nil && !([UIImagePNGRepresentation(_groupImage) isEqualToData:UIImagePNGRepresentation(newModel.groupImage)])) {
|
|
updatedGroupInfoString = [updatedGroupInfoString stringByAppendingString:NSLocalizedString(@"GROUP_AVATAR_CHANGED", @"")];
|
|
}
|
|
if([updatedGroupInfoString length]==0) {
|
|
updatedGroupInfoString = NSLocalizedString(@"GROUP_UPDATED", @"");
|
|
}
|
|
NSSet* oldMembers = [NSSet setWithArray:_groupMemberIds];
|
|
NSSet* newMembers = [NSSet setWithArray:newModel.groupMemberIds];
|
|
|
|
NSMutableSet *membersWhoJoined = [NSMutableSet setWithSet:newMembers];
|
|
[membersWhoJoined minusSet:oldMembers];
|
|
|
|
NSMutableSet *membersWhoLeft = [NSMutableSet setWithSet:oldMembers];
|
|
[membersWhoLeft minusSet:newMembers];
|
|
|
|
|
|
if([membersWhoLeft count] > 0 ) {
|
|
updatedGroupInfoString = [updatedGroupInfoString stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"GROUP_MEMBER_LEFT", @""),[[membersWhoLeft allObjects] componentsJoinedByString:@", "]]];
|
|
}
|
|
|
|
if([membersWhoJoined count] > 0 ) {
|
|
updatedGroupInfoString = [updatedGroupInfoString stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"GROUP_MEMBER_JOINED", @""),[[membersWhoJoined allObjects] componentsJoinedByString:@", "]]];
|
|
}
|
|
|
|
return updatedGroupInfoString;
|
|
}
|
|
|
|
@end
|