session-ios/Signal/src/view controllers/TSGroupModel.m
Frederic Jacobs 9872bed428 Addressing some storage related fixes.
- Tested on jailbroken phone that correct files are getting encrypted
- Fixes #557
- Stores image file extension
- Addresses issue with deletion of debug logs
- Preventing user to browse in app if not registered with TS server
2015-02-20 22:59:38 +01:00

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