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