From 10003276cd6a515c9735554aae136cd67df47d95 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Thu, 1 Jul 2021 19:49:39 -0500 Subject: [PATCH] (purple) Handle incoming invites --- protocols/purple/PurpleApp.cpp | 47 ++++++++++++++++++++++++++++++++-- protocols/purple/PurpleApp.h | 6 +++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/protocols/purple/PurpleApp.cpp b/protocols/purple/PurpleApp.cpp index f24e61c..c2483f6 100644 --- a/protocols/purple/PurpleApp.cpp +++ b/protocols/purple/PurpleApp.cpp @@ -209,7 +209,6 @@ PurpleApp::ImMessage(BMessage* msg) } case IM_GET_CONTACT_LIST: { - msg->PrintToStream(); BStringList user_ids; GSList* buddies = purple_blist_get_buddies(); for (int i = 0; buddies != NULL; buddies = buddies->next) { @@ -223,6 +222,28 @@ PurpleApp::ImMessage(BMessage* msg) SendMessage(_AccountFromMessage(msg), roster); break; } + case IM_ROOM_INVITE_ACCEPT: + { + PurpleAccount* account = _AccountFromMessage(msg); + BString key(purple_account_get_username(account)); + key = key.Append("-invite-").Append(msg->FindString("chat_id")); + GHashTable* data = fInviteList.ValueFor(key); + + if (data != NULL) + serv_join_chat(purple_account_get_connection(account), data); + break; + } + case IM_ROOM_INVITE_REFUSE: + { + PurpleAccount* account = _AccountFromMessage(msg); + BString key(purple_account_get_username(account)); + key = key.Append("-invite-").Append(msg->FindString("chat_id")); + GHashTable* data = fInviteList.ValueFor(key); + + if (data != NULL) + serv_reject_chat(purple_account_get_connection(account), data); + break; + } default: std::cout << "IM_MESSAGE unhandled by Purple:\n"; msg->PrintToStream(); @@ -571,6 +592,8 @@ init_signals() &handle, PURPLE_CALLBACK(signal_sent_im_msg), NULL); purple_signal_connect(purple_conversations_get_handle(), "chat-buddy-joined", &handle, PURPLE_CALLBACK(signal_chat_buddy_joined), NULL); + purple_signal_connect(purple_conversations_get_handle(), "chat-invited", + &handle, PURPLE_CALLBACK(signal_chat_invited), NULL); } @@ -593,7 +616,7 @@ signal_account_signed_on(PurpleAccount* account) BMessage info(IM_MESSAGE); info.AddInt32("im_what", IM_OWN_CONTACT_INFO); info.AddString("user_id", purple_account_get_username(account)); - info.AddString("user_name", purple_account_get_alias(account)); + info.AddString("user_name", purple_account_get_name_for_display(account)); ((PurpleApp*)be_app)->SendMessage(account, info); } @@ -741,6 +764,26 @@ signal_chat_buddy_joined(PurpleConversation* conv, const char* name, } +// inviter == user_id, not user_name +static void +signal_chat_invited(PurpleAccount* account, const char* inviter, + const char* chat, const char* message, const GHashTable* components) +{ + PurpleApp* app = (PurpleApp*)be_app; + BString key(purple_account_get_username(account)); + key = key.Append("-invite-").Append(chat); + + GHashTable* data = (GHashTable*)components; + app->fInviteList.AddItem(key, data); + + BMessage invited(IM_MESSAGE); + invited.AddInt32("im_what", IM_ROOM_INVITE_RECEIVED); + invited.AddString("chat_id", chat); + invited.AddString("user_id", inviter); + invited.AddString("body", message); + app->SendMessage(account, invited); +} + PurpleStatusPrimitive cardie_status_to_purple(UserStatus status) diff --git a/protocols/purple/PurpleApp.h b/protocols/purple/PurpleApp.h index e2339ef..9e7cd2b 100644 --- a/protocols/purple/PurpleApp.h +++ b/protocols/purple/PurpleApp.h @@ -34,6 +34,7 @@ typedef KeyMap Accounts; // Cardie username → Purple username typedef KeyMap AccountThreads; // Purple username → Thread +typedef KeyMap GHashList; const uint32 G_MAIN_LOOP = 'GLml'; const uint32 CHECK_APP = 'Paca'; @@ -79,6 +80,8 @@ public: void SendMessage(thread_id thread, BMessage msg); void SendMessage(PurpleAccount* account, BMessage msg); + GHashList fInviteList; + private: void _GetProtocolsInfo(); void _SaveProtocolInfo(PurplePlugin* plugin); @@ -128,6 +131,9 @@ private: static void signal_chat_buddy_joined(PurpleConversation* conv, const char* name, PurpleConvChatBuddyFlags flags, gboolean new_arrival); + static void signal_chat_invited(PurpleAccount* account, + const char* inviter, const char* chat, + const char* message, const GHashTable* components); // Util PurpleStatusPrimitive cardie_status_to_purple(UserStatus status);