From d9051766d9984f6bd0650b31577065e3e9b3f2c5 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Mon, 5 Jul 2021 23:53:46 -0500 Subject: [PATCH] Reloading of protocol's commands on request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes a protocol's commands are dynamic, or change based on certain events― and it's necessary in these cases that commands be reloaded. The IM_PROTOCOL_RELOAD_COMMANDS message is now added to the API, which will force Cardie to reload commands from the protocol. --- application/ChatProtocolMessages.h | 11 +++++++++++ application/ProtocolLooper.cpp | 5 +++-- application/ProtocolLooper.h | 4 ++-- application/Server.cpp | 10 ++++++++-- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/application/ChatProtocolMessages.h b/application/ChatProtocolMessages.h index 9e8e8a8..4e2e2ac 100644 --- a/application/ChatProtocolMessages.h +++ b/application/ChatProtocolMessages.h @@ -387,6 +387,17 @@ enum im_what_code { IM_ROOM_UNDEAFEN_PARTICIPANT = 199, + /* + * Misc. UI messages + */ + + /*! Reload commands from proto →App + If a protocol's command-list is dynamic (i.e., determined by its own + add-ons and preferences), it makes sense to relaod commands from time + to time. This forces that. */ + IM_PROTOCOL_RELOAD_COMMANDS = 900, + + /* * Special messages */ diff --git a/application/ProtocolLooper.cpp b/application/ProtocolLooper.cpp index 8acbb58..c995715 100644 --- a/application/ProtocolLooper.cpp +++ b/application/ProtocolLooper.cpp @@ -29,7 +29,7 @@ ProtocolLooper::ProtocolLooper(ChatProtocol* protocol, int64 instance) Account* account = reinterpret_cast( protocol->MessengerInterface()); - _InitCommands(); + LoadCommands(); BString name(protocol->FriendlySignature()); name << " - " << account->Name(); @@ -199,8 +199,9 @@ ProtocolLooper::GetListItem() void -ProtocolLooper::_InitCommands() +ProtocolLooper::LoadCommands() { + fCommands = CommandMap(); BObjectList commands = fProtocol->Commands(); for (int i = 0; i < commands.CountItems(); i++) { ChatCommand* cmd = new ChatCommand(commands.ItemAt(i)); diff --git a/application/ProtocolLooper.h b/application/ProtocolLooper.h index bd66bef..a73d029 100644 --- a/application/ProtocolLooper.h +++ b/application/ProtocolLooper.h @@ -61,9 +61,9 @@ public: ConversationAccountItem* GetListItem(); -private: - void _InitCommands(); + void LoadCommands(); +private: ChatProtocol* fProtocol; int64 fInstance; diff --git a/application/Server.cpp b/application/Server.cpp index b9b5a4f..8a01b74 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -568,12 +568,18 @@ Server::ImMessage(BMessage* msg) break; } + case IM_PROTOCOL_RELOAD_COMMANDS: + { + ProtocolLooper* looper = _LooperFromMessage(msg); + if (looper == NULL) break; + looper->LoadCommands(); + break; + } case IM_PROTOCOL_READY: { // Ready notification ProtocolLooper* looper = _LooperFromMessage(msg); - if (looper == NULL) - break; + if (looper == NULL) break; ChatProtocol* proto = looper->Protocol(); BString content("%user% has connected!");