Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slash commands suggestion list #7514

Merged
merged 15 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,21 @@ Tap the + to start adding people.";
"room_join_group_call" = "Join";
"room_no_privileges_to_create_group_call" = "You need to be an admin or a moderator to start a call.";

// Room commands descriptions
"room_command_change_display_name_description" = "Changes your display nickname";
"room_command_emote_description" = "Displays action";
"room_command_join_room_description" = "Joins room with given address";
"room_command_part_room_description" = "Leave room";
"room_command_invite_user_description" = "Invites user with given id to current room";
"room_command_kick_user_description" = "Removes user with given id from this room";
"room_command_ban_user_description" = "Bans user with given id";
"room_command_unban_user_description" = "Unbans user with given id";
"room_command_set_user_power_level_description" = "Define the power level of a user";
"room_command_reset_user_power_level_description" = "Deops user with given id";
"room_command_change_room_topic_description" = "Sets the room topic";
"room_command_discard_session_description" = "Forces the current outbound group session in an encrypted room to be discarded";
"room_command_error_unknown_command" = "Invalid or unhandled command";

// MARK: Threads
"room_thread_title" = "Thread";
"thread_copy_link_to_thread" = "Copy link to thread";
Expand Down
52 changes: 52 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5211,6 +5211,58 @@ public class VectorL10n: NSObject {
public static var roomAvatarViewAccessibilityLabel: String {
return VectorL10n.tr("Vector", "room_avatar_view_accessibility_label")
}
/// Bans user with given id
public static var roomCommandBanUserDescription: String {
return VectorL10n.tr("Vector", "room_command_ban_user_description")
}
/// Changes your display nickname
public static var roomCommandChangeDisplayNameDescription: String {
return VectorL10n.tr("Vector", "room_command_change_display_name_description")
}
/// Sets the room topic
public static var roomCommandChangeRoomTopicDescription: String {
return VectorL10n.tr("Vector", "room_command_change_room_topic_description")
}
/// Forces the current outbound group session in an encrypted room to be discarded
public static var roomCommandDiscardSessionDescription: String {
return VectorL10n.tr("Vector", "room_command_discard_session_description")
}
/// Displays action
public static var roomCommandEmoteDescription: String {
return VectorL10n.tr("Vector", "room_command_emote_description")
}
/// Invalid or unhandled command
public static var roomCommandErrorUnknownCommand: String {
return VectorL10n.tr("Vector", "room_command_error_unknown_command")
}
/// Invites user with given id to current room
public static var roomCommandInviteUserDescription: String {
return VectorL10n.tr("Vector", "room_command_invite_user_description")
}
/// Joins room with given address
public static var roomCommandJoinRoomDescription: String {
return VectorL10n.tr("Vector", "room_command_join_room_description")
}
/// Removes user with given id from this room
public static var roomCommandKickUserDescription: String {
return VectorL10n.tr("Vector", "room_command_kick_user_description")
}
/// Leave room
public static var roomCommandPartRoomDescription: String {
return VectorL10n.tr("Vector", "room_command_part_room_description")
}
/// Deops user with given id
public static var roomCommandResetUserPowerLevelDescription: String {
return VectorL10n.tr("Vector", "room_command_reset_user_power_level_description")
}
/// Define the power level of a user
public static var roomCommandSetUserPowerLevelDescription: String {
return VectorL10n.tr("Vector", "room_command_set_user_power_level_description")
}
/// Unbans user with given id
public static var roomCommandUnbanUserDescription: String {
return VectorL10n.tr("Vector", "room_command_unban_user_description")
}
/// You need permission to manage conference call in this room
public static var roomConferenceCallNoPower: String {
return VectorL10n.tr("Vector", "room_conference_call_no_power")
Expand Down
2 changes: 0 additions & 2 deletions Riot/Modules/MatrixKit/MatrixKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,3 @@

#import "MXKCountryPickerViewController.h"
#import "MXKLanguagePickerViewController.h"

#import "MXKSlashCommands.h"
4 changes: 1 addition & 3 deletions Riot/Modules/MatrixKit/Models/Room/MXKRoomDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

#import "MXKAppSettings.h"

#import "MXKSlashCommands.h"

#import "GeneratedInterface-Swift.h"

const BOOL USE_THREAD_TIMELINE = YES;
Expand Down Expand Up @@ -316,7 +314,7 @@ - (instancetype)initWithRoomId:(NSString *)roomId andMatrixSession:(MXSession *)

_filterMessagesWithURL = NO;

emoteMessageSlashCommandPrefix = [NSString stringWithFormat:@"%@ ", kMXKSlashCmdEmote];
emoteMessageSlashCommandPrefix = [NSString stringWithFormat:@"%@ ", [MXKSlashCommandsHelper commandNameFor:MXKSlashCommandEmote]];

// Set default data and view classes
// Cell data
Expand Down
34 changes: 0 additions & 34 deletions Riot/Modules/MatrixKit/Models/Room/MXKSlashCommands.h

This file was deleted.

30 changes: 0 additions & 30 deletions Riot/Modules/MatrixKit/Models/Room/MXKSlashCommands.m

This file was deleted.

101 changes: 101 additions & 0 deletions Riot/Modules/MatrixKit/Models/Room/MXKSlashCommands.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//
// Copyright 2023 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

@objc final class MXKSlashCommandsHelper: NSObject {
@objc static func commandNameFor(_ slashCommand: MXKSlashCommand) -> String {
slashCommand.cmd
}

@objc static func commandUsageFor(_ slashCommand: MXKSlashCommand) -> String {
"Usage: \(slashCommand.cmd) \(slashCommand.parametersFormat)"
}
}

@objc enum MXKSlashCommand: Int, CaseIterable {
case changeDisplayName
case emote
case joinRoom
case partRoom
case inviteUser
case kickUser
case banUser
case unbanUser
case setUserPowerLevel
case resetUserPowerLevel
case changeRoomTopic
case discardSession

var cmd: String {
switch self {
case .changeDisplayName:
return "/nick"
case .emote:
return "/me"
case .joinRoom:
return "/join"
case .partRoom:
return "/part"
case .inviteUser:
return "/invite"
case .kickUser:
return "/kick"
case .banUser:
return "/ban"
case .unbanUser:
return "/unban"
case .setUserPowerLevel:
return "/op"
case .resetUserPowerLevel:
return "/deop"
case .changeRoomTopic:
return "/topic"
case .discardSession:
return "/discardsession"
}
}

// Note: not localized for consistency, as commands are in english
// also translating these parameters could lead to inconsistency in
// the UI in case of languages with overlength translation.
var parametersFormat: String {
switch self {
case .changeDisplayName:
return "<display_name>"
case .emote:
return "<message>"
case .joinRoom:
return "<room-address>"
case .partRoom:
return "[<room-address>]"
case .inviteUser:
return "<user-id>"
case .kickUser:
return "<user-id> [<reason>]"
case .banUser:
return "<user-id> [<reason>]"
case .unbanUser:
return "<user-id>"
case .setUserPowerLevel:
return "<user-id> <power-level>"
case .resetUserPowerLevel:
return "<user-id>"
case .changeRoomTopic:
return "<topic>"
case .discardSession:
return ""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ typedef enum : NSUInteger
*/
- (void)roomInputToolbarView:(MXKRoomInputToolbarView *)toolbarView sendFormattedTextMessage:(NSString *)formattedTextMessage withRawText:(NSString *)rawText;

/**
Tells the delegate that the user wants to send a command.

@param toolbarView the room input toolbar view.
@param commandText the command to send.
*/
- (void)roomInputToolbarView:(MXKRoomInputToolbarView *)toolbarView sendCommand:(NSString *)commandText;

/**
Tells the delegate that the user wants to display the send media actions.

Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Room/DataSources/RoomDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
extension RoomDataSource {
// MARK: - Private Constants
private enum Constants {
static let emoteMessageSlashCommandPrefix = String(format: "%@ ", kMXKSlashCmdEmote)
static let emoteMessageSlashCommandPrefix = String(format: "%@ ", MXKSlashCommand.emote.cmd)
}

// MARK: - NSAttributedString Sending
Expand Down
Loading