Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Replies: Implement sending #452

Merged
merged 7 commits into from
Jul 24, 2018
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Changes in MatrixKit in 0.7.16 ()
==========================================

Improvements:
* MXKRoomDataSource: Add send reply with text message (vector-im/riot-ios#1911).


Changes in MatrixKit in 0.7.15 (2018-07-03)
==========================================

Expand Down
12 changes: 12 additions & 0 deletions MatrixKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
B12C470C20BECAF8004FBF96 /* MXKErrorViewModel.m in Sources */ = {isa = PBXBuildFile; fileRef = B12C470920BECAF7004FBF96 /* MXKErrorViewModel.m */; };
B12C470D20BECAF8004FBF96 /* MXKErrorAlertPresentation.m in Sources */ = {isa = PBXBuildFile; fileRef = B12C470A20BECAF7004FBF96 /* MXKErrorAlertPresentation.m */; };
B12C471020BED312004FBF96 /* MXKErrorPresentableBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = B12C470F20BED312004FBF96 /* MXKErrorPresentableBuilder.m */; };
B164380C210603CD00DBB3FD /* MXKSendReplyEventStringLocalizations.m in Sources */ = {isa = PBXBuildFile; fileRef = B164380B210603CD00DBB3FD /* MXKSendReplyEventStringLocalizations.m */; };
B1668AC021072F93002B14F1 /* MXKSlashCommands.m in Sources */ = {isa = PBXBuildFile; fileRef = B1668ABF21072F93002B14F1 /* MXKSlashCommands.m */; };
CE14CA661E80122600E329A3 /* MXKAttachmentAnimator.m in Sources */ = {isa = PBXBuildFile; fileRef = CE14CA631E80122600E329A3 /* MXKAttachmentAnimator.m */; };
CE14CA671E80122600E329A3 /* MXKAttachmentInteractionController.m in Sources */ = {isa = PBXBuildFile; fileRef = CE14CA651E80122600E329A3 /* MXKAttachmentInteractionController.m */; };
F0026B661C91EED1001D2C04 /* MXKWebViewViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F0026B651C91EED1001D2C04 /* MXKWebViewViewController.m */; };
Expand Down Expand Up @@ -331,6 +333,10 @@
B12C470B20BECAF7004FBF96 /* MXKErrorPresentable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXKErrorPresentable.h; sourceTree = "<group>"; };
B12C470E20BED312004FBF96 /* MXKErrorPresentableBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXKErrorPresentableBuilder.h; sourceTree = "<group>"; };
B12C470F20BED312004FBF96 /* MXKErrorPresentableBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXKErrorPresentableBuilder.m; sourceTree = "<group>"; };
B164380A210603CD00DBB3FD /* MXKSendReplyEventStringLocalizations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXKSendReplyEventStringLocalizations.h; sourceTree = "<group>"; };
B164380B210603CD00DBB3FD /* MXKSendReplyEventStringLocalizations.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXKSendReplyEventStringLocalizations.m; sourceTree = "<group>"; };
B1668ABE21072F93002B14F1 /* MXKSlashCommands.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXKSlashCommands.h; sourceTree = "<group>"; };
B1668ABF21072F93002B14F1 /* MXKSlashCommands.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXKSlashCommands.m; sourceTree = "<group>"; };
BFDF88630F521F8C5854F64F /* Pods-MatrixKitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MatrixKitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-MatrixKitTests/Pods-MatrixKitTests.debug.xcconfig"; sourceTree = "<group>"; };
C1C97E32A7F1D6C4B99A47EF /* Pods-MatrixKitSample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MatrixKitSample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-MatrixKitSample/Pods-MatrixKitSample.debug.xcconfig"; sourceTree = "<group>"; };
CE14CA621E80122600E329A3 /* MXKAttachmentAnimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXKAttachmentAnimator.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1148,6 +1154,10 @@
F07E180C1ABC2EDA00DE3766 /* MXKRoomDataSource.m */,
3230A3731ACADC1800CC57F5 /* MXKRoomDataSourceManager.h */,
3230A3741ACADC1800CC57F5 /* MXKRoomDataSourceManager.m */,
B164380A210603CD00DBB3FD /* MXKSendReplyEventStringLocalizations.h */,
B164380B210603CD00DBB3FD /* MXKSendReplyEventStringLocalizations.m */,
B1668ABE21072F93002B14F1 /* MXKSlashCommands.h */,
B1668ABF21072F93002B14F1 /* MXKSlashCommands.m */,
);
path = Room;
sourceTree = "<group>";
Expand Down Expand Up @@ -1669,6 +1679,7 @@
F04356321B2EF6FD0096FA02 /* MXKRoomMemberDetailsViewController.m in Sources */,
F095E5101B25899F009606CE /* MXKEmail.m in Sources */,
321313C91AEFC2D500A9B035 /* MXKRoomIOSOutgoingBubbleTableViewCell.m in Sources */,
B164380C210603CD00DBB3FD /* MXKSendReplyEventStringLocalizations.m in Sources */,
F0FDF2671E53586A00D23C47 /* MXKCountryPickerViewController.m in Sources */,
B12C471020BED312004FBF96 /* MXKErrorPresentableBuilder.m in Sources */,
F00FA85C1C0867F900E25826 /* MXKRoomIncomingAttachmentBubbleCell.m in Sources */,
Expand Down Expand Up @@ -1771,6 +1782,7 @@
F02528961C1092D300E1FE1B /* MXKCollectionViewCell.m in Sources */,
F0F148A61AB08F48005F5D4A /* MXKSampleJSQRoomDataSource.m in Sources */,
F096A3BF1B0B3DAA00AF1357 /* MXKAccountDetailsViewController.m in Sources */,
B1668AC021072F93002B14F1 /* MXKSlashCommands.m in Sources */,
F0CF98FD1B0CDF6100EAE373 /* MXKTableViewCellWithButton.m in Sources */,
F095E50D1B25899F009606CE /* MXKContact.m in Sources */,
F0F148A51AB08F48005F5D4A /* MXKSampleJSQRoomBubbleCellData.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@
"room_no_power_to_create_conference_call" = "You need permission to invite to start a conference in this room";
"room_no_conference_call_in_encrypted_rooms" = "Conference calls are not supported in encrypted rooms";

// Reply to message
"message_reply_to_sender_sent_an_image" = "sent an image.";
"message_reply_to_sender_sent_a_video" = "sent a video.";
"message_reply_to_sender_sent_an_audio_file" = "sent an audio file.";
"message_reply_to_sender_sent_a_file" = "sent a file.";
"message_reply_to_message_to_reply_to_prefix" = "In reply to";

// Room members
"room_member_ignore_prompt" = "Are you sure you want to hide all messages from this user?";
"room_member_power_level_prompt" = "You will not be able to undo this change as you are promoting the user to have the same power level as yourself.\nAre you sure?";
Expand Down
12 changes: 0 additions & 12 deletions MatrixKit/Controllers/MXKRoomViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ limitations under the License.
#import "MXKAttachmentsViewController.h"
#import "MXKAttachmentAnimator.h"

extern NSString *const kCmdChangeDisplayName;
extern NSString *const kCmdEmote;
extern NSString *const kCmdJoinRoom;
extern NSString *const kCmdPartRoom;
extern NSString *const kCmdInviteUser;
extern NSString *const kCmdKickUser;
extern NSString *const kCmdBanUser;
extern NSString *const kCmdUnbanUser;
extern NSString *const kCmdSetUserPowerLevel;
extern NSString *const kCmdResetUserPowerLevel;
extern NSString *const kCmdChangeRoomTopic;

/**
This view controller displays messages of a room. Only one matrix session is handled by this view controller.
*/
Expand Down
51 changes: 20 additions & 31 deletions MatrixKit/Controllers/MXKRoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,7 @@

#import "NSBundle+MatrixKit.h"
#import "UIScrollView+MatrixKit.h"

NSString *const kCmdChangeDisplayName = @"/nick";
NSString *const kCmdEmote = @"/me";
NSString *const kCmdJoinRoom = @"/join";
NSString *const kCmdPartRoom = @"/part";
NSString *const kCmdInviteUser = @"/invite";
NSString *const kCmdKickUser = @"/kick";
NSString *const kCmdBanUser = @"/ban";
NSString *const kCmdUnbanUser = @"/unban";
NSString *const kCmdSetUserPowerLevel = @"/op";
NSString *const kCmdResetUserPowerLevel = @"/deop";
NSString *const kCmdChangeRoomTopic = @"/topic";
#import "MXKSlashCommands.h"

@interface MXKRoomViewController ()
{
Expand Down Expand Up @@ -1313,20 +1302,20 @@ - (BOOL)isIRCStyleCommand:(NSString*)string
// TODO: display an alert with the cmd usage in case of error or unrecognized cmd.
NSString *cmdUsage;

if ([cmd isEqualToString:kCmdEmote])
if ([cmd isEqualToString:kMXKSlashCmdEmote])
{
// send message as an emote
[self sendTextMessage:string];
}
else if ([string hasPrefix:kCmdChangeDisplayName])
else if ([string hasPrefix:kMXKSlashCmdChangeDisplayName])
{
// Change display name
NSString *displayName;

// Sanity check
if (string.length > kCmdChangeDisplayName.length)
if (string.length > kMXKSlashCmdChangeDisplayName.length)
{
displayName = [string substringFromIndex:kCmdChangeDisplayName.length + 1];
displayName = [string substringFromIndex:kMXKSlashCmdChangeDisplayName.length + 1];

// Remove white space from both ends
displayName = [displayName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
Expand All @@ -1351,15 +1340,15 @@ - (BOOL)isIRCStyleCommand:(NSString*)string
cmdUsage = @"Usage: /nick <display_name>";
}
}
else if ([string hasPrefix:kCmdJoinRoom])
else 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 All @@ -1385,16 +1374,16 @@ - (BOOL)isIRCStyleCommand:(NSString*)string
cmdUsage = @"Usage: /join <room_alias>";
}
}
else if ([string hasPrefix:kCmdPartRoom])
else if ([string hasPrefix:kMXKSlashCmdPartRoom])
{
// Leave this room or another one
NSString *roomId;
NSString *roomIdOrAlias;

// Sanity check
if (string.length > kCmdPartRoom.length)
if (string.length > kMXKSlashCmdPartRoom.length)
{
roomIdOrAlias = [string substringFromIndex:kCmdPartRoom.length + 1];
roomIdOrAlias = [string substringFromIndex:kMXKSlashCmdPartRoom.length + 1];

// Remove white space from both ends
roomIdOrAlias = [roomIdOrAlias stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
Expand Down Expand Up @@ -1443,15 +1432,15 @@ - (BOOL)isIRCStyleCommand:(NSString*)string
cmdUsage = @"Usage: /part [<room_alias>]";
}
}
else if ([string hasPrefix:kCmdChangeRoomTopic])
else if ([string hasPrefix:kMXKSlashCmdChangeRoomTopic])
{
// Change topic
NSString *topic;

// Sanity check
if (string.length > kCmdChangeRoomTopic.length)
if (string.length > kMXKSlashCmdChangeRoomTopic.length)
{
topic = [string substringFromIndex:kCmdChangeRoomTopic.length + 1];
topic = [string substringFromIndex:kMXKSlashCmdChangeRoomTopic.length + 1];
// Remove white space from both ends
topic = [topic stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
}
Expand Down Expand Up @@ -1491,7 +1480,7 @@ - (BOOL)isIRCStyleCommand:(NSString*)string
userId = nil;
}

if ([cmd isEqualToString:kCmdInviteUser])
if ([cmd isEqualToString:kMXKSlashCmdInviteUser])
{
if (userId)
{
Expand All @@ -1513,7 +1502,7 @@ - (BOOL)isIRCStyleCommand:(NSString*)string
cmdUsage = @"Usage: /invite <userId>";
}
}
else if ([cmd isEqualToString:kCmdKickUser])
else if ([cmd isEqualToString:kMXKSlashCmdKickUser])
{
if (userId)
{
Expand Down Expand Up @@ -1548,7 +1537,7 @@ - (BOOL)isIRCStyleCommand:(NSString*)string
cmdUsage = @"Usage: /kick <userId> [<reason>]";
}
}
else if ([cmd isEqualToString:kCmdBanUser])
else if ([cmd isEqualToString:kMXKSlashCmdBanUser])
{
if (userId)
{
Expand Down Expand Up @@ -1583,7 +1572,7 @@ - (BOOL)isIRCStyleCommand:(NSString*)string
cmdUsage = @"Usage: /ban <userId> [<reason>]";
}
}
else if ([cmd isEqualToString:kCmdUnbanUser])
else if ([cmd isEqualToString:kMXKSlashCmdUnbanUser])
{
if (userId)
{
Expand All @@ -1605,7 +1594,7 @@ - (BOOL)isIRCStyleCommand:(NSString*)string
cmdUsage = @"Usage: /unban <userId>";
}
}
else if ([cmd isEqualToString:kCmdSetUserPowerLevel])
else if ([cmd isEqualToString:kMXKSlashCmdSetUserPowerLevel])
{
// Retrieve power level
NSString *powerLevel = nil;
Expand Down Expand Up @@ -1641,7 +1630,7 @@ - (BOOL)isIRCStyleCommand:(NSString*)string
cmdUsage = @"Usage: /op <userId> <power level>";
}
}
else if ([cmd isEqualToString:kCmdResetUserPowerLevel])
else if ([cmd isEqualToString:kMXKSlashCmdResetUserPowerLevel])
{
if (userId)
{
Expand Down
19 changes: 19 additions & 0 deletions MatrixKit/Models/Room/MXKRoomDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,25 @@ extern NSString *const kMXKRoomDataSourceTimelineErrorErrorKey;
success:(void (^)(NSString *eventId))success
failure:(void (^)(NSError *error))failure;

/**
Send a reply to an event with text message to the room.

While sending, a fake event will be echoed in the messages list.
Once complete, this local echo will be replaced by the event saved by the homeserver.

@param eventIdToReply the id of event to reply.
@param text the text to send.
@param success A block object called when the operation succeeds. It returns
the event id of the event generated on the home server
@param failure A block object called when the operation fails.
*/
- (void)sendReplyToEventWithId:(NSString*)eventIdToReply
withTextMessage:(NSString *)text
success:(void (^)(NSString *))success
failure:(void (^)(NSError *))failure;

- (BOOL)canReplyToEventWithId:(NSString*)eventIdToReply;

/**
Send an image to the room.

Expand Down