From 9e6c045a35fb4dea47238c34b5ce0125372084ef Mon Sep 17 00:00:00 2001 From: David Idmansour Date: Tue, 26 Jun 2018 11:41:31 +0200 Subject: [PATCH] save text messages data to notification user info --- Classes/LinphoneManager.m | 30 ++++++++- .../Base.lproj/MainInterface.storyboard | 61 +++++++++---------- .../NotificationViewController.h | 2 +- .../NotificationViewController.m | 34 +++++++++-- 4 files changed, 90 insertions(+), 37 deletions(-) diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 485fde3d9..8d7eb4494 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1230,7 +1230,35 @@ static void linphone_iphone_popup_password_request(LinphoneCore *lc, LinphoneAut } content.sound = [UNNotificationSound soundNamed:@"msg.caf"]; content.categoryIdentifier = @"msg_cat"; - content.userInfo = @{@"from" : from, @"peer_addr" : peer_uri, @"local_addr" : local_uri, @"CallId" : callID}; + NSMutableArray *msgs = [NSMutableArray array]; + bctbx_list_t *history = linphone_chat_room_get_history(room, 3); + while (history) { + NSMutableDictionary *msgData = [NSMutableDictionary dictionary]; + LinphoneChatMessage *msg = history->data; + bool_t isOutgoing = linphone_chat_message_is_outgoing(msg); + bool_t isFileTransfer = linphone_chat_message_is_file_transfer(msg); + const LinphoneAddress *fromAddress = linphone_chat_message_get_from_address(msg); + NSString *displayNameDate = [NSString stringWithFormat:@"%@ - %@", [LinphoneUtils timeToString:linphone_chat_message_get_time(msg) + withFormat:LinphoneDateChatBubble], + [FastAddressBook displayNameForAddress:fromAddress]]; + UIImage *fromImage = [UIImage resizeImage:[FastAddressBook imageForAddress:fromAddress] + withMaxWidth:200 + andMaxHeight:200]; + NSData *fromImageData = UIImageJPEGRepresentation(fromImage, 1); + [msgData setObject:displayNameDate forKey:@"displayNameDate"]; + [msgData setObject:[NSNumber numberWithBool:isFileTransfer] forKey:@"isFileTransfer"]; + [msgData setObject:fromImageData forKey:@"fromImageData"]; + if (isFileTransfer) { + // TODO + } else { + const char *textMsg = linphone_chat_message_get_text_content(msg); + [msgData setObject:[NSString stringWithUTF8String:textMsg] forKey:@"msg"]; + } + [msgData setObject:[NSNumber numberWithBool:isOutgoing] forKey:@"isOutgoing"]; + [msgs addObject:msgData]; + history = bctbx_list_next(history); + } + content.userInfo = @{@"from" : from, @"peer_addr" : peer_uri, @"local_addr" : local_uri, @"CallId" : callID, @"msgs" : msgs}; content.accessibilityLabel = @"Message notif"; UNNotificationRequest *req = [UNNotificationRequest requestWithIdentifier:@"call_request" content:content trigger:NULL]; [[UNUserNotificationCenter currentNotificationCenter] diff --git a/richNotifications/Base.lproj/MainInterface.storyboard b/richNotifications/Base.lproj/MainInterface.storyboard index b596d3278..7bfc6b3a5 100644 --- a/richNotifications/Base.lproj/MainInterface.storyboard +++ b/richNotifications/Base.lproj/MainInterface.storyboard @@ -1,43 +1,42 @@ - + + + + - - + + - + - - - + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/richNotifications/NotificationViewController.h b/richNotifications/NotificationViewController.h index 6bc345f56..f96beffbd 100644 --- a/richNotifications/NotificationViewController.h +++ b/richNotifications/NotificationViewController.h @@ -7,6 +7,6 @@ #import -@interface NotificationViewController : UIViewController +@interface NotificationViewController : UITableViewController @end diff --git a/richNotifications/NotificationViewController.m b/richNotifications/NotificationViewController.m index 8a738e4b1..e40e6ae9f 100644 --- a/richNotifications/NotificationViewController.m +++ b/richNotifications/NotificationViewController.m @@ -11,11 +11,12 @@ @interface NotificationViewController () -@property IBOutlet UILabel *label; - @end -@implementation NotificationViewController +@implementation NotificationViewController { + @private + NSArray *msgs; +} - (void)viewDidLoad { [super viewDidLoad]; @@ -23,7 +24,32 @@ } - (void)didReceiveNotification:(UNNotification *)notification { - self.label.text = notification.request.content.body; + msgs = [[[[notification request] content] userInfo] objectForKey:@"msgs"]; + printf("Taille tab : %d\n", (unsigned int)msgs.count); + [self.tableView reloadData]; +} + +#pragma mark - UITableViewDataSource Functions + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return msgs.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + BOOL isOutgoing = ((NSNumber *)[msgs[indexPath.row] objectForKey:@"isOutgoing"]).boolValue; + NSString *display = ((NSString *)[msgs[indexPath.row] objectForKey:@"displayNameDate"]); + NSString *msgText = ((NSString *)[msgs[indexPath.row] objectForKey:@"msg"]); + NSData *imageData = [msgs[indexPath.row] objectForKey:@"fromImageData"]; + printf("Message %s de %s : %s\n", isOutgoing ? "sortant" : "entrant", + display.UTF8String, + msgText.UTF8String); + printf("Taille de l'image de profil : %d\n", (unsigned int)imageData.length); + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"notificationCell" forIndexPath:indexPath]; + return cell; } @end