Rework MXKSlashCommands to a more Swift-friendly form and use it in suggestion module

This commit is contained in:
aringenbach
2023-04-20 12:10:03 +02:00
parent 56ad4a03d3
commit 787967a8e4
10 changed files with 185 additions and 115 deletions
+24 -19
View File
@@ -39,7 +39,6 @@
#import "MXKEncryptionKeysImportView.h"
#import "NSBundle+MatrixKit.h"
#import "MXKSlashCommands.h"
#import "MXKSwiftHeader.h"
#import "MXKPreviewViewController.h"
@@ -1284,8 +1283,14 @@ static const CGFloat kCellVisibilityMinimumHeight = 8.0;
// TODO: display an alert with the cmd usage in case of error or unrecognized cmd.
NSString *cmdUsage;
NSString* kMXKSlashCmdChangeDisplayName = [MXKSlashCommandsHelper commandNameFor:MXKSlashCommandChangeDisplayName];
NSString* kMXKSlashCmdJoinRoom = [MXKSlashCommandsHelper commandNameFor:MXKSlashCommandJoinRoom];
NSString* kMXKSlashCmdPartRoom = [MXKSlashCommandsHelper commandNameFor:MXKSlashCommandPartRoom];
NSString* kMXKSlashCmdChangeRoomTopic = [MXKSlashCommandsHelper commandNameFor:MXKSlashCommandChangeRoomTopic];
if ([cmd isEqualToString:kMXKSlashCmdEmote])
if ([cmd isEqualToString:[MXKSlashCommandsHelper commandNameFor:MXKSlashCommandEmote]])
{
// send message as an emote
[self sendTextMessage:string];
@@ -1320,7 +1325,7 @@ static const CGFloat kCellVisibilityMinimumHeight = 8.0;
else
{
// Display cmd usage in text input as placeholder
cmdUsage = @"Usage: /nick <display_name>";
cmdUsage = [MXKSlashCommandsHelper commandUsageFor:MXKSlashCommandChangeDisplayName];
}
}
else if ([string hasPrefix:kMXKSlashCmdJoinRoom])
@@ -1355,7 +1360,7 @@ static const CGFloat kCellVisibilityMinimumHeight = 8.0;
else
{
// Display cmd usage in text input as placeholder
cmdUsage = @"Usage: /join <room_alias>";
cmdUsage = [MXKSlashCommandsHelper commandUsageFor:MXKSlashCommandJoinRoom];
}
}
else if ([string hasPrefix:kMXKSlashCmdPartRoom])
@@ -1413,7 +1418,7 @@ static const CGFloat kCellVisibilityMinimumHeight = 8.0;
else
{
// Display cmd usage in text input as placeholder
cmdUsage = @"Usage: /part [<room_alias>]";
cmdUsage = [MXKSlashCommandsHelper commandUsageFor:MXKSlashCommandPartRoom];
}
}
else if ([string hasPrefix:kMXKSlashCmdChangeRoomTopic])
@@ -1445,10 +1450,10 @@ static const CGFloat kCellVisibilityMinimumHeight = 8.0;
else
{
// Display cmd usage in text input as placeholder
cmdUsage = @"Usage: /topic <topic>";
cmdUsage = [MXKSlashCommandsHelper commandUsageFor:MXKSlashCommandChangeRoomTopic];
}
}
else if ([string hasPrefix:kMXKSlashCmdDiscardSession])
else if ([string hasPrefix:[MXKSlashCommandsHelper commandNameFor:MXKSlashCommandDiscardSession]])
{
[roomDataSource.mxSession.crypto discardOutboundGroupSessionForRoomWithRoomId:roomDataSource.roomId onComplete:^{
MXLogDebug(@"[MXKRoomVC] Manually discarded outbound group session");
@@ -1470,7 +1475,7 @@ static const CGFloat kCellVisibilityMinimumHeight = 8.0;
userId = nil;
}
if ([cmd isEqualToString:kMXKSlashCmdInviteUser])
if ([cmd isEqualToString:[MXKSlashCommandsHelper commandNameFor:MXKSlashCommandInviteUser]])
{
if (userId)
{
@@ -1489,10 +1494,10 @@ static const CGFloat kCellVisibilityMinimumHeight = 8.0;
else
{
// Display cmd usage in text input as placeholder
cmdUsage = @"Usage: /invite <userId>";
cmdUsage = [MXKSlashCommandsHelper commandUsageFor:MXKSlashCommandInviteUser];
}
}
else if ([cmd isEqualToString:kMXKSlashCmdKickUser])
else if ([cmd isEqualToString:[MXKSlashCommandsHelper commandNameFor:MXKSlashCommandKickUser]])
{
if (userId)
{
@@ -1524,10 +1529,10 @@ static const CGFloat kCellVisibilityMinimumHeight = 8.0;
else
{
// Display cmd usage in text input as placeholder
cmdUsage = @"Usage: /kick <userId> [<reason>]";
cmdUsage = [MXKSlashCommandsHelper commandUsageFor:MXKSlashCommandKickUser];
}
}
else if ([cmd isEqualToString:kMXKSlashCmdBanUser])
else if ([cmd isEqualToString:[MXKSlashCommandsHelper commandNameFor:MXKSlashCommandBanUser]])
{
if (userId)
{
@@ -1559,10 +1564,10 @@ static const CGFloat kCellVisibilityMinimumHeight = 8.0;
else
{
// Display cmd usage in text input as placeholder
cmdUsage = @"Usage: /ban <userId> [<reason>]";
cmdUsage = [MXKSlashCommandsHelper commandUsageFor:MXKSlashCommandBanUser];
}
}
else if ([cmd isEqualToString:kMXKSlashCmdUnbanUser])
else if ([cmd isEqualToString:[MXKSlashCommandsHelper commandNameFor:MXKSlashCommandUnbanUser]])
{
if (userId)
{
@@ -1581,10 +1586,10 @@ static const CGFloat kCellVisibilityMinimumHeight = 8.0;
else
{
// Display cmd usage in text input as placeholder
cmdUsage = @"Usage: /unban <userId>";
cmdUsage = [MXKSlashCommandsHelper commandUsageFor:MXKSlashCommandUnbanUser];
}
}
else if ([cmd isEqualToString:kMXKSlashCmdSetUserPowerLevel])
else if ([cmd isEqualToString:[MXKSlashCommandsHelper commandNameFor:MXKSlashCommandSetUserPowerLevel]])
{
// Retrieve power level
NSString *powerLevel = nil;
@@ -1617,10 +1622,10 @@ static const CGFloat kCellVisibilityMinimumHeight = 8.0;
else
{
// Display cmd usage in text input as placeholder
cmdUsage = @"Usage: /op <userId> <power level>";
cmdUsage = [MXKSlashCommandsHelper commandUsageFor:MXKSlashCommandSetUserPowerLevel];
}
}
else if ([cmd isEqualToString:kMXKSlashCmdResetUserPowerLevel])
else if ([cmd isEqualToString:[MXKSlashCommandsHelper commandNameFor:MXKSlashCommandResetUserPowerLevel]])
{
if (userId)
{
@@ -1639,7 +1644,7 @@ static const CGFloat kCellVisibilityMinimumHeight = 8.0;
else
{
// Display cmd usage in text input as placeholder
cmdUsage = @"Usage: /deop <userId>";
cmdUsage = [MXKSlashCommandsHelper commandUsageFor:MXKSlashCommandResetUserPowerLevel];
}
}
else