(purple) Send user-roles to Cardie

Fixes #24
This commit is contained in:
Jaidyn Ann 2021-07-06 12:08:51 -05:00
parent e88a8372dc
commit 9d8b35fc86
2 changed files with 59 additions and 0 deletions

View File

@ -875,6 +875,8 @@ init_signals()
&handle, PURPLE_CALLBACK(signal_chat_buddy_joined), NULL);
purple_signal_connect(purple_conversations_get_handle(), "chat-invited",
&handle, PURPLE_CALLBACK(signal_chat_invited), NULL);
purple_signal_connect(purple_conversations_get_handle(), "chat-buddy-flags",
&handle, PURPLE_CALLBACK(signal_chat_buddy_flags), NULL);
}
@ -1047,6 +1049,8 @@ signal_chat_buddy_joined(PurpleConversation* conv, const char* name,
PurpleAccount* account = purple_conversation_get_account(conv);
((PurpleApp*)be_app)->SendMessage(account, joined);
send_user_role(conv, name, flags);
}
@ -1071,6 +1075,14 @@ signal_chat_invited(PurpleAccount* account, const char* inviter,
}
static void
signal_chat_buddy_flags(PurpleConversation* conv, const char* name,
PurpleConvChatBuddyFlags oldflags, PurpleConvChatBuddyFlags newflags)
{
send_user_role(conv, name, newflags);
}
static guint
ui_op_input_add(gint fd, PurpleInputCondition condition,
PurpleInputFunction function, gpointer data)
@ -1091,6 +1103,48 @@ ui_op_input_add(gint fd, PurpleInputCondition condition,
}
void
send_user_role(PurpleConversation* conv, const char* name,
PurpleConvChatBuddyFlags flags)
{
if (flags == 0) return;
BString role_title;
int32 role_perms = 0 | PERM_READ | PERM_WRITE;
int32 role_priority = 0;
if (flags & PURPLE_CBFLAGS_FOUNDER) {
role_title = "Founder";
role_priority = 3;
}
if (flags & PURPLE_CBFLAGS_OP) {
if (role_title.IsEmpty() == true)
role_title = "Operator";
role_perms |= PERM_KICK | PERM_BAN | PERM_MUTE | PERM_DEAFEN
| PERM_ROLECHANGE | PERM_ROOM_SUBJECT | PERM_ROOM_NAME;
role_priority = 2;
}
if (flags & PURPLE_CBFLAGS_HALFOP) {
if (role_title.IsEmpty() == true)
role_title = "Moderator";
role_perms |= PERM_KICK | PERM_MUTE | PERM_DEAFEN | PERM_ROOM_SUBJECT;
role_priority = 3;
}
if (role_title.IsEmpty() == true) return;
BMessage role(IM_MESSAGE);
role.AddInt32("im_what", IM_ROOM_ROLECHANGED);
role.AddString("user_id", name);
role.AddString("chat_id", purple_conversation_get_name(conv));
role.AddString("role_title", role_title);
role.AddInt32("role_perms", role_perms);
role.AddInt32("role_priority", role_priority);
((PurpleApp*)be_app)->SendMessage(purple_conversation_get_account(conv),
role);
}
PurpleStatusPrimitive
cardie_status_to_purple(UserStatus status)
{

View File

@ -140,6 +140,9 @@ private:
static void signal_chat_invited(PurpleAccount* account,
const char* inviter, const char* chat,
const char* message, const GHashTable* components);
static void signal_chat_buddy_flags(PurpleConversation* conv,
const char* name, PurpleConvChatBuddyFlags oldflags,
PurpleConvChatBuddyFlags newflags);
// EventLoop ui ops
static guint ui_op_input_add(gint fd,
@ -147,6 +150,8 @@ private:
PurpleInputFunction function, gpointer data);
// Util
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);