Merge pull request #1944 from vector-im/riot_1911

Replies: Implement sending
This commit is contained in:
SBiOSoftWhare 2018-07-24 13:48:18 +02:00 committed by GitHub
commit 77d65684b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 7 deletions

View file

@ -4,6 +4,7 @@ Changes in 0.6.21 ()
Improvements: Improvements:
* Update project structure. Organize UI related files by feature (PR#1932). * Update project structure. Organize UI related files by feature (PR#1932).
* Move image files to xcassets (PR#1932). * Move image files to xcassets (PR#1932).
* Replies: Implement sending (#1911).
Changes in 0.6.20 (2018-07-13) Changes in 0.6.20 (2018-07-13)
=============================================== ===============================================

View file

@ -233,9 +233,12 @@
"room_two_users_are_typing" = "%@ & %@ are typing…"; "room_two_users_are_typing" = "%@ & %@ are typing…";
"room_many_users_are_typing" = "%@, %@ & others are typing…"; "room_many_users_are_typing" = "%@, %@ & others are typing…";
"room_message_placeholder" = "Send a message (unencrypted)…"; "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"; "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_placeholder" = "Send an encrypted message…";
"encrypted_room_message_reply_to_placeholder" = "Send an encrypted reply…";
"room_message_short_placeholder" = "Send a message…"; "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_offline_notification" = "Connectivity to the server has been lost.";
"room_unsent_messages_notification" = "Messages not sent. %@ or %@ now?"; "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?"; "room_unsent_messages_unknown_devices_notification" = "Message not sent due to unknown devices being present. %@ or %@ now?";

View file

@ -118,6 +118,7 @@
#import "StickerPickerViewController.h" #import "StickerPickerViewController.h"
#import "EventFormatter.h" #import "EventFormatter.h"
#import <MatrixKit/MXKSlashCommands.h>
#import "Riot-Swift.h" #import "Riot-Swift.h"
@ -200,6 +201,9 @@
// Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change. // Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change.
id kRiotDesignValuesDidChangeThemeNotificationObserver; 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;
} }
@end @end
@ -984,15 +988,15 @@
{ {
// Override the default behavior for `/join` command in order to open automatically the joined room // 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 // Join a room
NSString *roomAlias; NSString *roomAlias;
// Sanity check // 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 // Remove white space from both ends
roomAlias = [roomAlias stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; roomAlias = [roomAlias stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
@ -1074,6 +1078,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 - (void)destroy
{ {
rightBarButtonItems = nil; rightBarButtonItems = nil;
@ -1391,6 +1417,13 @@
} }
} }
- (void)enableReplyMode:(BOOL)enable
{
isInReplyMode = enable;
RoomInputToolbarView *roomInputToolbarView = (RoomInputToolbarView*)self.inputToolbarView;
roomInputToolbarView.replyToEnabled = enable;
}
- (void)onSwipeGesture:(UISwipeGestureRecognizer*)swipeGestureRecognizer - (void)onSwipeGesture:(UISwipeGestureRecognizer*)swipeGestureRecognizer
{ {
UIView *view = swipeGestureRecognizer.view; UIView *view = swipeGestureRecognizer.view;
@ -1922,7 +1955,7 @@
else if (tappedEvent) else if (tappedEvent)
{ {
// Highlight this event in displayed message // Highlight this event in displayed message
customizedRoomDataSource.selectedEventId = tappedEvent.eventId; [self selectEventWithId:tappedEvent.eventId];
} }
// Force table refresh // Force table refresh
@ -1965,7 +1998,7 @@
else else
{ {
// Highlight this event in displayed message // Highlight this event in displayed message
customizedRoomDataSource.selectedEventId = ((MXKRoomBubbleTableViewCell*)cell).bubbleData.attachment.eventId; [self selectEventWithId:((MXKRoomBubbleTableViewCell*)cell).bubbleData.attachment.eventId];
} }
// Force table refresh // Force table refresh
@ -2717,8 +2750,19 @@
return shouldDoAction; return shouldDoAction;
} }
- (void)selectEventWithId:(NSString*)eventId
{
BOOL shouldEnableReplyMode = [self.roomDataSource canReplyToEventWithId:eventId];;
[self enableReplyMode:shouldEnableReplyMode];
customizedRoomDataSource.selectedEventId = eventId;
}
- (void)cancelEventSelection - (void)cancelEventSelection
{ {
[self enableReplyMode:NO];
if (currentAlert) if (currentAlert)
{ {
[currentAlert dismissViewControllerAnimated:NO completion:nil]; [currentAlert dismissViewControllerAnimated:NO completion:nil];
@ -2968,7 +3012,8 @@
[super roomInputToolbarView:toolbarView isTyping:typing]; [super roomInputToolbarView:toolbarView isTyping:typing];
// Cancel potential selected event (to leave edition mode) // 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]; [self cancelEventSelection];
} }

View file

@ -69,6 +69,11 @@
*/ */
@property (nonatomic) BOOL isEncryptionEnabled; @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. Tell whether a call is active.
*/ */

View file

@ -153,6 +153,41 @@
self.placeholder = placeholder; 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 - (void)setActiveCall:(BOOL)activeCall
{ {
if (_activeCall != activeCall) if (_activeCall != activeCall)