diff --git a/Classes/ChatConversationTableView.m b/Classes/ChatConversationTableView.m index fe59cc311..4516a86dc 100644 --- a/Classes/ChatConversationTableView.m +++ b/Classes/ChatConversationTableView.m @@ -40,6 +40,15 @@ [super viewWillAppear:animated]; self.tableView.accessibilityIdentifier = @"ChatRoom list"; _imagesInChatroom = [NSMutableDictionary dictionary]; + + [NSNotificationCenter.defaultCenter addObserver:self + selector:@selector(updateData) + name:kLinphoneMessageValueUpdated + object:nil]; +} + +- (void)viewWillDisappear:(BOOL)animated { + [NSNotificationCenter.defaultCenter removeObserver:self name:kLinphoneMessageValueUpdated object:nil]; } #pragma mark - @@ -66,6 +75,8 @@ while (chatRoomEvents) { LinphoneEventLog *event = (LinphoneEventLog *)chatRoomEvents->data; [eventList addObject:[NSValue valueWithPointer:linphone_event_log_ref(event)]]; + + LOGD([NSString stringWithFormat:@"adding event at adress: %p", [[eventList lastObject] pointerValue]]); chatRoomEvents = chatRoomEvents->next; } bctbx_list_free_with_data(head, (bctbx_list_free_func)linphone_event_log_unref); @@ -88,6 +99,7 @@ } - (void)addEventEntry:(LinphoneEventLog *)event { + LOGD([NSString stringWithFormat:@"adding event at adress: %p", event]); [eventList addObject:[NSValue valueWithPointer:linphone_event_log_ref(event)]]; int pos = (int)eventList.count - 1; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:pos inSection:0]; @@ -97,6 +109,7 @@ } - (void)updateEventEntry:(LinphoneEventLog *)event { + LOGD([NSString stringWithFormat:@"updating event at adress: %p", event]); NSInteger index = [eventList indexOfObject:[NSValue valueWithPointer:event]]; if (index < 0) { LOGW(@"event entry doesn't exist"); @@ -104,7 +117,11 @@ } [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:FALSE]; // just reload - return; + [self.tableView reloadData]; + [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] + atScrollPosition:UITableViewScrollPositionBottom + animated:YES]; + return; } - (void)scrollToBottom:(BOOL)animated { @@ -189,6 +206,7 @@ if (!cell) { cell = [[NSClassFromString(kCellId) alloc] initWithIdentifier:kCellId]; } + LOGD([NSString stringWithFormat:@"event adress: %p", event]); [cell setEvent:event]; if (chat) [cell update]; diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 9dd0454de..64da44824 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -57,6 +57,7 @@ extern NSString *const kLinphoneCallEncryptionChanged; extern NSString *const kLinphoneFileTransferSendUpdate; extern NSString *const kLinphoneFileTransferRecvUpdate; extern NSString *const kLinphoneQRCodeFound; +extern NSString *const kLinphoneMessageValueUpdated; typedef enum _NetworkType { network_none = 0, diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 5d0a16ef6..3896864cc 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -77,6 +77,7 @@ NSString *const kLinphoneCallEncryptionChanged = @"LinphoneCallEncryptionChanged NSString *const kLinphoneFileTransferSendUpdate = @"LinphoneFileTransferSendUpdate"; NSString *const kLinphoneFileTransferRecvUpdate = @"LinphoneFileTransferRecvUpdate"; NSString *const kLinphoneQRCodeFound = @"LinphoneQRCodeFound"; +NSString *const kLinphoneMessageValueUpdated = @"LinphoneMessageValueUpdated"; const int kLinphoneAudioVbrCodecDefaultBitrate = 36; /*you can override this from linphonerc or linphonerc-factory*/ @@ -2887,20 +2888,22 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { } + (void)setValueInMessageAppData:(id)value forKey:(NSString *)key inMessage:(LinphoneChatMessage *)msg { + dispatch_async(dispatch_get_main_queue(), ^{ + NSMutableDictionary *appDataDict = [NSMutableDictionary dictionary]; + const char *appData = linphone_chat_message_get_appdata(msg); + if (appData) { + appDataDict = [NSJSONSerialization JSONObjectWithData:[NSData dataWithBytes:appData length:strlen(appData)] + options:NSJSONReadingMutableContainers + error:nil]; + } - NSMutableDictionary *appDataDict = [NSMutableDictionary dictionary]; - const char *appData = linphone_chat_message_get_appdata(msg); - if (appData) { - appDataDict = [NSJSONSerialization JSONObjectWithData:[NSData dataWithBytes:appData length:strlen(appData)] - options:NSJSONReadingMutableContainers - error:nil]; - } + [appDataDict setValue:value forKey:key]; - [appDataDict setValue:value forKey:key]; - - NSData *data = [NSJSONSerialization dataWithJSONObject:appDataDict options:0 error:nil]; - NSString *appdataJSON = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - linphone_chat_message_set_appdata(msg, [appdataJSON UTF8String]); + NSData *data = [NSJSONSerialization dataWithJSONObject:appDataDict options:0 error:nil]; + NSString *appdataJSON = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + linphone_chat_message_set_appdata(msg, [appdataJSON UTF8String]); + [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneMessageValueUpdated object:nil]; + }); } #pragma mark - LPConfig Functions diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.m b/Classes/LinphoneUI/UIChatBubblePhotoCell.m index 51008ad03..9bd8b9321 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.m +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.m @@ -68,6 +68,10 @@ return; super.event = event; + + //LOGD([NSString stringWithFormat:@"photo cell adress: %p", self]); + //LOGD([NSString stringWithFormat:@"event adress: %p", event]); + //LOGD([NSString stringWithFormat:@"message adress: %p", linphone_event_log_get_chat_message(event)]); [self setChatMessage:linphone_event_log_get_chat_message(event)]; } @@ -109,6 +113,7 @@ _messageImageView.hidden = YES; _imageGestureRecognizer.enabled = YES; _finalImage.hidden = NO; + [self layoutSubviews]; }); } @@ -363,7 +368,8 @@ } - (void)disconnectFromFileDelegate { - [NSNotificationCenter.defaultCenter removeObserver:self]; + [NSNotificationCenter.defaultCenter removeObserver:self name:kLinphoneFileTransferSendUpdate object:_ftd]; + [NSNotificationCenter.defaultCenter removeObserver:self name:kLinphoneFileTransferRecvUpdate object:_ftd]; _ftd = nil; } diff --git a/Classes/Utils/FileTransferDelegate.m b/Classes/Utils/FileTransferDelegate.m index 3256e8993..dbf7e6d34 100644 --- a/Classes/Utils/FileTransferDelegate.m +++ b/Classes/Utils/FileTransferDelegate.m @@ -106,7 +106,7 @@ static void linphone_iphone_file_transfer_recv(LinphoneChatMessage *message, con userInfo:@{ @"state" : @(LinphoneChatMessageStateDelivered), // we dont want to trigger FileTransferDone here - @"image" : image, + //@"image" : image, @"progress" : @(1.f), }];