Reloading of protocol's commands on request
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.
This commit is contained in:
parent
95da508a38
commit
d9051766d9
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -29,7 +29,7 @@ ProtocolLooper::ProtocolLooper(ChatProtocol* protocol, int64 instance)
|
|||
Account* account = reinterpret_cast<Account*>(
|
||||
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<BMessage> commands = fProtocol->Commands();
|
||||
for (int i = 0; i < commands.CountItems(); i++) {
|
||||
ChatCommand* cmd = new ChatCommand(commands.ItemAt(i));
|
||||
|
|
|
@ -61,9 +61,9 @@ public:
|
|||
ConversationAccountItem*
|
||||
GetListItem();
|
||||
|
||||
private:
|
||||
void _InitCommands();
|
||||
void LoadCommands();
|
||||
|
||||
private:
|
||||
ChatProtocol* fProtocol;
|
||||
int64 fInstance;
|
||||
|
||||
|
|
|
@ -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!");
|
||||
|
|
Ŝarĝante…
Reference in New Issue