diff --git a/Classes/ChatsListTableView.m b/Classes/ChatsListTableView.m index 1aa26132c..1657ad7f0 100644 --- a/Classes/ChatsListTableView.m +++ b/Classes/ChatsListTableView.m @@ -235,7 +235,7 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo return; LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)bctbx_list_nth_data(_data, (int)[indexPath row]); - [PhoneMainView.instance goToChatRoom:chatRoom]; + [PhoneMainView.instance goToChatRoomSwift:chatRoom]; } void deletion_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomState newState) { diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 440ef5788..d0bb6092f 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -926,24 +926,13 @@ static RootViewManager *rootViewManagerInstance = nil; - (void)goToChatRoomSwift:(LinphoneChatRoom *)cr { - /* _waitView.hidden = YES; _waitView = NULL; ChatConversationViewSwift *view = VIEW(ChatConversationViewSwift); - if (view.chatRoom && view.chatRoomCbs) - linphone_chat_room_remove_callbacks(view.chatRoom, view.chatRoomCbs); - - view.chatRoomCbs = NULL; - if (view.chatRoom != cr) - [view clearMessageView]; - view.chatRoom = cr; - view.peerAddress = linphone_address_as_string(linphone_chat_room_get_peer_address(cr)); - self.currentRoom = view.chatRoom; - if (PhoneMainView.instance.currentView == view.compositeViewDescription) - [view configureForRoom:FALSE]; - else - [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; - */ + + [view initChatRoomWithCChatRoom:cr]; + + [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; } void main_view_chat_room_conference_joined(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { diff --git a/Classes/Swift/Chat/Views/ChatConversationViewSwift.swift b/Classes/Swift/Chat/Views/ChatConversationViewSwift.swift index f1af8af47..10f9b3c03 100644 --- a/Classes/Swift/Chat/Views/ChatConversationViewSwift.swift +++ b/Classes/Swift/Chat/Views/ChatConversationViewSwift.swift @@ -33,41 +33,85 @@ import DropDown func compositeViewDescription() -> UICompositeViewDescription! { return type(of: self).compositeDescription } + let APP_GROUP_ID = "group.belledonne-communications.linphone.widget" + var debugEnabled = false + + + var chatRoom: ChatRoom? = nil + var chatRoomDelegate: ChatRoomDelegate? = nil + var address: String? = nil + var notifications_on: Bool = true + let menu: DropDown = { let menu = DropDown() - menu.dataSource = [ - "Item 1", - "Item 2", - "Item 3", - "Item 4", - "Item 5" + menu.dataSource = [""] + var images = [ + "contact_add_default.png", + "contacts_all_default.png", + "menu_voip_meeting_schedule", + "menu_security_default.png", + "ephemeral_messages_default.png", + "menu_notifications_off.png", + "menu_notifications_on.png", + "delete_default.png", + "chat_group_informations.png" ] menu.cellNib = UINib(nibName: "DropDownCell", bundle: nil) menu.customCellConfiguration = { index, title, cell in guard let cell = cell as? MyCell else { return } - cell.myImageView.image = UIImage(named: "security_2_indicator.png") + if(index < images.count){ + switch menu.dataSource[index] { + case VoipTexts.dropdown_menu_chat_conversation_add_to_contact: + cell.myImageView.image = UIImage(named: images[0]) + case VoipTexts.dropdown_menu_chat_conversation_go_to_contact: + cell.myImageView.image = UIImage(named: images[1]) + case VoipTexts.conference_schedule_start: + cell.myImageView.image = UIImage(named: images[2]) + case VoipTexts.dropdown_menu_chat_conversation_conversation_device: + cell.myImageView.image = UIImage(named: images[3]) + case VoipTexts.dropdown_menu_chat_conversation_ephemeral_messages: + cell.myImageView.image = UIImage(named: images[4]) + case VoipTexts.dropdown_menu_chat_conversation_mute_notifications: + cell.myImageView.image = UIImage(named: images[5]) + case VoipTexts.dropdown_menu_chat_conversation_unmute_notifications: + cell.myImageView.image = UIImage(named: images[6]) + case VoipTexts.dropdown_menu_chat_conversation_delete_messages: + cell.myImageView.image = UIImage(named: images[7]) + default: + cell.myImageView.image = UIImage(named: images[8]) + } + } } return menu }() override func viewDidLoad() { super.viewDidLoad( - backAction: { - self.goBackChatListView() - }, - action1: { + backAction: { + self.goBackChatListView() + }, + action1: { - }, - action2: { + }, + action1Bis: { + + }, + action2: { self.tapChooseMenuItem(self.action2Button) - }, - title:"benoit.martins.test1" + }, + title: address ?? "Error" + //title:"benoit.martins.test1" //title:"Coin à champis de François" ) //view.backgroundColor = VoipTheme.backgroundColor3.get() } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + topBar.backgroundColor = VoipTheme.voipToolbarBackgroundColor.get() + } func goBackChatListView() { PhoneMainView.instance().pop(toView: ChatsListView.compositeViewDescription()) @@ -77,9 +121,72 @@ import DropDown menu.anchorView = sender menu.bottomOffset = CGPoint(x: -UIScreen.main.bounds.width * 0.6, y: sender.frame.size.height) menu.show() - - menu.selectionAction = { index, title in - print("index \(index) and \(title)") - } } + + func initDataSource(groupeChat: Bool, secureLevel: Bool, cChatRoom: OpaquePointer) { + menu.dataSource.removeAll() + + let config = Config.newForSharedCore(appGroupId: APP_GROUP_ID, configFilename: "linphonerc", factoryConfigFilename: "") + let debugLevel = config?.getInt(section: "app", key: "debugenable_preference", defaultValue: LogLevel.Debug.rawValue) + debugEnabled = (debugLevel! >= LogLevel.Debug.rawValue && debugLevel! < LogLevel.Error.rawValue) + + print(debugEnabled) + + if(groupeChat){ + menu.dataSource.append(VoipTexts.conference_schedule_start) + menu.dataSource.append(VoipTexts.dropdown_menu_chat_conversation_group_infos) + }else{ + var contact: Contact? = nil + let firstParticipant = chatRoom?.participants.first + let addr = (firstParticipant != nil) ? linphone_participant_get_address(firstParticipant?.getCobject) : linphone_chat_room_get_peer_address(cChatRoom) + + contact = FastAddressBook.getContactWith(addr) + + if (contact == nil) { + menu.dataSource.append(VoipTexts.dropdown_menu_chat_conversation_add_to_contact) + } else { + menu.dataSource.append(VoipTexts.dropdown_menu_chat_conversation_go_to_contact) + } + } + if(secureLevel){ + menu.dataSource.append(VoipTexts.dropdown_menu_chat_conversation_conversation_device) + menu.dataSource.append(VoipTexts.dropdown_menu_chat_conversation_ephemeral_messages) + } + if(notifications_on){ + menu.dataSource.append(VoipTexts.dropdown_menu_chat_conversation_mute_notifications) + }else{ + menu.dataSource.append(VoipTexts.dropdown_menu_chat_conversation_unmute_notifications) + } + menu.dataSource.append(VoipTexts.dropdown_menu_chat_conversation_delete_messages) + menu.dataSource.append(VoipTexts.dropdown_menu_chat_conversation_debug_infos) + } + + @objc func initChatRoom(cChatRoom:OpaquePointer) { + chatRoom = ChatRoom.getSwiftObject(cObject: cChatRoom) + PhoneMainView.instance().currentRoom = cChatRoom + address = chatRoom?.peerAddress?.asString() + var changeIcon = false + let isOneToOneChat = chatRoom!.hasCapability(mask: Int(LinphoneChatRoomCapabilitiesOneToOne.rawValue)) + + if (isOneToOneChat) { + + let firstParticipant = chatRoom?.participants.first + let addr = (firstParticipant != nil) ? linphone_participant_get_address(firstParticipant?.getCobject) : linphone_chat_room_get_peer_address(cChatRoom); + address = FastAddressBook.displayName(for: addr) ?? "unknow" + changeIcon = false + + } else { + address = chatRoom?.subject + changeIcon = true + + + } + + changeTitle(titleString: address ?? "Error") + changeCallIcon(groupeChat: changeIcon) + + let secureLevel = FastAddressBook.image(for: linphone_chat_room_get_security_level(cChatRoom)) + changeSecureLevel(secureLevel: secureLevel != nil, imageBadge: secureLevel) + initDataSource(groupeChat: !isOneToOneChat, secureLevel: secureLevel != nil, cChatRoom: cChatRoom) + } } diff --git a/Classes/Swift/Conference/ViewModels/ConferenceSchedulingViewModel.swift b/Classes/Swift/Conference/ViewModels/ConferenceSchedulingViewModel.swift index 17b53524f..0dc8c50e2 100644 --- a/Classes/Swift/Conference/ViewModels/ConferenceSchedulingViewModel.swift +++ b/Classes/Swift/Conference/ViewModels/ConferenceSchedulingViewModel.swift @@ -62,7 +62,7 @@ class ConferenceSchedulingViewModel { private var hour: Int = 0 private var minutes: Int = 0 - private var chatRooomDelegate : ChatRoomDelegate? = nil + private var chatRoomDelegate : ChatRoomDelegate? = nil private var conferenceSchedulerDelegate : ConferenceSchedulerDelegateStub? = nil var existingConfInfo:MutableLiveData = MutableLiveData() @@ -110,14 +110,14 @@ class ConferenceSchedulingViewModel { } ) - chatRooomDelegate = ChatRoomDelegateStub( + chatRoomDelegate = ChatRoomDelegateStub( onStateChanged : { (room: ChatRoom, state: ChatRoom.State) -> Void in if (state == ChatRoom.State.Created) { Log.i("[Conference Creation] Chat room created") - room.removeDelegate(delegate: self.chatRooomDelegate!) + room.removeDelegate(delegate: self.chatRoomDelegate!) } else if (state == ChatRoom.State.CreationFailed) { Log.e("[Conference Creation] Group chat room creation has failed !") - room.removeDelegate(delegate: self.chatRooomDelegate!) + room.removeDelegate(delegate: self.chatRoomDelegate!) } } ) diff --git a/Classes/Swift/Util/BackActionsNavigationView.swift b/Classes/Swift/Util/BackActionsNavigationView.swift index 040dca2ba..052b4dfb7 100644 --- a/Classes/Swift/Util/BackActionsNavigationView.swift +++ b/Classes/Swift/Util/BackActionsNavigationView.swift @@ -48,6 +48,7 @@ import linphonesw let backButton = CallControlButton(buttonTheme:VoipTheme.nav_button("back_default")) let action1Button = CallControlButton(buttonTheme:VoipTheme.nav_button("call_audio_start_default")) + let action1BisButton = CallControlButton(buttonTheme:VoipTheme.nav_button("voip_conference_new")) let action2Button = CallControlButton(buttonTheme:VoipTheme.nav_button("more_menu_default")) let cancel_button_alert = UIButton() @@ -56,13 +57,14 @@ import linphonesw var isChecked = false let checkBoxText = UILabel() - let isSecure : Bool = false + var isSecure : Bool = false let isGroupChat : Bool = false let levelMaxSecure : Bool = false let floatingButton = CallControlButton(buttonTheme:VoipTheme.nav_button("")) func viewDidLoad(backAction : @escaping () -> Void, action1 : @escaping () -> Void, + action1Bis : @escaping () -> Void, action2 : @escaping () -> Void, title:String) { self.backAction = backAction @@ -79,18 +81,16 @@ import linphonesw topBar.addSubview(action2Button) action2Button.alignParentRight(withMargin: side_buttons_margin).matchParentHeight().done() action2Button.onClickAction = action2 - - if(isGroupChat){ - action1Button.setImage(UIImage(named:"voip_conference_new.png"), for: .normal) - action1Button.setImage(UIImage(named:"voip_conference_new_selected.png"), for: .highlighted) - } topBar.addSubview(action1Button) + topBar.addSubview(action1BisButton) action1Button.toLeftOf(action2Button, withRightMargin: 20).matchParentHeight().done() - if(!isGroupChat){ - action1Button.size(w: 35, h: 35).done() - } + action1BisButton.toLeftOf(action2Button, withRightMargin: 20).matchParentHeight().done() + action1Button.onClickAction = action1 + action1BisButton.onClickAction = action1Bis + + action1BisButton.isHidden = true topBar.addSubview(titleLabel) titleLabel.toRightOf(backButton, withLeftMargin: 10).matchParentHeight().done() @@ -107,15 +107,12 @@ import linphonesw view.addSubview(messageView) messageView.alignParentBottom().height(top_bar_height).matchParentSideBorders().done() - - if(isSecure){ - view.addSubview(floatingButton) - floatingButton.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: -5).isActive = true - floatingButton.topAnchor.constraint(equalTo: self.view.layoutMarginsGuide.topAnchor, constant: top_bar_height + 5).isActive = true - levelMaxSecure ? floatingButton.setImage(UIImage(named:"security_2_indicator.png"), for: .normal) : floatingButton.setImage(UIImage(named:"security_1_indicator.png"), for: .normal) - floatingButton.imageEdgeInsets = UIEdgeInsets(top: 45, left: 45, bottom: 45, right: 45) - floatingButton.onClickAction = alertAction - } + view.addSubview(floatingButton) + floatingButton.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: -5).isActive = true + floatingButton.topAnchor.constraint(equalTo: self.view.layoutMarginsGuide.topAnchor, constant: top_bar_height + 5).isActive = true + floatingButton.setImage(UIImage(named:"security_alert_indicator.png"), for: .normal) + floatingButton.imageEdgeInsets = UIEdgeInsets(top: 45, left: 45, bottom: 45, right: 45) + floatingButton.onClickAction = alertAction } @@ -208,6 +205,29 @@ import linphonesw + } + + func changeTitle(titleString: String){ + titleLabel.text = titleString + } + + func changeSecureLevel(secureLevel: Bool, imageBadge: UIImage?){ + isSecure = secureLevel + if(isSecure){ + floatingButton.isHidden = false + floatingButton.setImage(imageBadge, for: .normal) + }else{ + floatingButton.isHidden = true + } } + func changeCallIcon(groupeChat: Bool){ + if(groupeChat){ + action1Button.isHidden = true + action1BisButton.isHidden = false + }else{ + action1Button.isHidden = false + action1BisButton.isHidden = true + } + } } diff --git a/Classes/Swift/Voip/Theme/VoipTexts.swift b/Classes/Swift/Voip/Theme/VoipTexts.swift index ef403e96f..3c2d458cc 100644 --- a/Classes/Swift/Voip/Theme/VoipTexts.swift +++ b/Classes/Swift/Voip/Theme/VoipTexts.swift @@ -156,6 +156,15 @@ import UIKit @objc static let image_picker_view_alert_action_document = NSLocalizedString("Document",comment:"") @objc static let alert_dialog_secure_badge_button_chat_conversation_title = NSLocalizedString("Instant messages are end-to-end encrypted in secured conversations. It is possible to upgrade the security level of a conversation by authenticating participants. To do so, call the contact and follow the authentification process.",comment:"") @objc static let alert_dialog_secure_badge_button_chat_conversation_checkboxtext = NSLocalizedString("Do not show again",comment:"") + @objc static let dropdown_menu_chat_conversation_go_to_contact = NSLocalizedString("Go to contact",comment:"") + @objc static let dropdown_menu_chat_conversation_add_to_contact = NSLocalizedString("Add to contacts",comment:"") + @objc static let dropdown_menu_chat_conversation_group_infos = NSLocalizedString("Group infos",comment:"") + @objc static let dropdown_menu_chat_conversation_conversation_device = NSLocalizedString("Conversation's devices",comment:"") + @objc static let dropdown_menu_chat_conversation_ephemeral_messages = NSLocalizedString("Ephemeral messages",comment:"") + @objc static let dropdown_menu_chat_conversation_mute_notifications = NSLocalizedString("Mute notifications",comment:"") + @objc static let dropdown_menu_chat_conversation_unmute_notifications = NSLocalizedString("Un-mute notifications",comment:"") + @objc static let dropdown_menu_chat_conversation_delete_messages = NSLocalizedString("Delete messages",comment:"") + @objc static let dropdown_menu_chat_conversation_debug_infos = NSLocalizedString("Debug infos",comment:"") // FROM ANDROID END