From b71222615c0a829b22be3dc2dd1c3763d8e17006 Mon Sep 17 00:00:00 2001 From: Sherif Nasr Date: Mon, 22 Jun 2020 16:35:06 +0200 Subject: [PATCH 1/3] adding locale and comparing users correctly --- ChatSDKCore/Classes/Session/BConfiguration.h | 3 +++ ChatSDKCore/Classes/Session/BConfiguration.m | 3 +++ ChatSDKCore/Classes/UI/NSBundle+Core.h | 4 ++-- ChatSDKCore/Classes/UI/NSBundle+Core.m | 4 ++-- ChatSDKUI/Classes/Components/Message Cells/BMessageCell.m | 4 ++-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ChatSDKCore/Classes/Session/BConfiguration.h b/ChatSDKCore/Classes/Session/BConfiguration.h index 59c792bd..44a6a427 100755 --- a/ChatSDKCore/Classes/Session/BConfiguration.h +++ b/ChatSDKCore/Classes/Session/BConfiguration.h @@ -149,6 +149,9 @@ typedef enum { @property (nonatomic, readwrite) NSString * inviteByEmailBody; @property (nonatomic, readwrite) NSString * inviteBySMSBody; +// Message locale +@property (nonatomic, readwrite) NSLocale * locale; + // Message fonts @property (nonatomic, readwrite) UIFont * messageTextFont; @property (nonatomic, readwrite) NSString * messageTextColorMe; diff --git a/ChatSDKCore/Classes/Session/BConfiguration.m b/ChatSDKCore/Classes/Session/BConfiguration.m index be09135d..e01ef42d 100755 --- a/ChatSDKCore/Classes/Session/BConfiguration.m +++ b/ChatSDKCore/Classes/Session/BConfiguration.m @@ -102,6 +102,7 @@ @implementation BConfiguration @synthesize enableCompatibilityWithV4; @synthesize messageDeletionEnabled; +@synthesize locale; -(instancetype) init { if((self = [super init])) { @@ -116,6 +117,8 @@ -(instancetype) init { [self setDefaultUserNamePrefix:@"ChatSDK"]; + locale = NSLocale.currentLocale; + showEmptyChats = YES; allowUsersToCreatePublicChats = NO; diff --git a/ChatSDKCore/Classes/UI/NSBundle+Core.h b/ChatSDKCore/Classes/UI/NSBundle+Core.h index fe65b749..47dab02d 100755 --- a/ChatSDKCore/Classes/UI/NSBundle+Core.h +++ b/ChatSDKCore/Classes/UI/NSBundle+Core.h @@ -138,8 +138,8 @@ #define bNoNewUsersFoundForThisSearch @"bNoNewUsersFoundForThisSearch" #define bLastSeen_at_ @"bLastSeen_at_" #define b_at_ @"b_at_" -#define bToday @"Today" -#define bYesterday @"Yesterday" +#define bToday @"bToday" +#define bYesterday @"bYesterday" #define bYouLeftTheGroup @"bYouLeftTheGroup" #define bYouJoinedTheGroup @"bYouJoinedTheGroup" #define bRejoinGroup @"bRejoinGroup" diff --git a/ChatSDKCore/Classes/UI/NSBundle+Core.m b/ChatSDKCore/Classes/UI/NSBundle+Core.m index 9b46c701..55e35105 100755 --- a/ChatSDKCore/Classes/UI/NSBundle+Core.m +++ b/ChatSDKCore/Classes/UI/NSBundle+Core.m @@ -29,14 +29,14 @@ + (NSString *)localizationFileForLang:(NSString *)lang { + (NSString *)bestLocalizationFileForLang:(NSString *)lang { NSString * exact = [self localizationFileForLang:lang]; if (exact) return exact; - lang = [[lang componentsSeparatedByString:@"-"] firstObject]; + lang = [[lang componentsSeparatedByString:@"_"] firstObject]; NSString * general = [self localizationFileForLang:lang]; if (general) return general; return bLocalizableFile; } + (NSString *)t:(NSString *)string { - NSString * lang = [[NSLocale preferredLanguages] objectAtIndex:0]; + NSString * lang = [BChatSDK.config.locale localeIdentifier]; NSString * localizableFile = [self bestLocalizationFileForLang:lang]; if (!localizableFile) return string; diff --git a/ChatSDKUI/Classes/Components/Message Cells/BMessageCell.m b/ChatSDKUI/Classes/Components/Message Cells/BMessageCell.m index dfc8e250..a313b6d8 100755 --- a/ChatSDKUI/Classes/Components/Message Cells/BMessageCell.m +++ b/ChatSDKUI/Classes/Components/Message Cells/BMessageCell.m @@ -218,7 +218,7 @@ -(void) willDisplayCell { // #1 Because of the text view insets we want the cellContentView of the // text cell to extend to the right edge of the bubble - BOOL isMine = [_message.userModel isEqual:BChatSDK.currentUser]; + BOOL isMine = [_message.userModel.entityID isEqual:BChatSDK.currentUser.entityID]; // Layout the profile picture if (_profilePicture.isHidden) { @@ -270,7 +270,7 @@ -(void) willDisplayCell { -(void) layoutSubviews { [super layoutSubviews]; - BOOL isMine = [_message.userModel isEqual:BChatSDK.currentUser]; + BOOL isMine = [_message.userModel.entityID isEqual:BChatSDK.currentUser.entityID]; // Extra x-margin if the profile picture isn't shown // TODO: Fix this From 786505ae88a73d6f6d778b1cee67b67d9c452d8d Mon Sep 17 00:00:00 2001 From: Sherif Nasr Date: Mon, 22 Jun 2020 17:06:39 +0200 Subject: [PATCH 2/3] adding locale for date --- ChatSDKCore/Classes/Categories/NSDate+Additions.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ChatSDKCore/Classes/Categories/NSDate+Additions.m b/ChatSDKCore/Classes/Categories/NSDate+Additions.m index f9fe23fa..88fab0de 100755 --- a/ChatSDKCore/Classes/Categories/NSDate+Additions.m +++ b/ChatSDKCore/Classes/Categories/NSDate+Additions.m @@ -15,7 +15,7 @@ @implementation NSDate (Additions) -(NSString *) threadTimeAgo { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:self.timeFormat]; - + [formatter setLocale:BChatSDK.config.locale]; NSString * time = [formatter stringFromDate:self]; NSDateComponents *otherDay = [[NSCalendar currentCalendar] components:NSCalendarUnitDay fromDate:self]; @@ -45,6 +45,7 @@ -(NSString *) messageTimeAt { // if (self.daysAgo < 1) { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:self.timeFormat]; + [formatter setLocale:BChatSDK.config.locale]; return [formatter stringFromDate:self]; // } // else { @@ -60,6 +61,7 @@ -(NSString *) dateAgo { NSString * day = @""; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; + [formatter setLocale:BChatSDK.config.locale]; if (self.isToday) { day = [NSBundle t: bToday]; @@ -100,7 +102,7 @@ -(BOOL) isPreviousDay: (NSDate *) date { -(NSString *) timeAgoWithFormatString: (NSString *) formatString { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:self.timeFormat]; - + [formatter setLocale:BChatSDK.config.locale]; NSString * time = [formatter stringFromDate:self]; NSString * day = [self dateAgo]; return [NSString stringWithFormat:[NSBundle t:formatString], day, time]; From 5586931a7f5cdea991099e663e95bdf050ded010 Mon Sep 17 00:00:00 2001 From: Sherif Nasr Date: Wed, 3 Mar 2021 10:46:32 +0200 Subject: [PATCH 3/3] fix crash if no file name exists --- ChatSDKCore/Classes/Utilities/BFileCache.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChatSDKCore/Classes/Utilities/BFileCache.m b/ChatSDKCore/Classes/Utilities/BFileCache.m index 68ce56cd..cf7f602a 100755 --- a/ChatSDKCore/Classes/Utilities/BFileCache.m +++ b/ChatSDKCore/Classes/Utilities/BFileCache.m @@ -16,6 +16,10 @@ + (BOOL)isFileCached:(NSString *)cacheName { } + (RXPromise *)cacheFileFromURL:(NSURL *)url withFileName:(NSString *)fileName andCacheName:(NSString *)cacheName { + if (!fileName || !fileName.length) { + fileName = BCoreUtilities.getUUID; + } + RXPromise * promise = [RXPromise new]; if (!url) { [promise rejectWithReason: @"URL must not be nil"];