From 5188189383a1f7bfd4cd6d86cb6d0ea6bc9e1e04 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Tue, 31 Oct 2017 10:57:58 +0100 Subject: [PATCH] send first messages in a group chat room --- Classes/ChatConversationTableView.m | 49 ++++++----- Classes/ChatConversationView.m | 83 +++++++++++++++---- .../Base.lproj/UIChatBubbleTextCell.xib | 41 ++------- Classes/LinphoneUI/UIChatBubbleTextCell.h | 2 - Classes/LinphoneUI/UIChatNotifiedEventCell.h | 23 +++++ Classes/LinphoneUI/UIChatNotifiedEventCell.m | 49 +++++++++++ .../LinphoneUI/UIChatNotifiedEventCell.xib | 54 ++++++++++++ linphone-Info.plist | 2 + linphone.xcodeproj/project.pbxproj | 10 +++ 9 files changed, 241 insertions(+), 72 deletions(-) create mode 100644 Classes/LinphoneUI/UIChatNotifiedEventCell.h create mode 100644 Classes/LinphoneUI/UIChatNotifiedEventCell.m create mode 100644 Classes/LinphoneUI/UIChatNotifiedEventCell.xib diff --git a/Classes/ChatConversationTableView.m b/Classes/ChatConversationTableView.m index 6e5747caf..2bb4aa63b 100644 --- a/Classes/ChatConversationTableView.m +++ b/Classes/ChatConversationTableView.m @@ -21,6 +21,7 @@ #import "ChatConversationTableView.h" #import "UIChatBubbleTextCell.h" #import "UIChatBubblePhotoCell.h" +#import "UIChatNotifiedEventCell.h" #import "PhoneMainView.h" @implementation ChatConversationTableView @@ -165,25 +166,35 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *kCellId = nil; - LinphoneChatMessage *chat = bctbx_list_nth_data(messageList, (int)[indexPath row]); - if (linphone_chat_message_get_file_transfer_information(chat) || - linphone_chat_message_get_external_body_url(chat)) { - kCellId = NSStringFromClass(UIChatBubblePhotoCell.class); - } else { - kCellId = NSStringFromClass(UIChatBubbleTextCell.class); - } - UIChatBubbleTextCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId]; - if (cell == nil) { - cell = [[NSClassFromString(kCellId) alloc] initWithIdentifier:kCellId]; - } - [cell setChatMessage:chat]; - if (chat) { - [cell update]; - } - [cell setChatRoomDelegate:_chatRoomDelegate]; - [super accessoryForCell:cell atPath:indexPath]; - cell.selectionStyle = UITableViewCellSelectionStyleNone; - return cell; + //LinphoneEventLog *event = bctbx_list_nth_data(messageList, (int)[indexPath row]); + //if (linphone_event_log_get_type(event) == LinphoneEventLogTypeConferenceChatMessage) { + LinphoneChatMessage *chat = bctbx_list_nth_data(messageList, (int)[indexPath row]); //linphone_event_log_get_chat_message(event); + if (linphone_chat_message_get_file_transfer_information(chat) || + linphone_chat_message_get_external_body_url(chat)) { + kCellId = NSStringFromClass(UIChatBubblePhotoCell.class); + } else { + kCellId = NSStringFromClass(UIChatBubbleTextCell.class); + } + UIChatBubbleTextCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId]; + if (cell == nil) { + cell = [[NSClassFromString(kCellId) alloc] initWithIdentifier:kCellId]; + } + [cell setChatMessage:chat]; + if (chat) { + [cell update]; + } + [cell setChatRoomDelegate:_chatRoomDelegate]; + [super accessoryForCell:cell atPath:indexPath]; + cell.selectionStyle = UITableViewCellSelectionStyleNone; + return cell; + /*} else { + kCellId = NSStringFromClass(UIChatNotifiedEventCell.class); + UIChatNotifiedEventCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId]; + [cell setEvent:event]; + [super accessoryForCell:cell atPath:indexPath]; + cell.selectionStyle = UITableViewCellSelectionStyleNone; + return cell; + }*/ } #pragma mark - UITableViewDelegate Functions diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 49686ccb4..7a4fbc292 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -117,6 +117,14 @@ static UICompositeViewDescription *compositeDescription = nil; name:kLinphoneCallUpdate object:nil]; + LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(_chatRoom); + linphone_chat_room_cbs_set_state_changed(cbs, on_chat_room_state_changed); + linphone_chat_room_cbs_set_subject_changed(cbs, on_chat_room_subject_changed); + linphone_chat_room_cbs_set_participant_added(cbs, on_chat_room_participant_added); + linphone_chat_room_cbs_set_participant_removed(cbs, on_chat_room_participant_removed); + linphone_chat_room_cbs_set_participant_admin_status_changed(cbs, on_chat_room_participant_admin_status_changed); + linphone_chat_room_cbs_set_user_data(cbs, (__bridge void*)self); + [self updateSuperposedButtons]; if (_tableController.isEditing) { @@ -132,28 +140,20 @@ static UICompositeViewDescription *compositeDescription = nil; if (linphone_chat_room_get_subject(_chatRoom)) _addressLabel.text = [NSString stringWithUTF8String:linphone_chat_room_get_subject(_chatRoom)]; - if (!linphone_chat_room_can_handle_participants(_chatRoom)) { - _particpantsLabel.hidden = TRUE; - } else { - _particpantsLabel.hidden = FALSE; - bctbx_list_t *participants = linphone_chat_room_get_participants(_chatRoom); - _particpantsLabel.text = @""; - while (participants) { - LinphoneParticipant *participant = (LinphoneParticipant *)participants->data; - if (![_particpantsLabel.text isEqualToString:@""]) - _particpantsLabel.text = [_particpantsLabel.text stringByAppendingString:@", "]; - - _particpantsLabel.text = [_particpantsLabel.text stringByAppendingString:[NSString stringWithUTF8String:linphone_address_get_display_name(linphone_participant_get_address(participant)) - ? linphone_address_get_display_name(linphone_participant_get_address(participant)) - : linphone_address_get_username(linphone_participant_get_address(participant))]]; - participants = participants->next; - } - } + [self updateParticipantLabel]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; + LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(_chatRoom); + linphone_chat_room_cbs_set_state_changed(cbs, NULL); + linphone_chat_room_cbs_set_subject_changed(cbs, NULL); + linphone_chat_room_cbs_set_participant_added(cbs, NULL); + linphone_chat_room_cbs_set_participant_removed(cbs, NULL); + linphone_chat_room_cbs_set_participant_admin_status_changed(cbs, NULL); + linphone_chat_room_cbs_set_user_data(cbs, NULL); + [_messageField resignFirstResponder]; [self setComposingVisible:FALSE withDelay:0]; // will hide the "user is composing.." message @@ -360,7 +360,27 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)updateSuperposedButtons { [_backToCallButton update]; _infoButton.hidden = !linphone_chat_room_can_handle_participants(_chatRoom) || !_backToCallButton.hidden; - _callButton.hidden = !_backToCallButton.hidden && !_infoButton.hidden; + _callButton.hidden = !_backToCallButton.hidden || !_infoButton.hidden; +} + +- (void)updateParticipantLabel { + if (!linphone_chat_room_can_handle_participants(_chatRoom)) { + _particpantsLabel.hidden = TRUE; + } else { + _particpantsLabel.hidden = FALSE; + bctbx_list_t *participants = linphone_chat_room_get_participants(_chatRoom); + _particpantsLabel.text = @""; + while (participants) { + LinphoneParticipant *participant = (LinphoneParticipant *)participants->data; + if (![_particpantsLabel.text isEqualToString:@""]) + _particpantsLabel.text = [_particpantsLabel.text stringByAppendingString:@", "]; + + _particpantsLabel.text = [_particpantsLabel.text stringByAppendingString:[NSString stringWithUTF8String:linphone_address_get_display_name(linphone_participant_get_address(participant)) + ? linphone_address_get_display_name(linphone_participant_get_address(participant)) + : linphone_address_get_username(linphone_participant_get_address(participant))]]; + participants = participants->next; + } + } } #pragma mark - Event Functions @@ -704,4 +724,31 @@ static UICompositeViewDescription *compositeDescription = nil; }]; } +#pragma mark - chat room callbacks + +void on_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomState newState) { + ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + if (view) {}; +} + +void on_chat_room_subject_changed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { + ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + view.addressLabel.text = [NSString stringWithUTF8String:linphone_chat_room_get_subject(cr)]; +} + +void on_chat_room_participant_added(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { + ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + [view updateParticipantLabel]; +} + +void on_chat_room_participant_removed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { + ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + [view updateParticipantLabel]; +} + +void on_chat_room_participant_admin_status_changed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { + ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + if (view) {}; +} + @end diff --git a/Classes/LinphoneUI/Base.lproj/UIChatBubbleTextCell.xib b/Classes/LinphoneUI/Base.lproj/UIChatBubbleTextCell.xib index 61c207140..b37bdc9a4 100644 --- a/Classes/LinphoneUI/Base.lproj/UIChatBubbleTextCell.xib +++ b/Classes/LinphoneUI/Base.lproj/UIChatBubbleTextCell.xib @@ -17,8 +17,6 @@ - - @@ -34,37 +32,15 @@ - + - - - - - - - - - - - - - - - - + - + @@ -93,11 +69,11 @@ - + - + @@ -109,14 +85,14 @@ - + @@ -129,7 +105,7 @@ - + @@ -138,6 +114,5 @@ - diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.h b/Classes/LinphoneUI/UIChatBubbleTextCell.h index 2a76dc620..9c3d71762 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.h +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.h @@ -39,8 +39,6 @@ @property(weak, nonatomic) IBOutlet UIImageView *LIMEKO; @property(weak, nonatomic) IBOutlet UIImageView *imdmIcon; @property(weak, nonatomic) IBOutlet UILabel *imdmLabel; -@property (weak, nonatomic) IBOutlet UILabel *eventContactDateLabel; -@property (weak, nonatomic) IBOutlet UIView *eventView; + (CGSize)ViewSizeForMessage:(LinphoneChatMessage *)chat withWidth:(int)width; diff --git a/Classes/LinphoneUI/UIChatNotifiedEventCell.h b/Classes/LinphoneUI/UIChatNotifiedEventCell.h new file mode 100644 index 000000000..25d2a53ea --- /dev/null +++ b/Classes/LinphoneUI/UIChatNotifiedEventCell.h @@ -0,0 +1,23 @@ +// +// UIChatNotifiedEventCell.h +// linphone +// +// Created by REIS Benjamin on 30/10/2017. +// + +#ifndef UIChatNotifiedEventCell_h +#define UIChatNotifiedEventCell_h + +#import + +#import "ChatConversationTableView.h" + +@interface UIChatNotifiedEventCell : UITableViewCell + +@property(readonly, nonatomic) LinphoneEventLog *event; +@property (weak, nonatomic) IBOutlet UILabel *contactDateLabel; + +- (void)setEvent:(LinphoneEventLog *)event; +@end + +#endif /* UIChatNotifiedEventCell_h */ diff --git a/Classes/LinphoneUI/UIChatNotifiedEventCell.m b/Classes/LinphoneUI/UIChatNotifiedEventCell.m new file mode 100644 index 000000000..7efacc683 --- /dev/null +++ b/Classes/LinphoneUI/UIChatNotifiedEventCell.m @@ -0,0 +1,49 @@ +// +// UIChatNotifiedEventCell.m +// linphone +// +// Created by REIS Benjamin on 30/10/2017. +// + +#import +#import "UIChatNotifiedEventCell.h" +#import "LinphoneManager.h" +#import "PhoneMainView.h" + +#import +#import + +@implementation UIChatNotifiedEventCell + +#pragma mark - Lifecycle Functions + +- (id)initWithIdentifier:(NSString *)identifier { + if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]) != nil) { + if ([identifier isEqualToString:NSStringFromClass(self.class)]) { + NSArray *arrayOfViews = + [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class) owner:self options:nil]; + // resize cell to match .nib size. It is needed when resized the cell to + // correctly adapt its height too + UIView *sub = ((UIView *)[arrayOfViews objectAtIndex:arrayOfViews.count - 1]); + [self setFrame:CGRectMake(0, 0, sub.frame.size.width, sub.frame.size.height)]; + [self addSubview:sub]; + } + } + return self; +} + +- (void)dealloc { + _event = NULL; +} + +#pragma mark - + +- (void)setEvent:(LinphoneEventLog *)event { + +} + +- (void)layoutSubviews { + [super layoutSubviews]; +} + +@end diff --git a/Classes/LinphoneUI/UIChatNotifiedEventCell.xib b/Classes/LinphoneUI/UIChatNotifiedEventCell.xib new file mode 100644 index 000000000..d2e89f7f6 --- /dev/null +++ b/Classes/LinphoneUI/UIChatNotifiedEventCell.xib @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/linphone-Info.plist b/linphone-Info.plist index 630b626a0..dba791aa9 100644 --- a/linphone-Info.plist +++ b/linphone-Info.plist @@ -68,6 +68,8 @@ Make calls with your friends NSMicrophoneUsageDescription Use microphone to make audio calls + NSPhotoLibraryAddUsageDescription + Add tranfered files to your library NSPhotoLibraryUsageDescription Share photos with your friends and customize avatars NSVoIPUsageDescription diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index b2f890fda..12ce7973e 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -683,6 +683,8 @@ 8C5BCEDF1EB385B100A9AAEF /* bctoolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8C5BCEC71EB3859200A9AAEF /* bctoolbox.framework */; }; 8C5BCEE01EB385B100A9AAEF /* linphone.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8C5BCEC81EB3859200A9AAEF /* linphone.framework */; }; 8C73477C1D9BA3A00022EE8C /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8C73477B1D9BA3A00022EE8C /* UserNotifications.framework */; }; + 8C92ABE81FA773190006FB5D /* UIChatNotifiedEventCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8C92ABE71FA773190006FB5D /* UIChatNotifiedEventCell.xib */; }; + 8C92ABF31FA773E50006FB5D /* UIChatNotifiedEventCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C92ABF21FA773E50006FB5D /* UIChatNotifiedEventCell.m */; }; 8C9C5E0D1F83B2EF006987FA /* ChatConversationCreateCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C9C5E0C1F83B2EF006987FA /* ChatConversationCreateCollectionViewController.m */; }; 8C9C5E111F83BD97006987FA /* UIChatCreateCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C9C5E0F1F83BD97006987FA /* UIChatCreateCollectionViewCell.m */; }; 8C9C5E121F83BD97006987FA /* UIChatCreateCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8C9C5E101F83BD97006987FA /* UIChatCreateCollectionViewCell.xib */; }; @@ -1702,6 +1704,9 @@ 8C5D1B9A1D9BC48100DC6539 /* UIShopTableCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIShopTableCell.m; sourceTree = ""; }; 8C5D1B9B1D9BC48100DC6539 /* UIShopTableCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = UIShopTableCell.xib; sourceTree = ""; }; 8C73477B1D9BA3A00022EE8C /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; }; + 8C92ABE71FA773190006FB5D /* UIChatNotifiedEventCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = UIChatNotifiedEventCell.xib; sourceTree = ""; }; + 8C92ABF11FA773C20006FB5D /* UIChatNotifiedEventCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIChatNotifiedEventCell.h; sourceTree = ""; }; + 8C92ABF21FA773E50006FB5D /* UIChatNotifiedEventCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIChatNotifiedEventCell.m; sourceTree = ""; }; 8C9C5E0B1F83B2EF006987FA /* ChatConversationCreateCollectionViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ChatConversationCreateCollectionViewController.h; sourceTree = ""; }; 8C9C5E0C1F83B2EF006987FA /* ChatConversationCreateCollectionViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ChatConversationCreateCollectionViewController.m; sourceTree = ""; }; 8C9C5E0E1F83BD97006987FA /* UIChatCreateCollectionViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIChatCreateCollectionViewCell.h; sourceTree = ""; }; @@ -2192,6 +2197,9 @@ D3A8BB6E15A6C7D500F96BE5 /* UIChatBubbleTextCell.h */, D3A8BB6F15A6C7D500F96BE5 /* UIChatBubbleTextCell.m */, 639E9CA51C0DB7EA00019A75 /* UIChatBubbleTextCell.xib */, + 8C92ABF11FA773C20006FB5D /* UIChatNotifiedEventCell.h */, + 8C92ABF21FA773E50006FB5D /* UIChatNotifiedEventCell.m */, + 8C92ABE71FA773190006FB5D /* UIChatNotifiedEventCell.xib */, D3EA540F159853750037DC6B /* UIChatCell.h */, D3EA5410159853750037DC6B /* UIChatCell.m */, 639CEB0B1A1DF4FA004DE38F /* UIChatCell.xib */, @@ -3419,6 +3427,7 @@ D38187F815FE355D00C3EDCA /* TabBarView.xib in Resources */, 633FEE2F1D3CD5590014B822 /* color_G.png in Resources */, 633FEECE1D3CD55A0014B822 /* numpad_6_over@2x.png in Resources */, + 8C92ABE81FA773190006FB5D /* UIChatNotifiedEventCell.xib in Resources */, 633FEDAB1D3CD5590014B822 /* backspace_disabled@2x.png in Resources */, 633FEDD91D3CD5590014B822 /* call_start_body_default~ipad@2x.png in Resources */, 633FEE401D3CD5590014B822 /* contacts_all_selected.png in Resources */, @@ -4091,6 +4100,7 @@ D380800015C2894A005BE9BC /* IASKSwitch.m in Sources */, D380800215C2894A005BE9BC /* IASKTextField.m in Sources */, D380801315C299D0005BE9BC /* ColorSpaceUtilites.m in Sources */, + 8C92ABF31FA773E50006FB5D /* UIChatNotifiedEventCell.m in Sources */, 633FEF581D3CD5E00014B822 /* UIAvatarPresence.m in Sources */, 637157A11B283FE200C91677 /* FileTransferDelegate.m in Sources */, D378AB2A15DCDB4A0098505D /* ImagePickerView.m in Sources */,