From 74dcf452c276972f1d606eabd876a3cb430cf8de Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Mon, 5 Jul 2021 12:42:20 -0500 Subject: [PATCH] (purple) Creation/joining rooms using "room" template Fixes #30 --- protocols/purple/PurpleApp.cpp | 58 ++++++++++++++++++++++++---------- protocols/purple/PurpleApp.h | 3 +- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/protocols/purple/PurpleApp.cpp b/protocols/purple/PurpleApp.cpp index e96bd29..d8e27f1 100644 --- a/protocols/purple/PurpleApp.cpp +++ b/protocols/purple/PurpleApp.cpp @@ -190,13 +190,16 @@ PurpleApp::ImMessage(BMessage* msg) SendMessage(account, created); break; } + case IM_CREATE_ROOM: + { + serv_join_chat(_ConnectionFromMessage(msg), _ParseRoomTemplate(msg)); + break; + } case IM_JOIN_ROOM: { - PurpleAccount* account = _AccountFromMessage(msg); - PurpleConnection* conn = purple_account_get_connection(account); + PurpleConnection* conn = _ConnectionFromMessage(msg); BString chat_id = msg->FindString("chat_id"); - if (account == NULL || conn == NULL || chat_id.IsEmpty() == true) - break; + if (conn == NULL || chat_id.IsEmpty() == true) break; PurplePluginProtocolInfo* info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(conn)); @@ -418,8 +421,8 @@ void PurpleApp::_SaveProtocolInfo(PurplePlugin* plugin) { ProtocolInfo* proto = new ProtocolInfo; - proto->id = plugin->info->id; - proto->name = plugin->info->name; + proto->id = purple_plugin_get_id(plugin); + proto->name = purple_plugin_get_name(plugin); PurplePluginProtocolInfo* info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); proto->accountTemplate = _GetAccountTemplate(info); @@ -654,6 +657,32 @@ PurpleApp::_ParseAccountTemplate(BMessage* settings) } +GHashTable* +PurpleApp::_ParseRoomTemplate(BMessage* msg) +{ + PurplePlugin* plugin = _PluginFromMessage(msg); + PurplePluginProtocolInfo* info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); + + if (info->chat_info == NULL && info->chat_info_defaults != NULL) + return info->chat_info_defaults(_ConnectionFromMessage(msg), + msg->FindString("chat_id")); + else if (info->chat_info == NULL) + return NULL; + + GHashTable* table + = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); + + GList* prefs = info->chat_info(NULL); + for (int i = 0; prefs != NULL; prefs = prefs->next) { + BString setting; + proto_chat_entry* pref = (proto_chat_entry*)prefs->data; + if (msg->FindString(pref->identifier, &setting) == B_OK) + g_hash_table_insert(table, (void*)pref->identifier, g_strdup(setting.String())); + } + return table; +} + + PurplePlugin* PurpleApp::_PluginFromMessage(BMessage* msg) { @@ -661,6 +690,13 @@ PurpleApp::_PluginFromMessage(BMessage* msg) } +PurpleConnection* +PurpleApp::_ConnectionFromMessage(BMessage* msg) +{ + return purple_account_get_connection(_AccountFromMessage(msg)); +} + + PurpleAccount* PurpleApp::_AccountFromMessage(BMessage* msg) { @@ -1039,11 +1075,6 @@ static guint _purple_glib_input_add(gint fd, PurpleInputCondition condition, closure->function = function; closure->data = data; -// if (condition & PURPLE_INPUT_READ) -// cond |= PURPLE_GLIB_READ_COND; -// if (condition & PURPLE_INPUT_WRITE) -// cond |= PURPLE_GLIB_WRITE_COND; - channel = g_io_channel_unix_new(fd); closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, _purple_glib_io_invoke, closure, g_free); @@ -1058,11 +1089,6 @@ static gboolean _purple_glib_io_invoke(GIOChannel *source, GIOCondition conditio PurpleGLibIOClosure *closure = (PurpleGLibIOClosure*)data; PurpleInputCondition purple_cond = (PurpleInputCondition)0; -// if (condition & PURPLE_GLIB_READ_COND) -// purple_cond |= PURPLE_INPUT_READ; -// if (condition & PURPLE_GLIB_WRITE_COND) -// purple_cond |= PURPLE_INPUT_WRITE; - closure->function(closure->data, g_io_channel_unix_get_fd(source), purple_cond); diff --git a/protocols/purple/PurpleApp.h b/protocols/purple/PurpleApp.h index b2e8a6e..595024a 100644 --- a/protocols/purple/PurpleApp.h +++ b/protocols/purple/PurpleApp.h @@ -91,9 +91,10 @@ private: BMessage _GetRoomTemplate(PurplePluginProtocolInfo* info); void _ParseAccountTemplate(BMessage* settings); - void _ParseRoomTemplate(BMessage* msg); + GHashTable* _ParseRoomTemplate(BMessage* msg); PurplePlugin* _PluginFromMessage(BMessage* msg); + PurpleConnection* _ConnectionFromMessage(BMessage* msg); PurpleAccount* _AccountFromMessage(BMessage* msg); PurpleConversation* _ConversationFromMessage(BMessage* msg);