(purple) Handle incoming invites
This commit is contained in:
parent
140a7f8834
commit
10003276cd
|
@ -209,7 +209,6 @@ PurpleApp::ImMessage(BMessage* msg)
|
||||||
}
|
}
|
||||||
case IM_GET_CONTACT_LIST:
|
case IM_GET_CONTACT_LIST:
|
||||||
{
|
{
|
||||||
msg->PrintToStream();
|
|
||||||
BStringList user_ids;
|
BStringList user_ids;
|
||||||
GSList* buddies = purple_blist_get_buddies();
|
GSList* buddies = purple_blist_get_buddies();
|
||||||
for (int i = 0; buddies != NULL; buddies = buddies->next) {
|
for (int i = 0; buddies != NULL; buddies = buddies->next) {
|
||||||
|
@ -223,6 +222,28 @@ PurpleApp::ImMessage(BMessage* msg)
|
||||||
SendMessage(_AccountFromMessage(msg), roster);
|
SendMessage(_AccountFromMessage(msg), roster);
|
||||||
break;
|
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:
|
default:
|
||||||
std::cout << "IM_MESSAGE unhandled by Purple:\n";
|
std::cout << "IM_MESSAGE unhandled by Purple:\n";
|
||||||
msg->PrintToStream();
|
msg->PrintToStream();
|
||||||
|
@ -571,6 +592,8 @@ init_signals()
|
||||||
&handle, PURPLE_CALLBACK(signal_sent_im_msg), NULL);
|
&handle, PURPLE_CALLBACK(signal_sent_im_msg), NULL);
|
||||||
purple_signal_connect(purple_conversations_get_handle(), "chat-buddy-joined",
|
purple_signal_connect(purple_conversations_get_handle(), "chat-buddy-joined",
|
||||||
&handle, PURPLE_CALLBACK(signal_chat_buddy_joined), NULL);
|
&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);
|
BMessage info(IM_MESSAGE);
|
||||||
info.AddInt32("im_what", IM_OWN_CONTACT_INFO);
|
info.AddInt32("im_what", IM_OWN_CONTACT_INFO);
|
||||||
info.AddString("user_id", purple_account_get_username(account));
|
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);
|
((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
|
PurpleStatusPrimitive
|
||||||
cardie_status_to_purple(UserStatus status)
|
cardie_status_to_purple(UserStatus status)
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
typedef KeyMap<BString, BString> Accounts; // Cardie username → Purple username
|
typedef KeyMap<BString, BString> Accounts; // Cardie username → Purple username
|
||||||
typedef KeyMap<BString, thread_id> AccountThreads; // Purple username → Thread
|
typedef KeyMap<BString, thread_id> AccountThreads; // Purple username → Thread
|
||||||
|
typedef KeyMap<BString, GHashTable*> GHashList;
|
||||||
|
|
||||||
const uint32 G_MAIN_LOOP = 'GLml';
|
const uint32 G_MAIN_LOOP = 'GLml';
|
||||||
const uint32 CHECK_APP = 'Paca';
|
const uint32 CHECK_APP = 'Paca';
|
||||||
|
@ -79,6 +80,8 @@ public:
|
||||||
void SendMessage(thread_id thread, BMessage msg);
|
void SendMessage(thread_id thread, BMessage msg);
|
||||||
void SendMessage(PurpleAccount* account, BMessage msg);
|
void SendMessage(PurpleAccount* account, BMessage msg);
|
||||||
|
|
||||||
|
GHashList fInviteList;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _GetProtocolsInfo();
|
void _GetProtocolsInfo();
|
||||||
void _SaveProtocolInfo(PurplePlugin* plugin);
|
void _SaveProtocolInfo(PurplePlugin* plugin);
|
||||||
|
@ -128,6 +131,9 @@ private:
|
||||||
static void signal_chat_buddy_joined(PurpleConversation* conv,
|
static void signal_chat_buddy_joined(PurpleConversation* conv,
|
||||||
const char* name, PurpleConvChatBuddyFlags flags,
|
const char* name, PurpleConvChatBuddyFlags flags,
|
||||||
gboolean new_arrival);
|
gboolean new_arrival);
|
||||||
|
static void signal_chat_invited(PurpleAccount* account,
|
||||||
|
const char* inviter, const char* chat,
|
||||||
|
const char* message, const GHashTable* components);
|
||||||
|
|
||||||
// Util
|
// Util
|
||||||
PurpleStatusPrimitive cardie_status_to_purple(UserStatus status);
|
PurpleStatusPrimitive cardie_status_to_purple(UserStatus status);
|
||||||
|
|
Ŝarĝante…
Reference in New Issue