parent
4294993761
commit
988a4ebfb6
|
@ -233,6 +233,7 @@ PurpleApp::ImMessage(BMessage* msg)
|
|||
}
|
||||
case IM_GET_ROOM_PARTICIPANTS:
|
||||
{
|
||||
PurpleAccount* account = _AccountFromMessage(msg);
|
||||
PurpleConversation* conv = _ConversationFromMessage(msg);
|
||||
PurpleConvChat* chat = purple_conversation_get_chat_data(conv);
|
||||
PurpleConvIm* im = purple_conversation_get_im_data(conv);
|
||||
|
@ -245,7 +246,9 @@ PurpleApp::ImMessage(BMessage* msg)
|
|||
GList* users = purple_conv_chat_get_users(chat);
|
||||
for (int i = 0; users != NULL; users = users->next) {
|
||||
PurpleConvChatBuddy* user = (PurpleConvChatBuddy*)users->data;
|
||||
user_ids.Add(BString(purple_conv_chat_cb_get_name(user)));
|
||||
const char* user_name = purple_conv_chat_cb_get_name(user);
|
||||
if (is_own_user(account, user_name) == false)
|
||||
user_ids.Add(BString(user_name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -856,7 +859,6 @@ PurpleApp::_ConversationFromMessage(BMessage* msg)
|
|||
}
|
||||
|
||||
|
||||
|
||||
status_t
|
||||
init_libpurple()
|
||||
{
|
||||
|
@ -958,11 +960,13 @@ signal_account_signed_on(PurpleAccount* account)
|
|||
PurpleApp* app = (PurpleApp*)be_app;
|
||||
((PurpleApp*)be_app)->SendMessage(account, readyMsg);
|
||||
|
||||
BString username = purple_account_get_username(account);
|
||||
BString display = purple_account_get_name_for_display(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_name_for_display(account));
|
||||
((PurpleApp*)be_app)->SendMessage(account, info);
|
||||
send_own_info(account);
|
||||
|
||||
((PurpleApp*)be_app)->fUserNicks.AddItem(username, display);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1052,8 +1056,8 @@ static void
|
|||
signal_received_chat_msg(PurpleAccount* account, char* sender, char* message,
|
||||
PurpleConversation* conv, PurpleMessageFlags flags)
|
||||
{
|
||||
if (strcmp(sender, purple_account_get_name_for_display(account)) == 0
|
||||
|| strcmp(sender, purple_account_get_username(account)) == 0)
|
||||
is_own_user(account, sender);
|
||||
if (flags | PURPLE_MESSAGE_SEND)
|
||||
return;
|
||||
|
||||
BString chat_id = BString(purple_conversation_get_name(conv));
|
||||
|
@ -1107,8 +1111,11 @@ signal_chat_buddy_joined(PurpleConversation* conv, const char* name,
|
|||
BMessage joined(IM_MESSAGE);
|
||||
if (new_arrival)
|
||||
joined.AddInt32("im_what", IM_ROOM_PARTICIPANT_JOINED);
|
||||
else
|
||||
else {
|
||||
joined.AddInt32("im_what", IM_ROOM_PARTICIPANTS);
|
||||
if (is_own_user(purple_conversation_get_account(conv), name) == true)
|
||||
return;
|
||||
}
|
||||
joined.AddString("chat_id", purple_conversation_get_name(conv));
|
||||
joined.AddString("user_id", name);
|
||||
|
||||
|
@ -1168,6 +1175,36 @@ ui_op_input_add(gint fd, PurpleInputCondition condition,
|
|||
}
|
||||
|
||||
|
||||
bool
|
||||
is_own_user(PurpleAccount* account, const char* name)
|
||||
{
|
||||
PurpleApp* app = ((PurpleApp*)be_app);
|
||||
BString username = purple_account_get_username(account);
|
||||
BString display = purple_account_get_name_for_display(account);
|
||||
|
||||
if (app->fUserNicks.ValueFor(username) != display) {
|
||||
app->fUserNicks.RemoveItemFor(username);
|
||||
app->fUserNicks.AddItem(username, display);
|
||||
send_own_info(account);
|
||||
}
|
||||
|
||||
if (name == username || name == display)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
send_own_info(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_name_for_display(account));
|
||||
((PurpleApp*)be_app)->SendMessage(account, info);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
send_user_role(PurpleConversation* conv, const char* name,
|
||||
PurpleConvChatBuddyFlags flags)
|
||||
|
|
|
@ -32,9 +32,9 @@
|
|||
#include <AppConstants.h>
|
||||
|
||||
|
||||
typedef KeyMap<BString, BString> Accounts; // Cardie username → Purple username
|
||||
typedef KeyMap<BString, thread_id> AccountThreads; // Purple username → Thread
|
||||
typedef KeyMap<BString, GHashTable*> GHashList;
|
||||
typedef KeyMap<BString, BString> StringMap;
|
||||
typedef KeyMap<BString, thread_id> ThreadMap;
|
||||
typedef KeyMap<BString, GHashTable*> HashMap;
|
||||
|
||||
const uint32 G_MAIN_LOOP = 'GLml';
|
||||
const uint32 CHECK_APP = 'Paca';
|
||||
|
@ -82,7 +82,8 @@ public:
|
|||
void SendMessage(thread_id thread, BMessage msg);
|
||||
void SendMessage(PurpleAccount* account, BMessage msg);
|
||||
|
||||
GHashList fInviteList;
|
||||
HashMap fInviteList;
|
||||
StringMap fUserNicks; // Purple username → Nickname for Cardie
|
||||
|
||||
private:
|
||||
void _SendSysText(PurpleConversation* conv, const char* text);
|
||||
|
@ -102,8 +103,8 @@ private:
|
|||
PurpleAccount* _AccountFromMessage(BMessage* msg);
|
||||
PurpleConversation* _ConversationFromMessage(BMessage* msg);
|
||||
|
||||
Accounts fAccounts;
|
||||
AccountThreads fAccountThreads;
|
||||
StringMap fAccounts; // Cardie account name → Purple username
|
||||
ThreadMap fAccountThreads; // Cardie account name → Thread
|
||||
BObjectList<ProtocolInfo> fProtocols;
|
||||
|
||||
GMainLoop* fGloop;
|
||||
|
@ -153,8 +154,12 @@ private:
|
|||
PurpleInputFunction function, gpointer data);
|
||||
|
||||
// Util
|
||||
bool is_own_user(PurpleAccount* account, const char* name);
|
||||
|
||||
void send_own_info(PurpleAccount* account);
|
||||
void send_user_role(PurpleConversation* conv,
|
||||
const char* name, PurpleConvChatBuddyFlags flags);
|
||||
|
||||
PurpleStatusPrimitive cardie_status_to_purple(UserStatus status);
|
||||
UserStatus purple_status_to_cardie(PurpleStatus* status);
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue