aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libdino/src/plugin/registry.vala9
-rw-r--r--main/src/ui/chat_input/view.vala34
2 files changed, 34 insertions, 9 deletions
diff --git a/libdino/src/plugin/registry.vala b/libdino/src/plugin/registry.vala
index 01d18d5f..6284269b 100644
--- a/libdino/src/plugin/registry.vala
+++ b/libdino/src/plugin/registry.vala
@@ -6,6 +6,7 @@ public class Registry {
internal ArrayList<EncryptionListEntry> encryption_list_entries = new ArrayList<EncryptionListEntry>();
internal ArrayList<AccountSettingsEntry> account_settings_entries = new ArrayList<AccountSettingsEntry>();
internal ArrayList<ContactDetailsProvider> contact_details_entries = new ArrayList<ContactDetailsProvider>();
+ internal Map<string, TextCommand> text_commands = new HashMap<string, TextCommand>();
internal Gee.Collection<ConversationTitlebarEntry> conversation_titlebar_entries = new Gee.TreeSet<ConversationTitlebarEntry>((a, b) => {
if (a.order < b.order) {
return -1;
@@ -49,6 +50,14 @@ public class Registry {
}
}
+ public bool register_text_command(TextCommand cmd) {
+ lock(text_commands) {
+ if (text_commands.has_key(cmd.cmd)) return false;
+ text_commands[cmd.cmd] = cmd;
+ return true;
+ }
+ }
+
public bool register_contact_titlebar_entry(ConversationTitlebarEntry entry) {
lock(conversation_titlebar_entries) {
foreach(ConversationTitlebarEntry e in conversation_titlebar_entries) {
diff --git a/main/src/ui/chat_input/view.vala b/main/src/ui/chat_input/view.vala
index d8a31a22..a7c3099c 100644
--- a/main/src/ui/chat_input/view.vala
+++ b/main/src/ui/chat_input/view.vala
@@ -52,30 +52,46 @@ public class View : Box {
private void send_text() {
string text = text_input.buffer.text;
+ text_input.buffer.text = "";
if (text.has_prefix("/")) {
string[] token = text.split(" ", 2);
switch(token[0]) {
- case "/kick":
- stream_interactor.get_module(MucManager.IDENTITY).kick(conversation.account, conversation.counterpart, token[1]);
- break;
case "/me":
- stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(text, conversation);
+ // Just send as is.
+ break;
+ case "/say":
+ if (token.length == 1) return;
+ text = token[1];
break;
+ case "/kick":
+ stream_interactor.get_module(MucManager.IDENTITY).kick(conversation.account, conversation.counterpart, token[1]);
+ return;
case "/nick":
stream_interactor.get_module(MucManager.IDENTITY).change_nick(conversation.account, conversation.counterpart, token[1]);
- break;
+ return;
case "/ping":
Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(conversation.account);
stream.get_module(Xmpp.Xep.Ping.Module.IDENTITY).send_ping(stream, conversation.counterpart.to_string() + "/" + token[1], null);
- break;
+ return;
case "/topic":
stream_interactor.get_module(MucManager.IDENTITY).change_subject(conversation.account, conversation.counterpart, token[1]);
+ return;
+ default:
+ if (token[0].has_prefix("//")) {
+ text = text.substring(1);
+ } else {
+ string cmd_name = token[0].substring(1);
+ Dino.Application app = GLib.Application.get_default() as Dino.Application;
+ if (app != null && app.plugin_registry.text_commands.has_key(cmd_name)) {
+ string? new_text = app.plugin_registry.text_commands[cmd_name].handle_command(token[1], conversation);
+ if (new_text == null) return;
+ text = (!)new_text;
+ }
+ }
break;
}
- } else {
- stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(text, conversation);
}
- text_input.buffer.text = "";
+ stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(text, conversation);
}
private bool on_text_input_key_press(EventKey event) {