(purple) Fetch room template from purple

This commit is contained in:
Jaidyn Ann 2021-07-04 11:31:32 -05:00
parent b051cbed5a
commit ee8584e14c
5 changed files with 86 additions and 33 deletions

View File

@ -84,15 +84,20 @@ PurpleApp::MessageReceived(BMessage* msg)
int32 index = msg->GetInt32("index", 0); int32 index = msg->GetInt32("index", 0);
ProtocolInfo* info = fProtocols.ItemAt(index); ProtocolInfo* info = fProtocols.ItemAt(index);
BMessage protocolInfo = info->settingsTemplate; BMessage protoInfo;
protocolInfo.AddString("name", info->name); BMessage temps;
protocolInfo.AddString("id", info->id); temps.AddMessage("account", new BMessage(info->accountTemplate));
SendMessage(thread_id, protocolInfo); temps.AddMessage("room", new BMessage(info->roomTemplate));
protoInfo.AddMessage("templates", &temps);
protoInfo.AddString("name", info->name);
protoInfo.AddString("id", info->id);
SendMessage(thread_id, protoInfo);
break; break;
} }
case PURPLE_CONNECT_ACCOUNT: case PURPLE_CONNECT_ACCOUNT:
{ {
_ParseCardieSettings(msg); _ParseAccountTemplate(msg);
break; break;
} }
case PURPLE_REGISTER_THREAD: case PURPLE_REGISTER_THREAD:
@ -417,14 +422,14 @@ PurpleApp::_SaveProtocolInfo(PurplePlugin* plugin)
proto->name = plugin->info->name; proto->name = plugin->info->name;
PurplePluginProtocolInfo* info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); PurplePluginProtocolInfo* info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
proto->settingsTemplate = _ParseProtoOptions(info); proto->accountTemplate = _GetAccountTemplate(info);
proto->roomTemplate = _GetRoomTemplate(info);
fProtocols.AddItem(proto); fProtocols.AddItem(proto);
} }
BMessage BMessage
PurpleApp::_ParseProtoOptions(PurplePluginProtocolInfo* info) PurpleApp::_GetAccountTemplate(PurplePluginProtocolInfo* info)
{ {
BMessage temp; BMessage temp;
@ -524,8 +529,44 @@ PurpleApp::_ParseProtoOptions(PurplePluginProtocolInfo* info)
} }
BMessage
PurpleApp::_GetRoomTemplate(PurplePluginProtocolInfo* info)
{
BMessage settings;
if (info->chat_info == NULL) {
settings.AddString("name", "chat_id");
settings.AddString("description", "Room ID");
settings.AddInt32("type", B_STRING_TYPE);
return settings;
}
GList* prefs = info->chat_info(NULL);
for (int i = 0; prefs != NULL; prefs = prefs->next) {
BMessage setting;
proto_chat_entry* pref = (proto_chat_entry*)prefs->data;
setting.AddString("name", pref->identifier);
setting.AddString("description", pref->label);
if (pref->required)
setting.AddString("error",
BString(pref->identifier).Append(" is necessary."));
if (pref->secret)
setting.AddBool("is_secret", true);
if (pref->is_int)
setting.AddInt32("type", B_INT32_TYPE);
else
setting.AddInt32("type", B_STRING_TYPE);
settings.AddMessage("setting", &setting);
}
return settings;
}
void void
PurpleApp::_ParseCardieSettings(BMessage* settings) PurpleApp::_ParseAccountTemplate(BMessage* settings)
{ {
PurplePlugin* plugin = _PluginFromMessage(settings); PurplePlugin* plugin = _PluginFromMessage(settings);
PurplePluginProtocolInfo* info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); PurplePluginProtocolInfo* info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);

View File

@ -63,7 +63,8 @@ struct _PurpleStatus
typedef struct _ProtocolInfo { typedef struct _ProtocolInfo {
BString name; BString name;
BString id; BString id;
BMessage settingsTemplate; BMessage accountTemplate;
BMessage roomTemplate;
} ProtocolInfo; } ProtocolInfo;
@ -86,8 +87,11 @@ private:
void _GetProtocolsInfo(); void _GetProtocolsInfo();
void _SaveProtocolInfo(PurplePlugin* plugin); void _SaveProtocolInfo(PurplePlugin* plugin);
BMessage _ParseProtoOptions(PurplePluginProtocolInfo* info); BMessage _GetAccountTemplate(PurplePluginProtocolInfo* info);
void _ParseCardieSettings(BMessage* settings); BMessage _GetRoomTemplate(PurplePluginProtocolInfo* info);
void _ParseAccountTemplate(BMessage* settings);
void _ParseRoomTemplate(BMessage* msg);
PurplePlugin* _PluginFromMessage(BMessage* msg); PurplePlugin* _PluginFromMessage(BMessage* msg);
PurpleAccount* _AccountFromMessage(BMessage* msg); PurpleAccount* _AccountFromMessage(BMessage* msg);

View File

@ -27,35 +27,35 @@ enum purple_message {
*/ */
/*! Request a count of protocols. →Server /*! Request a count of protocols. →Server
* Response is sent directly to the requesting thread Response is sent directly to the requesting thread
* as a message's code, use receive_data() to catch it. as a message's code, use receive_data() to catch it.
* Requires: int64 thread_id */ Requires: int64 thread_id */
PURPLE_REQUEST_PROTOCOL_COUNT = 'PApc', PURPLE_REQUEST_PROTOCOL_COUNT = 'PApc',
/*! Request protocol metadata. →Server /*! Request protocol metadata. →Server
* Response is sent directly to the requesting thread Response is sent directly to the requesting thread
* with two subsquent messages (using receive_data()) with two subsquent messages (using receive_data())
* the first sending the size of the subsequently sent the first sending the size of the subsequently sent
* flattened BMessage. flattened BMessage.
* Requires: int32 protocol_index, int64 thread_id */ Requires: int32 protocol_index, int64 thread_id */
PURPLE_REQUEST_PROTOCOL_INFO = 'PApi', PURPLE_REQUEST_PROTOCOL_INFO = 'PApi',
/*! Load/start connecting the account →Server /*! Load/start connecting the account →Server
* Just the account's settings message from Cardie's end. Just the account's settings message from Cardie's end.
* It's the server's job to tie the Cardie account name It's the server's job to tie the Cardie account name
* to the PurpleAccount. */ to the PurpleAccount. */
PURPLE_CONNECT_ACCOUNT = 'PAla', PURPLE_CONNECT_ACCOUNT = 'PAla',
/*! Associate account with thread →Server /*! Associate account with thread →Server
* Makes the server associate the given account with Makes the server associate the given account with
* the given thread. All subsequent ServerAdd-On the given thread. All subsequent ServerAdd-On
* messages related to the account will be sent to this messages related to the account will be sent to this
* thread. thread.
* Requires: String account_name, int64 thread_id */ Requires: String account_name, int64 thread_id */
PURPLE_REGISTER_THREAD = 'PArl', PURPLE_REGISTER_THREAD = 'PArl',
/*! Disconnect add-on's account →Server /*! Disconnect add-on's account →Server
* Requires: String account_name */ Requires: String account_name */
PURPLE_REQUEST_DISCONNECT = 'Axwx' PURPLE_REQUEST_DISCONNECT = 'Axwx'
}; };

View File

@ -46,8 +46,10 @@ protocol_at(int32 i)
BMessage protoInfo = receive_message(); BMessage protoInfo = receive_message();
BString name = protoInfo.FindString("name"); BString name = protoInfo.FindString("name");
BString id = protoInfo.FindString("id"); BString id = protoInfo.FindString("id");
BMessage templates;
protoInfo.FindMessage("templates", &templates);
return (ChatProtocol*)new PurpleProtocol(name, id, protoInfo); return (ChatProtocol*)new PurpleProtocol(name, id, templates);
} }
@ -141,7 +143,7 @@ PurpleProtocol::PurpleProtocol(BString name, BString id, BMessage settings)
: :
fSignature(id), fSignature(id),
fFriendlySignature(name), fFriendlySignature(name),
fSettingsTemplate(settings) fTemplates(settings)
{ {
} }
@ -208,9 +210,15 @@ PurpleProtocol::UpdateSettings(BMessage* msg)
BMessage BMessage
PurpleProtocol::SettingsTemplate(const char* name) PurpleProtocol::SettingsTemplate(const char* name)
{ {
BMessage temp;
if (strcmp(name, "roster") == 0) if (strcmp(name, "roster") == 0)
return _RosterTemplate(); return _RosterTemplate();
return fSettingsTemplate; else if (strcmp(name, "account") == 0)
fTemplates.FindMessage("account", &temp);
else if (strcmp(name, "room") == 0 || strcmp(name, "join") == 0)
fTemplates.FindMessage("room", &temp);
return temp;
} }

View File

@ -92,7 +92,7 @@ private:
BString fSignature; BString fSignature;
BString fFriendlySignature; BString fFriendlySignature;
BMessage fSettingsTemplate; BMessage fTemplates;
}; };