mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
The images for group avatars are stored directly in the datbase, which is fine since they are small. But then there's no reason to have them lingering on the filesystem. Also removed the unused group associatedAttachmentId property. // FREEBIE
102 lines
3.6 KiB
Objective-C
102 lines
3.6 KiB
Objective-C
// Created by Frederic Jacobs on 13/11/14.
|
|
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
|
|
|
#import "TSGroupModel.h"
|
|
|
|
@implementation TSGroupModel
|
|
|
|
#if TARGET_OS_IOS
|
|
- (instancetype)initWithTitle:(NSString *)title
|
|
memberIds:(NSMutableArray *)memberIds
|
|
image:(UIImage *)image
|
|
groupId:(NSData *)groupId
|
|
{
|
|
_groupName = title;
|
|
_groupMemberIds = [memberIds copy];
|
|
_groupImage = image; // image is stored in DB
|
|
_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;
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
@end
|