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,
|
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
|
* Special messages
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -29,7 +29,7 @@ ProtocolLooper::ProtocolLooper(ChatProtocol* protocol, int64 instance)
|
||||||
Account* account = reinterpret_cast<Account*>(
|
Account* account = reinterpret_cast<Account*>(
|
||||||
protocol->MessengerInterface());
|
protocol->MessengerInterface());
|
||||||
|
|
||||||
_InitCommands();
|
LoadCommands();
|
||||||
|
|
||||||
BString name(protocol->FriendlySignature());
|
BString name(protocol->FriendlySignature());
|
||||||
name << " - " << account->Name();
|
name << " - " << account->Name();
|
||||||
|
@ -199,8 +199,9 @@ ProtocolLooper::GetListItem()
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ProtocolLooper::_InitCommands()
|
ProtocolLooper::LoadCommands()
|
||||||
{
|
{
|
||||||
|
fCommands = CommandMap();
|
||||||
BObjectList<BMessage> commands = fProtocol->Commands();
|
BObjectList<BMessage> commands = fProtocol->Commands();
|
||||||
for (int i = 0; i < commands.CountItems(); i++) {
|
for (int i = 0; i < commands.CountItems(); i++) {
|
||||||
ChatCommand* cmd = new ChatCommand(commands.ItemAt(i));
|
ChatCommand* cmd = new ChatCommand(commands.ItemAt(i));
|
||||||
|
|
|
@ -61,9 +61,9 @@ public:
|
||||||
ConversationAccountItem*
|
ConversationAccountItem*
|
||||||
GetListItem();
|
GetListItem();
|
||||||
|
|
||||||
private:
|
void LoadCommands();
|
||||||
void _InitCommands();
|
|
||||||
|
|
||||||
|
private:
|
||||||
ChatProtocol* fProtocol;
|
ChatProtocol* fProtocol;
|
||||||
int64 fInstance;
|
int64 fInstance;
|
||||||
|
|
||||||
|
|
|
@ -568,12 +568,18 @@ Server::ImMessage(BMessage* msg)
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case IM_PROTOCOL_RELOAD_COMMANDS:
|
||||||
|
{
|
||||||
|
ProtocolLooper* looper = _LooperFromMessage(msg);
|
||||||
|
if (looper == NULL) break;
|
||||||
|
looper->LoadCommands();
|
||||||
|
break;
|
||||||
|
}
|
||||||
case IM_PROTOCOL_READY:
|
case IM_PROTOCOL_READY:
|
||||||
{
|
{
|
||||||
// Ready notification
|
// Ready notification
|
||||||
ProtocolLooper* looper = _LooperFromMessage(msg);
|
ProtocolLooper* looper = _LooperFromMessage(msg);
|
||||||
if (looper == NULL)
|
if (looper == NULL) break;
|
||||||
break;
|
|
||||||
ChatProtocol* proto = looper->Protocol();
|
ChatProtocol* proto = looper->Protocol();
|
||||||
|
|
||||||
BString content("%user% has connected!");
|
BString content("%user% has connected!");
|
||||||
|
|
Ŝarĝante…
Reference in New Issue