From 70fc87d41bbf1c6c006665a64a593ca9b0fdecad Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Mon, 23 Jul 2018 16:49:45 +0200 Subject: [PATCH 1/7] Add english string localizations for room message send reply --- Riot/Assets/en.lproj/Vector.strings | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 2920c6ec5..9145899d0 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -233,9 +233,12 @@ "room_two_users_are_typing" = "%@ & %@ are typing…"; "room_many_users_are_typing" = "%@, %@ & others are typing…"; "room_message_placeholder" = "Send a message (unencrypted)…"; +"room_message_reply_to_placeholder" = "Send a reply (unencrypted)…"; "room_do_not_have_permission_to_post" = "You do not have permission to post to this room"; "encrypted_room_message_placeholder" = "Send an encrypted message…"; +"encrypted_room_message_reply_to_placeholder" = "Send an encrypted reply…"; "room_message_short_placeholder" = "Send a message…"; +"room_message_reply_to_short_placeholder" = "Send a reply…"; "room_offline_notification" = "Connectivity to the server has been lost."; "room_unsent_messages_notification" = "Messages not sent. %@ or %@ now?"; "room_unsent_messages_unknown_devices_notification" = "Message not sent due to unknown devices being present. %@ or %@ now?"; From f81ba368800e1f3e741233563db23ce1de338f1e Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Mon, 23 Jul 2018 16:54:23 +0200 Subject: [PATCH 2/7] Add send reply mode in RoomInputToolbarView in order to update text input placeholder when sending a reply. --- .../Views/InputToolbar/RoomInputToolbarView.h | 5 +++ .../Views/InputToolbar/RoomInputToolbarView.m | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.h b/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.h index ccf18e143..20c66fcaf 100644 --- a/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.h +++ b/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.h @@ -69,6 +69,11 @@ */ @property (nonatomic) BOOL isEncryptionEnabled; +/** + Tell whether the input text will be a reply to a message. + */ +@property (nonatomic, getter=isReplyToEnabled) BOOL replyToEnabled; + /** Tell whether a call is active. */ diff --git a/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m b/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m index 47c243199..032e827be 100644 --- a/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m +++ b/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m @@ -153,6 +153,41 @@ self.placeholder = placeholder; } +- (void)setReplyToEnabled:(BOOL)isReplyToEnabled +{ + _replyToEnabled = isReplyToEnabled; + + [self updatePlaceholder]; +} + +- (void)updatePlaceholder +{ + // Consider the default placeholder + + NSString *placeholder; + + // Check the device screen size before using large placeholder + BOOL shouldDisplayLargePlaceholder = [GBDeviceInfo deviceInfo].family == GBDeviceFamilyiPad || [GBDeviceInfo deviceInfo].displayInfo.display >= GBDeviceDisplay4p7Inch; + + if (shouldDisplayLargePlaceholder) + { + placeholder = _replyToEnabled ? NSLocalizedStringFromTable(@"room_message_reply_to_short_placeholder", @"Vector", nil) : NSLocalizedStringFromTable(@"room_message_short_placeholder", @"Vector", nil); + } + else + { + if (_isEncryptionEnabled) + { + placeholder = _replyToEnabled ? NSLocalizedStringFromTable(@"encrypted_room_message_reply_to_placeholder", @"Vector", nil) : NSLocalizedStringFromTable(@"encrypted_room_message_placeholder", @"Vector", nil); + } + else + { + placeholder = _replyToEnabled ? NSLocalizedStringFromTable(@"room_message_reply_to_placeholder", @"Vector", nil) : NSLocalizedStringFromTable(@"room_message_placeholder", @"Vector", nil); + } + } + + self.placeholder = placeholder; +} + - (void)setActiveCall:(BOOL)activeCall { if (_activeCall != activeCall) From 42fffae6defb0526c6ac975a113e04c147cd2410 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Mon, 23 Jul 2018 16:56:03 +0200 Subject: [PATCH 3/7] [RoomViewController] Handle sending a reply by highlighting a message on timeline for supported events. --- Riot/Modules/Room/RoomViewController.m | 51 ++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 5f7e72ec0..716d57b5e 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -200,6 +200,8 @@ // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. id kRiotDesignValuesDidChangeThemeNotificationObserver; + + BOOL isInReplyMode; } @end @@ -1074,6 +1076,28 @@ } } +- (void)sendTextMessage:(NSString*)msgTxt +{ + if (isInReplyMode && customizedRoomDataSource.selectedEventId) + { + [self.roomDataSource sendReplyToEventWithId:customizedRoomDataSource.selectedEventId withTextMessage:msgTxt success:nil failure:^(NSError *error) { + // Just log the error. The message will be displayed in red in the room history + NSLog(@"[MXKRoomViewController] sendTextMessage failed."); + }]; + } + else + { + // Let the datasource send it and manage the local echo + [self.roomDataSource sendTextMessage:msgTxt success:nil failure:^(NSError *error) + { + // Just log the error. The message will be displayed in red in the room history + NSLog(@"[MXKRoomViewController] sendTextMessage failed."); + }]; + } + + [self cancelEventSelection]; +} + - (void)destroy { rightBarButtonItems = nil; @@ -1391,6 +1415,13 @@ } } +- (void)enableReplyMode:(BOOL)enable +{ + isInReplyMode = enable; + RoomInputToolbarView *roomInputToolbarView = (RoomInputToolbarView*)self.inputToolbarView; + roomInputToolbarView.replyToEnabled = enable; +} + - (void)onSwipeGesture:(UISwipeGestureRecognizer*)swipeGestureRecognizer { UIView *view = swipeGestureRecognizer.view; @@ -1922,7 +1953,7 @@ else if (tappedEvent) { // Highlight this event in displayed message - customizedRoomDataSource.selectedEventId = tappedEvent.eventId; + [self selectEventWithId:tappedEvent.eventId]; } // Force table refresh @@ -1965,7 +1996,7 @@ else { // Highlight this event in displayed message - customizedRoomDataSource.selectedEventId = ((MXKRoomBubbleTableViewCell*)cell).bubbleData.attachment.eventId; + [self selectEventWithId:((MXKRoomBubbleTableViewCell*)cell).bubbleData.attachment.eventId]; } // Force table refresh @@ -2717,8 +2748,19 @@ return shouldDoAction; } +- (void)selectEventWithId:(NSString*)eventId +{ + BOOL shouldEnableReplyMode = [self.roomDataSource canReplyToEventWithId:eventId];; + + [self enableReplyMode:shouldEnableReplyMode]; + + customizedRoomDataSource.selectedEventId = eventId; +} + - (void)cancelEventSelection { + [self enableReplyMode:NO]; + if (currentAlert) { [currentAlert dismissViewControllerAnimated:NO completion:nil]; @@ -2966,9 +3008,10 @@ - (void)roomInputToolbarView:(MXKRoomInputToolbarView*)toolbarView isTyping:(BOOL)typing { [super roomInputToolbarView:toolbarView isTyping:typing]; - + // Cancel potential selected event (to leave edition mode) - if (typing && customizedRoomDataSource.selectedEventId) + NSString *selectedEventId = customizedRoomDataSource.selectedEventId; + if (typing && selectedEventId && ![self.roomDataSource canReplyToEventWithId:selectedEventId]) { [self cancelEventSelection]; } From e2962bece0130c8edcaca2f417c489b16692fdaf Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Mon, 23 Jul 2018 18:48:23 +0200 Subject: [PATCH 4/7] Add send reply to changes --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 8e5d79ff8..bfcd34f25 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ Changes in 0.6.21 () Improvements: * Update project structure. Organize UI related files by feature (PR#1932). * Move image files to xcassets (PR#1932). +* Replies: Implement sending (#1911). Changes in 0.6.20 (2018-07-13) =============================================== From f6469b3958de655780981afdf8b0587875c35f2a Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Tue, 24 Jul 2018 12:24:12 +0200 Subject: [PATCH 5/7] Update join slash command constant in RoomViewController from MXKSlashCommands --- Riot/Modules/Room/RoomViewController.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 716d57b5e..e4a7c5772 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -118,6 +118,7 @@ #import "StickerPickerViewController.h" #import "EventFormatter.h" +#import "MXKSlashCommands.h" #import "Riot-Swift.h" @@ -201,6 +202,7 @@ // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. id kRiotDesignValuesDidChangeThemeNotificationObserver; + // Tell whether the input text field is in send reply mode. If true typed message will be sent to highlighted event. BOOL isInReplyMode; } @@ -986,15 +988,15 @@ { // Override the default behavior for `/join` command in order to open automatically the joined room - if ([string hasPrefix:kCmdJoinRoom]) + if ([string hasPrefix:kMXKSlashCmdJoinRoom]) { // Join a room NSString *roomAlias; // Sanity check - if (string.length > kCmdJoinRoom.length) + if (string.length > kMXKSlashCmdJoinRoom.length) { - roomAlias = [string substringFromIndex:kCmdJoinRoom.length + 1]; + roomAlias = [string substringFromIndex:kMXKSlashCmdJoinRoom.length + 1]; // Remove white space from both ends roomAlias = [roomAlias stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; From f53d554d528b57e55417a8a99d2138cbde6b276d Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Tue, 24 Jul 2018 13:31:37 +0200 Subject: [PATCH 6/7] Fix MXKSlashCommands import from RoomViewController --- Riot/Modules/Room/RoomViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index e4a7c5772..7d2f4cb9f 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -118,7 +118,7 @@ #import "StickerPickerViewController.h" #import "EventFormatter.h" -#import "MXKSlashCommands.h" +#import #import "Riot-Swift.h" From d22e04cc8eef3fecd662716e5a135763b2b6838f Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Tue, 24 Jul 2018 13:32:40 +0200 Subject: [PATCH 7/7] Fix boolean condition when updating placholder in RoomInputToolbarView --- Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m b/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m index 032e827be..feae0f022 100644 --- a/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m +++ b/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m @@ -169,7 +169,7 @@ // Check the device screen size before using large placeholder BOOL shouldDisplayLargePlaceholder = [GBDeviceInfo deviceInfo].family == GBDeviceFamilyiPad || [GBDeviceInfo deviceInfo].displayInfo.display >= GBDeviceDisplay4p7Inch; - if (shouldDisplayLargePlaceholder) + if (!shouldDisplayLargePlaceholder) { placeholder = _replyToEnabled ? NSLocalizedStringFromTable(@"room_message_reply_to_short_placeholder", @"Vector", nil) : NSLocalizedStringFromTable(@"room_message_short_placeholder", @"Vector", nil); }