From ee8584e14ce46453f354419837175d1376480df5 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sun, 4 Jul 2021 11:31:32 -0500 Subject: [PATCH] (purple) Fetch room template from purple --- protocols/purple/PurpleApp.cpp | 59 ++++++++++++++++++++++++----- protocols/purple/PurpleApp.h | 10 +++-- protocols/purple/PurpleMessages.h | 34 ++++++++--------- protocols/purple/PurpleProtocol.cpp | 14 +++++-- protocols/purple/PurpleProtocol.h | 2 +- 5 files changed, 86 insertions(+), 33 deletions(-) diff --git a/protocols/purple/PurpleApp.cpp b/protocols/purple/PurpleApp.cpp index 175093e..e96bd29 100644 --- a/protocols/purple/PurpleApp.cpp +++ b/protocols/purple/PurpleApp.cpp @@ -84,15 +84,20 @@ PurpleApp::MessageReceived(BMessage* msg) int32 index = msg->GetInt32("index", 0); ProtocolInfo* info = fProtocols.ItemAt(index); - BMessage protocolInfo = info->settingsTemplate; - protocolInfo.AddString("name", info->name); - protocolInfo.AddString("id", info->id); - SendMessage(thread_id, protocolInfo); + BMessage protoInfo; + BMessage temps; + temps.AddMessage("account", new BMessage(info->accountTemplate)); + 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; } case PURPLE_CONNECT_ACCOUNT: { - _ParseCardieSettings(msg); + _ParseAccountTemplate(msg); break; } case PURPLE_REGISTER_THREAD: @@ -417,14 +422,14 @@ PurpleApp::_SaveProtocolInfo(PurplePlugin* plugin) proto->name = plugin->info->name; PurplePluginProtocolInfo* info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); - proto->settingsTemplate = _ParseProtoOptions(info); - + proto->accountTemplate = _GetAccountTemplate(info); + proto->roomTemplate = _GetRoomTemplate(info); fProtocols.AddItem(proto); } BMessage -PurpleApp::_ParseProtoOptions(PurplePluginProtocolInfo* info) +PurpleApp::_GetAccountTemplate(PurplePluginProtocolInfo* info) { 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 -PurpleApp::_ParseCardieSettings(BMessage* settings) +PurpleApp::_ParseAccountTemplate(BMessage* settings) { PurplePlugin* plugin = _PluginFromMessage(settings); PurplePluginProtocolInfo* info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); diff --git a/protocols/purple/PurpleApp.h b/protocols/purple/PurpleApp.h index 9e7cd2b..b2e8a6e 100644 --- a/protocols/purple/PurpleApp.h +++ b/protocols/purple/PurpleApp.h @@ -63,7 +63,8 @@ struct _PurpleStatus typedef struct _ProtocolInfo { BString name; BString id; - BMessage settingsTemplate; + BMessage accountTemplate; + BMessage roomTemplate; } ProtocolInfo; @@ -86,8 +87,11 @@ private: void _GetProtocolsInfo(); void _SaveProtocolInfo(PurplePlugin* plugin); - BMessage _ParseProtoOptions(PurplePluginProtocolInfo* info); - void _ParseCardieSettings(BMessage* settings); + BMessage _GetAccountTemplate(PurplePluginProtocolInfo* info); + BMessage _GetRoomTemplate(PurplePluginProtocolInfo* info); + + void _ParseAccountTemplate(BMessage* settings); + void _ParseRoomTemplate(BMessage* msg); PurplePlugin* _PluginFromMessage(BMessage* msg); PurpleAccount* _AccountFromMessage(BMessage* msg); diff --git a/protocols/purple/PurpleMessages.h b/protocols/purple/PurpleMessages.h index bcffb47..cf6a7f0 100644 --- a/protocols/purple/PurpleMessages.h +++ b/protocols/purple/PurpleMessages.h @@ -27,35 +27,35 @@ enum purple_message { */ /*! Request a count of protocols. →Server - * Response is sent directly to the requesting thread - * as a message's code, use receive_data() to catch it. - * Requires: int64 thread_id */ + Response is sent directly to the requesting thread + as a message's code, use receive_data() to catch it. + Requires: int64 thread_id */ PURPLE_REQUEST_PROTOCOL_COUNT = 'PApc', /*! Request protocol metadata. →Server - * Response is sent directly to the requesting thread - * with two subsquent messages (using receive_data())― - * the first sending the size of the subsequently sent - * flattened BMessage. - * Requires: int32 protocol_index, int64 thread_id */ + Response is sent directly to the requesting thread + with two subsquent messages (using receive_data())― + the first sending the size of the subsequently sent + flattened BMessage. + Requires: int32 protocol_index, int64 thread_id */ PURPLE_REQUEST_PROTOCOL_INFO = 'PApi', /*! Load/start connecting the account →Server - * Just the account's settings message from Cardie's end. - * It's the server's job to tie the Cardie account name - * to the PurpleAccount. */ + Just the account's settings message from Cardie's end. + It's the server's job to tie the Cardie account name + to the PurpleAccount. */ PURPLE_CONNECT_ACCOUNT = 'PAla', /*! Associate account with thread →Server - * Makes the server associate the given account with - * the given thread. All subsequent Server→Add-On - * messages related to the account will be sent to this - * thread. - * Requires: String account_name, int64 thread_id */ + Makes the server associate the given account with + the given thread. All subsequent Server→Add-On + messages related to the account will be sent to this + thread. + Requires: String account_name, int64 thread_id */ PURPLE_REGISTER_THREAD = 'PArl', /*! Disconnect add-on's account →Server - * Requires: String account_name */ + Requires: String account_name */ PURPLE_REQUEST_DISCONNECT = 'Axwx' }; diff --git a/protocols/purple/PurpleProtocol.cpp b/protocols/purple/PurpleProtocol.cpp index f49d55d..5320b23 100644 --- a/protocols/purple/PurpleProtocol.cpp +++ b/protocols/purple/PurpleProtocol.cpp @@ -46,8 +46,10 @@ protocol_at(int32 i) BMessage protoInfo = receive_message(); BString name = protoInfo.FindString("name"); 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), fFriendlySignature(name), - fSettingsTemplate(settings) + fTemplates(settings) { } @@ -208,9 +210,15 @@ PurpleProtocol::UpdateSettings(BMessage* msg) BMessage PurpleProtocol::SettingsTemplate(const char* name) { + BMessage temp; + if (strcmp(name, "roster") == 0) 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; } diff --git a/protocols/purple/PurpleProtocol.h b/protocols/purple/PurpleProtocol.h index fd0f2a5..f8ede23 100644 --- a/protocols/purple/PurpleProtocol.h +++ b/protocols/purple/PurpleProtocol.h @@ -92,7 +92,7 @@ private: BString fSignature; BString fFriendlySignature; - BMessage fSettingsTemplate; + BMessage fTemplates; };