Skip to content

Commit

Permalink
Merge pull request #1944 from vector-im/riot_1911
Browse files Browse the repository at this point in the history
Replies: Implement sending
  • Loading branch information
SBiOSoftWhare authored Jul 24, 2018
2 parents 01182b8 + 3a7a5c9 commit 77d6568
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
===============================================
Expand Down
3 changes: 3 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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?";
Expand Down
59 changes: 52 additions & 7 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
#import "StickerPickerViewController.h"

#import "EventFormatter.h"
#import <MatrixKit/MXKSlashCommands.h>

#import "Riot-Swift.h"

Expand Down Expand Up @@ -200,6 +201,9 @@ @interface RoomViewController ()

// 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;
}

@end
Expand Down Expand Up @@ -984,15 +988,15 @@ - (BOOL)isIRCStyleCommand:(NSString*)string
{
// 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]];
Expand Down Expand Up @@ -1074,6 +1078,28 @@ - (void)setBubbleTableViewDisplayInTransition:(BOOL)bubbleTableViewDisplayInTran
}
}

- (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;
Expand Down Expand Up @@ -1391,6 +1417,13 @@ - (void)refreshRoomInputToolbar
}
}

- (void)enableReplyMode:(BOOL)enable
{
isInReplyMode = enable;
RoomInputToolbarView *roomInputToolbarView = (RoomInputToolbarView*)self.inputToolbarView;
roomInputToolbarView.replyToEnabled = enable;
}

- (void)onSwipeGesture:(UISwipeGestureRecognizer*)swipeGestureRecognizer
{
UIView *view = swipeGestureRecognizer.view;
Expand Down Expand Up @@ -1922,7 +1955,7 @@ - (void)dataSource:(MXKDataSource *)dataSource didRecognizeAction:(NSString *)ac
else if (tappedEvent)
{
// Highlight this event in displayed message
customizedRoomDataSource.selectedEventId = tappedEvent.eventId;
[self selectEventWithId:tappedEvent.eventId];
}

// Force table refresh
Expand Down Expand Up @@ -1965,7 +1998,7 @@ - (void)dataSource:(MXKDataSource *)dataSource didRecognizeAction:(NSString *)ac
else
{
// Highlight this event in displayed message
customizedRoomDataSource.selectedEventId = ((MXKRoomBubbleTableViewCell*)cell).bubbleData.attachment.eventId;
[self selectEventWithId:((MXKRoomBubbleTableViewCell*)cell).bubbleData.attachment.eventId];
}

// Force table refresh
Expand Down Expand Up @@ -2717,8 +2750,19 @@ - (BOOL)dataSource:(MXKDataSource *)dataSource shouldDoAction:(NSString *)action
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];
Expand Down Expand Up @@ -2966,9 +3010,10 @@ - (void)roomInputToolbarViewPresentStickerPicker:(MXKRoomInputToolbarView*)toolb
- (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];
}
Expand Down
5 changes: 5 additions & 0 deletions Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
35 changes: 35 additions & 0 deletions Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,41 @@ - (void)setIsEncryptionEnabled:(BOOL)isEncryptionEnabled
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)
Expand Down

0 comments on commit 77d6568

Please sign in to comment.