Commit bac5e5b8 authored by Dominic Vedericho's avatar Dominic Vedericho
Browse files

fixing crash inconsistency

parent 2a1906b8
......@@ -84,6 +84,7 @@ typedef NS_ENUM(NSInteger, TAPChatManagerQuoteActionType) {
- (void)sendLocationMessage:(CGFloat)latitude longitude:(CGFloat)longitude address:(NSString *)address room:(TAPRoomModel *)room successGenerateMessage:(void (^)(TAPMessageModel *message))successGenerateMessage;
- (void)sentFileMessage:(TAPDataFileModel *)dataFile filePath:(NSString *)filePath;
- (void)sentFileMessage:(TAPDataFileModel *)dataFile filePath:(NSString *)filePath room:(TAPRoomModel *)room successGenerateMessage:(void (^)(TAPMessageModel *message))successGenerateMessage;
- (void)sendCustomMessage:(TAPMessageModel *)customMessage;
- (TAPMessageModel *)generateUnreadMessageIdentifierWithRoom:(TAPRoomModel *)room created:(NSNumber *)created indexPosition:(NSInteger)index;
- (void)saveMessageToDraftWithMessage:(NSString *)message roomID:(NSString *)roomID;
......
......@@ -280,7 +280,7 @@
}
NSString *substringMessage = [textMessage substringWithRange:NSMakeRange(startIndex, substringLength)];
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:substringMessage type:TAPChatMessageTypeText];
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:substringMessage type:TAPChatMessageTypeText messageData:nil];
//Check if quote message available
id quotedMessageObject = [[TAPChatManager sharedManager].quotedMessageDictionary objectForKey:room.roomID];
......@@ -341,7 +341,7 @@
}
}
else {
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:textMessage type:TAPChatMessageTypeText];
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:textMessage type:TAPChatMessageTypeText messageData:nil];
//Check if quote message available
id quotedMessageObject = [self.quotedMessageDictionary objectForKey:room.roomID];
......@@ -427,7 +427,7 @@
messageBodyCaption = [NSString stringWithFormat:@"🖼 %@", caption];
}
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:messageBodyCaption type:TAPChatMessageTypeImage];
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:messageBodyCaption type:TAPChatMessageTypeImage messageData:nil];
NSMutableDictionary *dataDictionary = message.data;
if (dataDictionary == nil) {
......@@ -525,7 +525,7 @@
messageBodyCaption = [NSString stringWithFormat:@"🖼 %@", caption];
}
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:messageBodyCaption type:TAPChatMessageTypeImage];
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:messageBodyCaption type:TAPChatMessageTypeImage messageData:nil];
NSMutableDictionary *dataDictionary = message.data;
if (dataDictionary == nil) {
......@@ -623,7 +623,7 @@
messageBodyCaption = [NSString stringWithFormat:@"🎥 %@", caption];
}
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:messageBodyCaption type:TAPChatMessageTypeVideo];
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:messageBodyCaption type:TAPChatMessageTypeVideo messageData:nil];
NSMutableDictionary *dataDictionary = message.data;
if (dataDictionary == nil) {
......@@ -733,7 +733,7 @@
NSString *messageBodyString = NSLocalizedString(@"📍Location", @"");
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:messageBodyString type:TAPChatMessageTypeLocation];
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:messageBodyString type:TAPChatMessageTypeLocation messageData:nil];
NSMutableDictionary *dataDictionary = message.data;
if (dataDictionary == nil) {
......@@ -824,7 +824,7 @@
NSString *messageBodyString = [NSString stringWithFormat:@"📎 %@", fileName];
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:messageBodyString type:TAPChatMessageTypeFile];
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:messageBodyString type:TAPChatMessageTypeFile messageData:nil];
NSMutableDictionary *dataDictionary = message.data;
if (dataDictionary == nil) {
......@@ -894,8 +894,12 @@
[[TAPFileUploadManager sharedManager] sendFileWithData:message];
}
- (void)sendCustomMessage:(TAPMessageModel *)customMessage {
[self sendMessage:customMessage notifyDelegate:YES];
}
- (TAPMessageModel *)generateUnreadMessageIdentifierWithRoom:(TAPRoomModel *)room created:(NSNumber *)created indexPosition:(NSInteger)index {
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser created:created room:room body:@"" type:TAPChatMessageTypeUnreadMessageIdentifier];
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser created:created room:room body:@"" type:TAPChatMessageTypeUnreadMessageIdentifier messageData:nil];
return message;
}
......@@ -1388,7 +1392,7 @@
TAPMessageModel *existingMessage = [self.quotedMessageDictionary objectForKey:room.roomID];
if (type == TAPChatManagerQuoteActionTypeForward) {
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:existingMessage.body type:existingMessage.type];
TAPMessageModel *message = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:existingMessage.body type:existingMessage.type messageData:nil];
message.data = existingMessage.data;
message.quote = existingMessage.quote;
......
......@@ -169,14 +169,9 @@
[self validateToken];
NSString *appKeyID = [[NSUserDefaults standardUserDefaults] secureObjectForKey:TAP_PREFS_APP_KEY_ID valid:nil];
NSString *appKeySecret = [[NSUserDefaults standardUserDefaults] secureObjectForKey:TAP_PREFS_APP_KEY_SECRET valid:nil];
NSString *authorizationValueString = [NSString stringWithFormat:@"Bearer %@", [TAPDataManager getAccessToken]];
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.socketURL]];
NSString *appKey = [NSString stringWithFormat:@"%@:%@", appKeyID, appKeySecret];
NSData *base64Data = [appKey dataUsingEncoding:NSUTF8StringEncoding];
NSString *encodedAppKey = [base64Data base64EncodedStringWithOptions:0];
NSString *encodedAppKey = [[TAPNetworkManager sharedManager] getAppKey];
[urlRequest addValue:encodedAppKey forHTTPHeaderField:@"App-Key"];
[urlRequest addValue:[[UIDevice currentDevice] identifierForVendor].UUIDString forHTTPHeaderField:@"Device-Identifier"];
......
......@@ -115,6 +115,19 @@ NS_ASSUME_NONNULL_BEGIN
progress:(void (^)(CGFloat progress, CGFloat total))progress
success:(void (^)(TAPMessageModel *message))success
failure:(void (^)(NSError *error))failure;
- (TAPMessageModel *)constructTapTalkMessageModelWithRoom:(TAPRoomModel *)room
messageBody:(NSString *)messageBody
messageType:(NSInteger)messageType
messageData:(NSDictionary * _Nullable)messageData;
- (TAPMessageModel *)constructTapTalkMessageModelWithRoom:(TAPRoomModel *)room
quotedMessage:(TAPMessageModel *)quotedMessage
messageBody:(NSString *)messageBody
messageType:(NSInteger)messageType
messageData:(NSDictionary * _Nullable)messageData;
- (void)sendCustomMessageWithMessageModel:(TAPMessageModel *)customMessage
start:(void (^)(TAPMessageModel *message))start
success:(void (^)(TAPMessageModel *message))success
failure:(void (^)(NSError *error))failure;
- (void)deleteLocalMessageWithLocalID:(NSString *)localID
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure;
......
......@@ -442,6 +442,59 @@
[[TAPChatManager sharedManager] checkAndSendForwardedMessageWithRoom:room];
}
- (TAPMessageModel *)constructTapTalkMessageModelWithRoom:(TAPRoomModel *)room
messageBody:(NSString *)messageBody
messageType:(NSInteger)messageType
messageData:(NSDictionary * _Nullable)messageData {
TAPMessageModel *constructedMessage = [TAPMessageModel createMessageWithUser:[TAPChatManager sharedManager].activeUser room:room body:messageBody type:messageType messageData:messageData];
return constructedMessage;
}
- (TAPMessageModel *)constructTapTalkMessageModelWithRoom:(TAPRoomModel *)room
quotedMessage:(TAPMessageModel *)quotedMessage
messageBody:(NSString *)messageBody
messageType:(NSInteger)messageType
messageData:(NSDictionary * _Nullable)messageData {
TAPMessageModel *constructedMessage = [self constructTapTalkMessageModelWithRoom:room messageBody:messageBody messageType:messageType messageData:messageData];
//if message quoted from message model then should construct quote and reply to model
NSString *quoteImageUrl = [TAPUtil nullToEmptyString:quotedMessage.quote.imageURL];
NSString *quoteFileID = [TAPUtil nullToEmptyString:quotedMessage.quote.fileID];
if (![quoteImageUrl isEqualToString:@""] || ![quoteFileID isEqualToString:@""]) {
constructedMessage.quote = [quotedMessage.quote copy];
}
else {
TAPQuoteModel *quote = [TAPQuoteModel new];
quote.title = quotedMessage.user.fullname;
quote.content = quotedMessage.body;
constructedMessage.quote = [quote copy];
}
TAPReplyToModel *replyTo = [TAPReplyToModel new];
replyTo.messageID = quotedMessage.messageID;
replyTo.localID = quotedMessage.localID;
replyTo.messageType = quotedMessage.type;
replyTo.fullname = quotedMessage.user.fullname;
replyTo.xcUserID = quotedMessage.user.xcUserID;
replyTo.userID = quotedMessage.user.userID;
constructedMessage.replyTo = replyTo;
return constructedMessage;
}
- (void)sendCustomMessageWithMessageModel:(TAPMessageModel *)customMessage
start:(void (^)(TAPMessageModel *message))start
success:(void (^)(TAPMessageModel *message))success
failure:(void (^)(NSError *error))failure {
[[TAPChatManager sharedManager] sendCustomMessage:customMessage];
void (^handlerSuccess)(TAPMessageModel *) = [success copy];
NSMutableDictionary *blockTypeDictionary = [[NSMutableDictionary alloc] init];
[blockTypeDictionary setObject:handlerSuccess forKey:@"successBlock"];
[self.blockDictionary setObject:blockTypeDictionary forKey:customMessage.localID];
start(customMessage);
}
- (void)deleteLocalMessageWithLocalID:(NSString *)localID
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure {
......
......@@ -76,4 +76,7 @@ refreshToken:(NSString *)refreshToken
- (void)cancelDownloadWithFileID:(NSString *)fileID;
- (void)setAppKey:(NSString *)appKey;
- (NSString *)getAppKey;
@end
......@@ -12,6 +12,7 @@ static const NSInteger kAPITimeOut = 60;
@interface TAPNetworkManager ()
@property (strong, nonatomic) NSString *appKey;
@property (strong, nonatomic) NSMutableDictionary *currentDownloadTaskDictionary;
- (AFHTTPSessionManager *)defaultManager;
......@@ -55,6 +56,7 @@ static const NSInteger kAPITimeOut = 60;
}
}];
_currentDownloadTaskDictionary = [[NSMutableDictionary alloc] init];
_appKey = [NSString string];
}
return self;
......@@ -66,23 +68,13 @@ static const NSInteger kAPITimeOut = 60;
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSString *appKeyID = [[NSUserDefaults standardUserDefaults] secureObjectForKey:TAP_PREFS_APP_KEY_ID valid:nil];
NSString *appKeySecret = [[NSUserDefaults standardUserDefaults] secureObjectForKey:TAP_PREFS_APP_KEY_SECRET valid:nil];
NSString *userAgent = [[NSUserDefaults standardUserDefaults] secureObjectForKey:@"ios" valid:nil];
NSString *appKey = [NSString stringWithFormat:@"%@:%@", appKeyID, appKeySecret];
NSData *base64Data = [appKey dataUsingEncoding:NSUTF8StringEncoding];
NSString *encodedAppKey = [base64Data base64EncodedStringWithOptions:0];
[manager.requestSerializer setValue:encodedAppKey forHTTPHeaderField:@"App-Key"];
[manager.requestSerializer setValue:self.appKey forHTTPHeaderField:@"App-Key"];
[manager.requestSerializer setValue:[[UIDevice currentDevice] identifierForVendor].UUIDString forHTTPHeaderField:@"Device-Identifier"];
[manager.requestSerializer setValue:[[UIDevice currentDevice] model] forHTTPHeaderField:@"Device-Model"];
[manager.requestSerializer setValue:@"ios" forHTTPHeaderField:@"Device-Platform"];
[manager.requestSerializer setValue:[[UIDevice currentDevice] systemVersion] forHTTPHeaderField:@"Device-OS-Version"];
[manager.requestSerializer setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] forHTTPHeaderField:@"App-Version"];
[manager.requestSerializer setValue:userAgent forHTTPHeaderField:@"User-Agent"];
[manager.requestSerializer setValue:@"MTlkYzhjMjc0YmNjOGM0NjQ2MmI2ODM4NTpNR1kyT0Raa01ETmlZVFJqTlRFdU1TNHgvWkRka05tTTBNelkvWm1JNE5UUTRaV1E0WmpJNS9Oems0TVdaa1pUZGhaVGsw" forHTTPHeaderField:@"Server-Key"]; //DV Temp - Temporary set server key, needs to be deleted when integrated to Moselo
[manager.requestSerializer setValue:@"ios" forHTTPHeaderField:@"User-Agent"];
[manager.requestSerializer setTimeoutInterval:kAPITimeOut];
......@@ -92,7 +84,7 @@ static const NSInteger kAPITimeOut = 60;
}
#ifdef DEBUG
NSLog(@"App Key: %@", encodedAppKey);
NSLog(@"App Key: %@", self.appKey);
NSLog(@"Device Identifier: %@", [[UIDevice currentDevice] identifierForVendor].UUIDString);
NSLog(@"Device Model: %@", [[UIDevice currentDevice] model]);
NSLog(@"Device-OS-Version: %@", [[UIDevice currentDevice] systemVersion]);
......@@ -622,4 +614,14 @@ refreshToken:(NSString *)refreshToken
[self.currentDownloadTaskDictionary removeObjectForKey:fileID];
}
- (void)setAppKey:(NSString *)appKey {
NSData *base64Data = [appKey dataUsingEncoding:NSUTF8StringEncoding];
NSString *encodedAppKey = [base64Data base64EncodedStringWithOptions:0];
_appKey = encodedAppKey;
}
- (NSString *)getAppKey {
return self.appKey;
}
@end
......@@ -182,10 +182,10 @@
return;
}
if ([[TapUI sharedInstance] roomListViewController].isViewAppear) {
//Do not show if currently in room list
return;
}
// if ([[TapUI sharedInstance] roomListViewController].isViewAppear) {
// //Do not show if currently in room list
// return;
// }
if (!self.isViewIsAddedToSubview) {
[self initCustomNotificationAlertViewController];
......
......@@ -41,10 +41,10 @@
@property (nonatomic) BOOL isRead;
@property (nonatomic) BOOL isDelivered;
@property (nonatomic) BOOL isHidden;
//If add new property, don't forget to update copyMessageModel method
+ (instancetype)createMessageWithUser:(TAPUserModel *)user room:(TAPRoomModel *)room body:(NSString *)body type:(TAPChatMessageType)type;
+ (instancetype)createMessageWithUser:(TAPUserModel *)user created:(NSNumber *)created room:(TAPRoomModel *)room body:(NSString *)body type:(TAPChatMessageType)type;
+ (instancetype)createMessageWithUser:(TAPUserModel *)user room:(TAPRoomModel *)room body:(NSString *)body type:(TAPChatMessageType)type messageData:(NSDictionary * _Nullable)messageData;
+ (instancetype)createMessageWithUser:(TAPUserModel *)user created:(NSNumber *)created room:(TAPRoomModel *)room body:(NSString *)body type:(TAPChatMessageType)type messageData:(NSDictionary * _Nullable)messageData;
- (TAPMessageModel *)copyMessageModel;
......
......@@ -13,7 +13,7 @@
#pragma mark - Lifecycle
#pragma mark - Custom Method
+ (instancetype)createMessageWithUser:(TAPUserModel *)user created:(NSNumber *)created room:(TAPRoomModel *)room body:(NSString *)body type:(TAPChatMessageType)type {
+ (instancetype)createMessageWithUser:(TAPUserModel *)user created:(NSNumber *)created room:(TAPRoomModel *)room body:(NSString *)body type:(TAPChatMessageType)type messageData:(NSDictionary * _Nullable)messageData {
TAPMessageModel *messageForReturn = [[TAPMessageModel alloc] init];
//DV Note - Set message ID to string 0 because server accepted as an integer, so empty string will cause a trouble in server
......@@ -31,6 +31,7 @@
messageForReturn.isRead = NO;
messageForReturn.isDelivered = NO;
messageForReturn.isHidden = NO;
messageForReturn.data = messageData;
//Obtain other user ID
NSString *roomID = room.roomID;
......@@ -60,13 +61,13 @@
return messageForReturn;
}
+ (instancetype)createMessageWithUser:(TAPUserModel *)user room:(TAPRoomModel *)room body:(NSString *)body type:(TAPChatMessageType)type {
+ (instancetype)createMessageWithUser:(TAPUserModel *)user room:(TAPRoomModel *)room body:(NSString *)body type:(TAPChatMessageType)type messageData:(NSDictionary * _Nullable)messageData {
NSDate *date = [NSDate date];
double createdDate = [date timeIntervalSince1970] * 1000.0f;
NSNumber *createdDateNumber = [NSNumber numberWithLong:createdDate];
TAPMessageModel *messageForReturn = [[TAPMessageModel alloc] init];
messageForReturn = [self createMessageWithUser:user created:createdDateNumber room:room body:body type:type];
messageForReturn = [self createMessageWithUser:user created:createdDateNumber room:room body:body type:type messageData:messageData];
return messageForReturn;
}
......
......@@ -33,10 +33,8 @@
#define TAP_PREFS_CONTACT_PERMISSION_ASKED @"Prefs.TapTalkContactPermissionAsked"
#define TAP_PREFS_ROOM_MODEL_DICTIONARY @"Prefs.TapTalkRoomModelDictionary"
#define TAP_PREFS_PROJECT_CONFIGS_DICTIONARY @"Prefs.TapTalkProjectConfigsDictionary"
//User Customized Prefs
#define TAP_PREFS_APP_KEY_ID @"Prefs.TapTalkAppKeyID"
#define TAP_PREFS_APP_KEY_SECRET @"Prefs.TapTalkAppKeySecret"
#define TAP_PREFS_AUTO_SYNC_CONTACT_DISABLED @"Prefs.TapTalkAutoSyncContactDisabled"
#define TAP_PREFS_DONE_FIRST_TIME_AUTO_SYNC_CONTACT @"Prefs.TapTalkDoneFirstTimeAutoSyncContact"
//Color
#define TAP_COLOR_WHITE @"FFFFFF"
......
......@@ -213,23 +213,39 @@ FOUNDATION_EXPORT const unsigned char TapTalkVersionString[];
/**
Get core configs data
*/
- (NSDictionary *)getCoreConfigs;
- (NSDictionary *_Nonnull)getCoreConfigs;
/**
Get project configs data
*/
- (NSDictionary *)getProjectConfigs;
- (NSDictionary *_Nonnull)getProjectConfigs;
/**
Get custom configs data
*/
- (NSDictionary *)getCustomConfigs;
- (NSDictionary *_Nonnull)getCustomConfigs;
/**
Set Google Places API Key to pick and obtain location when send location chat
*/
- (void)initializeGooglePlacesAPIKey:(NSString * _Nonnull)apiKey;
/**
Enable TapTalk.io to sync your contact automatically
Default is enabled
*/
- (void)enableAutoContactSync;
/**
Disable TapTalk.io to sync your contact automatically
*/
- (void)disableAutoContactSync;
/**
Obtain auto contact sync status
*/
- (BOOL)isAutoContactSyncEnabled;
//==========================================================
// User
//==========================================================
......
......@@ -395,10 +395,8 @@
apiURLString:(NSString *_Nonnull)apiURLString
implementationType:(TapTalkImplentationType)tapTalkImplementationType {
[[NSUserDefaults standardUserDefaults] setSecureObject:appKeyID forKey:TAP_PREFS_APP_KEY_ID];
[[NSUserDefaults standardUserDefaults] setSecureObject:appKeySecret forKey:TAP_PREFS_APP_KEY_SECRET];
[[NSUserDefaults standardUserDefaults] synchronize];
NSString *appKey = [NSString stringWithFormat:@"%@:%@", appKeyID, appKeySecret];
[[TAPNetworkManager sharedManager] setAppKey:appKey];
[[TAPAPIManager sharedManager] setBaseAPIURLString:apiURLString];
[[TAPConnectionManager sharedManager] setSocketURLString:apiURLString];
......@@ -526,6 +524,8 @@
[[NSUserDefaults standardUserDefaults] removeObjectForKey:TAP_PREFS_USER_COUNTRY_CODE];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:TAP_PREFS_CONTACT_PERMISSION_ASKED];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:TAP_PREFS_PROJECT_CONFIGS_DICTIONARY];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:TAP_PREFS_AUTO_SYNC_CONTACT_DISABLED];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:TAP_PREFS_DONE_FIRST_TIME_AUTO_SYNC_CONTACT];
[[NSUserDefaults standardUserDefaults] synchronize];
//Clear Manager Data
......@@ -559,4 +559,19 @@
}
}
- (void)enableAutoContactSync {
[[NSUserDefaults standardUserDefaults] setSecureBool:NO forKey:TAP_PREFS_AUTO_SYNC_CONTACT_DISABLED];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)disableAutoContactSync {
[[NSUserDefaults standardUserDefaults] setSecureBool:YES forKey:TAP_PREFS_AUTO_SYNC_CONTACT_DISABLED];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (BOOL)isAutoContactSyncEnabled {
BOOL isDisabled = [[NSUserDefaults standardUserDefaults] secureBoolForKey:TAP_PREFS_AUTO_SYNC_CONTACT_DISABLED valid:nil];
return !isDisabled;
}
@end
......@@ -38,6 +38,8 @@
@property (strong, nonatomic) NSString *updatedString;
@property (nonatomic) BOOL skipCheckContactSync;
- (void)loadContactListFromDatabase;
- (void)syncContactWithLoading:(BOOL)loading;
- (void)requestAccessAndCheckNewContact;
......@@ -83,7 +85,6 @@
[self.addNewChatView showSyncContactButtonView:NO];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActiveNotification:) name:TAP_NOTIFICATION_APPLICATION_DID_BECOME_ACTIVE object:nil];
}
- (void)viewWillAppear:(BOOL)animated {
......@@ -571,7 +572,9 @@
#pragma mark TAPCustomButtonView
- (void)customButtonViewDidTappedButton {
//Sync Button Tapped
[self syncContactWithLoading:YES];
// [self syncContactWithLoading:YES];
[self showPopupViewWithPopupType:TAPPopUpInfoViewControllerTypeInfoDefault popupIdentifier:@"Sync Contact Manually" title:NSLocalizedString(@"Contact Access", @"") detailInformation:NSLocalizedString(@"We need your permission to access your contact, we will sync your contact to our server and automatically find your friend so it is easier for you to find your friends.", @"") leftOptionButtonTitle:@"Cancel" singleOrRightOptionButtonTitle:@"Allow"];
}
#pragma mark TAPAddNewContactViewController
......@@ -786,28 +789,98 @@
}
- (void)requestAccessAndCheckNewContact {
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (granted && [[TAPContactManager sharedManager] isContactPermissionAsked]) {
//2nd time sync contact and so on, no loading
[self syncContactWithLoading:NO];
}
else if (granted) {
//1st time sync contact, show loading
[self syncContactWithLoading:YES];
}
else {
//not granted, show sync button view
[self.addNewChatView showSyncContactButtonView:YES];
}
[[TAPContactManager sharedManager] setContactPermissionAsked];
});
}];
BOOL isAutoSyncEnabled = [[TapTalk sharedInstance] isAutoContactSyncEnabled];
BOOL isDoneFirstTimeAutoSync = [[NSUserDefaults standardUserDefaults] secureBoolForKey:TAP_PREFS_DONE_FIRST_TIME_AUTO_SYNC_CONTACT valid:nil];
if (!isAutoSyncEnabled) {
//Auto sync contact disabled
return;
}
if (isDoneFirstTimeAutoSync) {
//Allow Access
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (granted && [[TAPContactManager sharedManager] isContactPermissionAsked]) {
//2nd time sync contact and so on, no loading
[self syncContactWithLoading:NO];
}
else if (granted) {
//1st time sync contact, show loading
[self syncContactWithLoading:YES];
//Save done auto sync contact
[[NSUserDefaults standardUserDefaults] setSecureBool:YES forKey:TAP_PREFS_DONE_FIRST_TIME_AUTO_SYNC_CONTACT];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else {
//not granted, show sync button view
[self.addNewChatView showSyncContactButtonView:YES];
}
[[TAPContactManager sharedManager] setContactPermissionAsked];
});
}];
}
else {
[self showPopupViewWithPopupType:TAPPopUpInfoViewControllerTypeInfoDefault popupIdentifier:@"Contact Access" title:NSLocalizedString(@"Contact Access", @"") detailInformation:NSLocalizedString(@"We need your permission to access your contact, we will sync your contact to our server and automatically find your friend so it is easier for you to find your friends.", @"") leftOptionButtonTitle:@"Cancel" singleOrRightOptionButtonTitle:@"Allow"];
}
}
- (void)applicationDidBecomeActiveNotification:(NSNotification *)notification {
[self requestAccessAndCheckNewContact];
if(!self.skipCheckContactSync) {
[self requestAccessAndCheckNewContact];
}
}
#pragma mark PopUpInfoViewController
- (void)popUpInfoDidTappedLeftButtonWithIdentifier:(NSString *)popupIdentifier {
[super popUpInfoDidTappedLeftButtonWithIdentifier:popupIdentifier];
if ([popupIdentifier isEqualToString:@"Contact Access"]) {
//Decline Access
//not granted, show sync button view
[self.addNewChatView showSyncContactButtonView:YES];
}
else if ([popupIdentifier isEqualToString:@"Sync Contact Manually"]) {
//Decline
}
}
- (void)popUpInfoTappedSingleButtonOrRightButtonWithIdentifier:(NSString *)popupIdentifier {
[super popUpInfoTappedSingleButtonOrRightButtonWithIdentifier:popupIdentifier];
if ([popupIdentifier isEqualToString:@"Contact Access"]) {
//Allow Access
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (granted && [[TAPContactManager sharedManager] isContactPermissionAsked]) {
//2nd time sync contact and so on, no loading
[self syncContactWithLoading:NO];
}
else if (granted) {
//1st time sync contact, show loading
[self syncContactWithLoading:YES];
//Save done auto sync contact
[[NSUserDefaults standardUserDefaults] setSecureBool:YES forKey:TAP_PREFS_DONE_FIRST_TIME_AUTO_SYNC_CONTACT];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else {
//not granted, show sync button view
[self.addNewChatView showSyncContactButtonView:YES];
_skipCheckContactSync = YES;
}
[[TAPContactManager sharedManager] setContactPermissionAsked];
});
}];
}
else if ([popupIdentifier isEqualToString:@"Sync Contact Manually"]) {
[self.addNewChatView showSyncContactButtonView:NO];
[self syncContactWithLoading:YES];
//Save done auto sync contact
[[NSUserDefaults standardUserDefaults] setSecureBool:YES forKey:TAP_PREFS_DONE_FIRST_TIME_AUTO_SYNC_CONTACT];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
@end
......@@ -5916,9 +5916,13 @@ typedef NS_ENUM(NSInteger, TopFloatingIndicatorViewType) {
}
- (void)updateMessageDataAndUIWithMessages:(NSArray *)messageArray checkFirstUnreadMessage:(BOOL)checkFirstUnreadMessage toTop:(BOOL)toTop withCompletionHandler:(void(^)())completionHandler {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
//DV NOTE
//13 Sept 2019
//Comment async to prevent crash when in and out to room and insert message and prevent inconsistency data
//END DV Note
// dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
// dispatch_async(queue, ^{
NSInteger earliestUnreadMessageIndex = -1;
long minCreatedUnreadMessage;
......@@ -5937,6 +5941,7 @@ typedef NS_ENUM(NSInteger, TopFloatingIndicatorViewType) {
if (!toTop) {
index = [self.messageArray count];
}
[self addIncomingMessageToArrayAndDictionaryWithMessage:message atIndex:index];
if (checkFirstUnreadMessage && message.isRead == 0) {
//For checking unread message from API After
......@@ -5966,7 +5971,11 @@ typedef NS_ENUM(NSInteger, TopFloatingIndicatorViewType) {
}
NSLog(@"numberOfUnreadMessages: %ld", (long)self.numberOfUnreadMessages);
//DV NOTE
//13 Sept 2019
//Comment async to prevent crash when in and out to room and insert message and prevent inconsistency data
//END DV Note
// dispatch_async(dispatch_get_main_queue(), ^{
//Check to show unread message identifier
if (!self.isShowingUnreadMessageIdentifier) {
......@@ -6008,9 +6017,13 @@ typedef NS_ENUM(NSInteger, TopFloatingIndicatorViewType) {
}
[self sortAndFilterMessageArray];
dispatch_async(dispatch_get_main_queue(), ^{
//DV NOTE
//13 Sept 2019
//Comment async to prevent crash when in and out to room and insert message and prevent inconsistency data
//END DV Note
// dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
//Check to show top unread button
......@@ -6024,8 +6037,8 @@ typedef NS_ENUM(NSInteger, TopFloatingIndicatorViewType) {
[self checkEmptyState];
completionHandler();
});
});
// });
// });
}
- (void)updateMessageDataAndUIFromBeforeWithMessages:(NSArray *)messageArray
......@@ -6066,8 +6079,7 @@ typedef NS_ENUM(NSInteger, TopFloatingIndicatorViewType) {
}
NSMutableArray *indexPaths = [NSMutableArray array];
NSInteger currentCount = [self.messageArray count] - [currentAddedMessageArray count]
;
NSInteger currentCount = [self.messageArray count] - [currentAddedMessageArray count];
for (int count = currentCount; count < [self.messageArray count]; count++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:count inSection:0]];
}
......@@ -6078,7 +6090,7 @@ typedef NS_ENUM(NSInteger, TopFloatingIndicatorViewType) {
[self.tableView endUpdates];
[self.tableView scrollsToTop];
}
completionHandler();
});
});
......
......@@ -201,12 +201,26 @@
TAPUserModel *user = message.user;
NSString *profilePictureURL = user.imageURL.thumbnail;
NSString *nameString = message.user.fullname;
NSString *nameString;
NSString *messageString = message.body;
NSString *contentImageURL = @""; //DV TO DO - Obtain image message
UIImage *thumbnailImage = nil;
if (message.type == TAPChatMessageTypeImage || message.type == TAPChatMessageTypeVideo) {
NSString *thumbnailString = [message.data objectForKey:@"thumbnail"];
NSData *thumbnailImageData = [[NSData alloc]
initWithBase64EncodedString:thumbnailString options:0];
thumbnailImage = [UIImage imageWithData:thumbnailImageData];
}
if (message.room.type == RoomTypeGroup) {
nameString = message.room.name;
}
else {
nameString = message.user.fullname;
}
BOOL isShowContentImage = NO;
if (contentImageURL == nil || [contentImageURL isEqualToString:@""]) {
if (thumbnailImage == nil) {
//Hide content image
isShowContentImage = NO;
}
......@@ -215,7 +229,6 @@
}
if (message.type == TAPChatMessageTypeSystemMessage) {
NSString *targetAction = message.action;
TAPGroupTargetModel *groupTarget = message.target;
NSString *targetName = groupTarget.targetName;
......@@ -244,19 +257,18 @@
_currentFirstShownMessage = message;
self.customNotificationAlertView.nameLabel.text = nameString;
self.customNotificationAlertView.messageLabel.text = messageString;
[self showFirstAnimationHasContentImage:isShowContentImage profilePictureURL:profilePictureURL contentImageURL:contentImageURL];
[self showFirstAnimationHasContentImage:isShowContentImage profilePictureURL:profilePictureURL contentImage:thumbnailImage];
}
else {
//Even message, show secondary notification view
_currentSecondaryShownMessage = message;
self.customNotificationAlertView.secondaryNameLabel.text = nameString;
self.customNotificationAlertView.secondaryMessageLabel.text = messageString;
[self showSecondaryAnimationHasContentImage:isShowContentImage profilePictureURL:profilePictureURL contentImageURL:contentImageURL];
[self showSecondaryAnimationHasContentImage:isShowContentImage profilePictureURL:profilePictureURL contentImage:thumbnailImage];
}
}
- (void)showFirstAnimationHasContentImage:(BOOL)hasContentImage profilePictureURL:(NSString *)profilePictureURL contentImageURL:(NSString *)contentImageURL {
- (void)showFirstAnimationHasContentImage:(BOOL)hasContentImage profilePictureURL:(NSString *)profilePictureURL contentImage:(UIImage *)contentImage {
if (!hasContentImage) {
//Hide Content Image
self.customNotificationAlertView.contentImageView.alpha = 0.0f;
......@@ -303,11 +315,11 @@
[self.customNotificationAlertView.profilePictureImage setImageWithURLString:profilePictureURL];
}
[self.customNotificationAlertView.contentImageView setImageWithURLString:contentImageURL];
[self.customNotificationAlertView.contentImageView setImage:contentImage];
}
}
- (void)showSecondaryAnimationHasContentImage:(BOOL)hasContentImage profilePictureURL:(NSString *)profilePictureURL contentImageURL:(NSString *)contentImageURL {
- (void)showSecondaryAnimationHasContentImage:(BOOL)hasContentImage profilePictureURL:(NSString *)profilePictureURL contentImage:(UIImage *)contentImage {
if (!hasContentImage) {
//Hide Content Image
self.customNotificationAlertView.secondaryContentImageView.alpha = 0.0f;
......@@ -347,7 +359,7 @@
[self.customNotificationAlertView.secondaryProfilePictureImage setImageWithURLString:profilePictureURL];
}
[self.customNotificationAlertView.secondaryContentImageView setImageWithURLString:contentImageURL];
[self.customNotificationAlertView.secondaryContentImageView setImage:contentImage];
}
}
......
......@@ -440,7 +440,7 @@
}
- (void)dismissSelf {
UIImage *thumbnailImage = [UIImage imageNamed:@"blank-image"];
UIImage *thumbnailImage = [UIImage imageNamed:@"blank-image" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
if(self.currentViewController != nil) {
thumbnailImage = [self.currentViewController currentImage];
......
......@@ -52,7 +52,7 @@
[self.syncedContactNotificationView addSubview:self.syncedContactNotificationLabel];
_syncedContactNotificationCheckMarkImageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.syncedContactNotificationLabel.frame) + 4.0f, (CGRectGetHeight(self.syncedContactNotificationView.frame) - 9.0f) / 2.0f, 9.0f, 9.0f)];
self.syncedContactNotificationCheckMarkImageView.image = [UIImage imageNamed:@"TAPIconConnected"];
self.syncedContactNotificationCheckMarkImageView.image = [UIImage imageNamed:@"TAPIconConnected" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
[self.syncedContactNotificationView addSubview:self.syncedContactNotificationCheckMarkImageView];
_searchBarBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.bgView.frame), 46.0f)];
......@@ -209,7 +209,7 @@
gradient.startPoint = CGPointMake(0.0f, 0.0f);
gradient.endPoint = CGPointMake(0.0f, 1.0f);
[self.syncedContactNotificationView.layer replaceSublayer:[self.syncedContactNotificationView.layer.sublayers objectAtIndex:0] with:gradient];
self.syncedContactNotificationCheckMarkImageView.image = [UIImage imageNamed:@"TAPIconLoaderProgress"];
self.syncedContactNotificationCheckMarkImageView.image = [UIImage imageNamed:@"TAPIconLoaderProgress" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
self.syncedContactNotificationCheckMarkImageView.image = [self.syncedContactNotificationCheckMarkImageView.image setImageTintColor:[[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorIconLoadingProgressWhite]];
[self showNotificationLoading:YES];
}
......@@ -220,7 +220,7 @@
gradient.startPoint = CGPointMake(0.0f, 0.0f);
gradient.endPoint = CGPointMake(0.0f, 1.0f);
[self.syncedContactNotificationView.layer replaceSublayer:[self.syncedContactNotificationView.layer.sublayers objectAtIndex:0] with:gradient];
self.syncedContactNotificationCheckMarkImageView.image = [UIImage imageNamed:@"TAPIconConnected"];
self.syncedContactNotificationCheckMarkImageView.image = [UIImage imageNamed:@"TAPIconConnected" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
[self showNotificationLoading:NO];
}
......
......@@ -143,7 +143,7 @@
_groupPictureImageView = [[TAPImageView alloc] initWithFrame:CGRectMake((CGRectGetWidth(self.frame) - 96.0f) / 2,CGRectGetMaxY(self.navigationHeaderView.frame) + profilePictureTopGap, 96.0f, 96.0f)];
self.groupPictureImageView.layer.cornerRadius = CGRectGetWidth(self.groupPictureImageView.frame) / 2.0f;
self.groupPictureImageView.image = [UIImage imageNamed:@"TAPIconDefaultAvatar"];
self.groupPictureImageView.image = [UIImage imageNamed:@"TAPIconDefaultAvatar" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
self.groupPictureImageView.layer.masksToBounds = YES;
self.groupPictureImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.bgScrollView addSubview:self.groupPictureImageView];
......@@ -190,7 +190,7 @@
[self.bgScrollView addSubview:self.loadingLabel];
_changeIconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.changeLabel.frame) + 4.0f, CGRectGetMinY(self.changeLabel.frame) + 4.0f, 14.0f, 14.0f)];
self.changeIconImageView.image = [UIImage imageNamed:@"TAPIconAddEditItem"];
self.changeIconImageView.image = [UIImage imageNamed:@"TAPIconAddEditItem" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
self.changeIconImageView.image = [self.changeIconImageView.image setImageTintColor:[[TAPStyleManager sharedManager] getComponentColorForType:TAPComponentColorIconChangePicture]];
[self.bgScrollView addSubview:self.changeIconImageView];
......@@ -277,7 +277,7 @@
#pragma mark - Custom Method
- (void)setGroupPictureImageViewWithImage:(UIImage *)image {
if (image == nil) {
self.groupPictureImageView.image = [UIImage imageNamed:@"TAPIconDefaultAvatar"];
self.groupPictureImageView.image = [UIImage imageNamed:@"TAPIconDefaultAvatar" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
self.removePictureView.alpha = 0.0f;
}
else {
......@@ -304,7 +304,7 @@
- (void)setGroupPictureWithImageURL:(NSString *)urlString {
if ([TAPUtil isEmptyString:urlString]) {
self.groupPictureImageView.image = [UIImage imageNamed:@"TAPIconDefaultAvatar"];
self.groupPictureImageView.image = [UIImage imageNamed:@"TAPIconDefaultAvatar" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
self.removePictureView.alpha = 0.0f;
}
else {
......
......@@ -188,7 +188,7 @@
#pragma mark - Custom Method
- (void)animateOpeningWithThumbnailFrame:(CGRect)thumbnailFrame thumbnailImage:(UIImage *)thumbnailImage {
if(thumbnailImage == nil) {
thumbnailImage = [UIImage imageNamed:@"blank-image"];
thumbnailImage = [UIImage imageNamed:@"blank-image" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
}
if([self.delegate respondsToSelector:@selector(mediaDetailViewWillStartOpeningAnimation)]) {
......@@ -258,7 +258,7 @@
- (void)animateClosingWithThumbnailFrame:(CGRect)thumbnailFrame thumbnailImage:(UIImage *)thumbnailImage {
if(thumbnailImage == nil) {
thumbnailImage = [UIImage imageNamed:@"blank-image"];
thumbnailImage = [UIImage imageNamed:@"blank-image" inBundle:[TAPUtil currentBundle] compatibleWithTraitCollection:nil];
}
if([self.delegate respondsToSelector:@selector(mediaDetailViewWillStartClosingAnimation)]) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment