mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Store room affiliation and role
This commit is contained in:
parent
a4f7932ed7
commit
41b49cb5d6
@ -307,12 +307,13 @@ static struct cmd_t command_defs[] =
|
|||||||
|
|
||||||
{ "/room",
|
{ "/room",
|
||||||
cmd_room, parse_args, 1, 1, NULL,
|
cmd_room, parse_args, 1, 1, NULL,
|
||||||
{ "/room accept|destroy|config", "Room configuration.",
|
{ "/room accept|destroy|config|info", "Room configuration.",
|
||||||
{ "/room accept|destroy|config",
|
{ "/room accept|destroy|config|info",
|
||||||
"---------------------------",
|
"--------------------------------",
|
||||||
"accept - Accept default room configuration.",
|
"accept - Accept default room configuration.",
|
||||||
"destroy - Reject default room configuration.",
|
"destroy - Reject default room configuration.",
|
||||||
"config - Edit room configuration.",
|
"config - Edit room configuration.",
|
||||||
|
"info - Show room details.",
|
||||||
NULL } } },
|
NULL } } },
|
||||||
|
|
||||||
{ "/form",
|
{ "/form",
|
||||||
@ -1226,6 +1227,7 @@ cmd_init(void)
|
|||||||
autocomplete_add(room_ac, "accept");
|
autocomplete_add(room_ac, "accept");
|
||||||
autocomplete_add(room_ac, "destroy");
|
autocomplete_add(room_ac, "destroy");
|
||||||
autocomplete_add(room_ac, "config");
|
autocomplete_add(room_ac, "config");
|
||||||
|
autocomplete_add(room_ac, "info");
|
||||||
|
|
||||||
form_ac = autocomplete_new();
|
form_ac = autocomplete_new();
|
||||||
autocomplete_add(form_ac, "submit");
|
autocomplete_add(form_ac, "submit");
|
||||||
|
@ -2083,7 +2083,8 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
|||||||
|
|
||||||
if ((g_strcmp0(args[0], "accept") != 0) &&
|
if ((g_strcmp0(args[0], "accept") != 0) &&
|
||||||
(g_strcmp0(args[0], "destroy") != 0) &&
|
(g_strcmp0(args[0], "destroy") != 0) &&
|
||||||
(g_strcmp0(args[0], "config") != 0)) {
|
(g_strcmp0(args[0], "config") != 0) &&
|
||||||
|
(g_strcmp0(args[0], "info") != 0)) {
|
||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -2097,6 +2098,13 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
|||||||
ui_index = 0;
|
ui_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (g_strcmp0(args[0], "info") == 0) {
|
||||||
|
char *role = muc_get_role_str(room);
|
||||||
|
char *affiliation = muc_get_affiliation_str(room);
|
||||||
|
ui_current_print_line("Affiliation: %s, Role: %s", affiliation, role);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (g_strcmp0(args[0], "accept") == 0) {
|
if (g_strcmp0(args[0], "accept") == 0) {
|
||||||
gboolean requires_config = muc_requires_config(room);
|
gboolean requires_config = muc_requires_config(room);
|
||||||
if (!requires_config) {
|
if (!requires_config) {
|
||||||
|
156
src/muc.c
156
src/muc.c
@ -43,9 +43,26 @@
|
|||||||
#include "tools/autocomplete.h"
|
#include "tools/autocomplete.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MUC_ROLE_NONE,
|
||||||
|
MUC_ROLE_VISITOR,
|
||||||
|
MUC_ROLE_PARTICIPANT,
|
||||||
|
MUC_ROLE_MODERATOR
|
||||||
|
} muc_role_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MUC_AFFILIATION_NONE,
|
||||||
|
MUC_AFFILIATION_OUTCAST,
|
||||||
|
MUC_AFFILIATION_MEMBER,
|
||||||
|
MUC_AFFILIATION_ADMIN,
|
||||||
|
MUC_AFFILIATION_OWNER
|
||||||
|
} muc_affiliation_t;
|
||||||
|
|
||||||
typedef struct _muc_room_t {
|
typedef struct _muc_room_t {
|
||||||
char *room; // e.g. test@conference.server
|
char *room; // e.g. test@conference.server
|
||||||
char *nick; // e.g. Some User
|
char *nick; // e.g. Some User
|
||||||
|
muc_role_t role;
|
||||||
|
muc_affiliation_t affiliation;
|
||||||
char *password;
|
char *password;
|
||||||
char *subject;
|
char *subject;
|
||||||
char *autocomplete_prefix;
|
char *autocomplete_prefix;
|
||||||
@ -64,6 +81,10 @@ Autocomplete invite_ac;
|
|||||||
|
|
||||||
static void _free_room(ChatRoom *room);
|
static void _free_room(ChatRoom *room);
|
||||||
static gint _compare_participants(PContact a, PContact b);
|
static gint _compare_participants(PContact a, PContact b);
|
||||||
|
static muc_role_t _role_from_string(const char * const role);
|
||||||
|
static muc_affiliation_t _affiliation_from_string(const char * const affiliation);
|
||||||
|
static char* _role_to_string(muc_role_t role);
|
||||||
|
static char* _affiliation_to_string(muc_affiliation_t affiliation);
|
||||||
|
|
||||||
void
|
void
|
||||||
muc_init(void)
|
muc_init(void)
|
||||||
@ -147,6 +168,8 @@ muc_join_room(const char * const room, const char * const nick,
|
|||||||
ChatRoom *new_room = malloc(sizeof(ChatRoom));
|
ChatRoom *new_room = malloc(sizeof(ChatRoom));
|
||||||
new_room->room = strdup(room);
|
new_room->room = strdup(room);
|
||||||
new_room->nick = strdup(nick);
|
new_room->nick = strdup(nick);
|
||||||
|
new_room->role = MUC_ROLE_NONE;
|
||||||
|
new_room->affiliation = MUC_AFFILIATION_NONE;
|
||||||
new_room->autocomplete_prefix = NULL;
|
new_room->autocomplete_prefix = NULL;
|
||||||
if (password) {
|
if (password) {
|
||||||
new_room->password = strdup(password);
|
new_room->password = strdup(password);
|
||||||
@ -582,6 +605,46 @@ muc_reset_autocomplete(const char * const room)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
muc_get_role_str(const char * const room)
|
||||||
|
{
|
||||||
|
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
|
||||||
|
if (chat_room) {
|
||||||
|
return _role_to_string(chat_room->role);
|
||||||
|
} else {
|
||||||
|
return "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
muc_set_role(const char * const room, const char * const role)
|
||||||
|
{
|
||||||
|
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
|
||||||
|
if (chat_room) {
|
||||||
|
chat_room->role = _role_from_string(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
muc_get_affiliation_str(const char * const room)
|
||||||
|
{
|
||||||
|
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
|
||||||
|
if (chat_room) {
|
||||||
|
return _affiliation_to_string(chat_room->affiliation);
|
||||||
|
} else {
|
||||||
|
return "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
muc_set_affiliation(const char * const room, const char * const affiliation)
|
||||||
|
{
|
||||||
|
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
|
||||||
|
if (chat_room) {
|
||||||
|
chat_room->affiliation = _affiliation_from_string(affiliation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_free_room(ChatRoom *room)
|
_free_room(ChatRoom *room)
|
||||||
{
|
{
|
||||||
@ -621,3 +684,96 @@ gint _compare_participants(PContact a, PContact b)
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static muc_role_t
|
||||||
|
_role_from_string(const char * const role)
|
||||||
|
{
|
||||||
|
if (role) {
|
||||||
|
if (g_strcmp0(role, "visitor") == 0) {
|
||||||
|
return MUC_ROLE_VISITOR;
|
||||||
|
} else if (g_strcmp0(role, "participant") == 0) {
|
||||||
|
return MUC_ROLE_PARTICIPANT;
|
||||||
|
} else if (g_strcmp0(role, "moderator") == 0) {
|
||||||
|
return MUC_ROLE_MODERATOR;
|
||||||
|
} else {
|
||||||
|
return MUC_ROLE_NONE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return MUC_ROLE_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
_role_to_string(muc_role_t role)
|
||||||
|
{
|
||||||
|
char *result = NULL;
|
||||||
|
|
||||||
|
switch (role) {
|
||||||
|
case MUC_ROLE_NONE:
|
||||||
|
result = "none";
|
||||||
|
break;
|
||||||
|
case MUC_ROLE_VISITOR:
|
||||||
|
result = "visitor";
|
||||||
|
break;
|
||||||
|
case MUC_ROLE_PARTICIPANT:
|
||||||
|
result = "participant";
|
||||||
|
break;
|
||||||
|
case MUC_ROLE_MODERATOR:
|
||||||
|
result = "moderator";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result = "none";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static muc_affiliation_t
|
||||||
|
_affiliation_from_string(const char * const affiliation)
|
||||||
|
{
|
||||||
|
if (affiliation) {
|
||||||
|
if (g_strcmp0(affiliation, "outcast") == 0) {
|
||||||
|
return MUC_AFFILIATION_OUTCAST;
|
||||||
|
} else if (g_strcmp0(affiliation, "member") == 0) {
|
||||||
|
return MUC_AFFILIATION_MEMBER;
|
||||||
|
} else if (g_strcmp0(affiliation, "admin") == 0) {
|
||||||
|
return MUC_AFFILIATION_ADMIN;
|
||||||
|
} else if (g_strcmp0(affiliation, "owner") == 0) {
|
||||||
|
return MUC_AFFILIATION_OWNER;
|
||||||
|
} else {
|
||||||
|
return MUC_AFFILIATION_NONE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return MUC_AFFILIATION_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
_affiliation_to_string(muc_affiliation_t affiliation)
|
||||||
|
{
|
||||||
|
char *result = NULL;
|
||||||
|
|
||||||
|
switch (affiliation) {
|
||||||
|
case MUC_AFFILIATION_NONE:
|
||||||
|
result = "none";
|
||||||
|
break;
|
||||||
|
case MUC_AFFILIATION_OUTCAST:
|
||||||
|
result = "outcast";
|
||||||
|
break;
|
||||||
|
case MUC_AFFILIATION_MEMBER:
|
||||||
|
result = "member";
|
||||||
|
break;
|
||||||
|
case MUC_AFFILIATION_ADMIN:
|
||||||
|
result = "admin";
|
||||||
|
break;
|
||||||
|
case MUC_AFFILIATION_OWNER:
|
||||||
|
result = "owner";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result = "none";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -93,4 +93,9 @@ void muc_reset_autocomplete(const char * const room);
|
|||||||
gboolean muc_requires_config(const char * const room);
|
gboolean muc_requires_config(const char * const room);
|
||||||
void muc_set_requires_config(const char * const room, gboolean val);
|
void muc_set_requires_config(const char * const room, gboolean val);
|
||||||
|
|
||||||
|
void muc_set_role(const char * const room, const char * const role);
|
||||||
|
void muc_set_affiliation(const char * const room, const char * const affiliation);
|
||||||
|
char *muc_get_role_str(const char * const room);
|
||||||
|
char *muc_get_affiliation_str(const char * const room);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -456,6 +456,7 @@ void
|
|||||||
handle_room_nick_change(const char * const room,
|
handle_room_nick_change(const char * const room,
|
||||||
const char * const nick)
|
const char * const nick)
|
||||||
{
|
{
|
||||||
|
muc_complete_room_nick_change(room, nick);
|
||||||
ui_room_nick_change(room, nick);
|
ui_room_nick_change(room, nick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -697,6 +697,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
|
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
|
||||||
char *new_nick = stanza_get_new_nick(stanza);
|
char *new_nick = stanza_get_new_nick(stanza);
|
||||||
|
|
||||||
|
// self unavailable
|
||||||
if ((type != NULL) && (strcmp(type, STANZA_TYPE_UNAVAILABLE) == 0)) {
|
if ((type != NULL) && (strcmp(type, STANZA_TYPE_UNAVAILABLE) == 0)) {
|
||||||
|
|
||||||
// leave room if not self nick change
|
// leave room if not self nick change
|
||||||
@ -706,9 +707,11 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
handle_leave_room(from_room);
|
handle_leave_room(from_room);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// self online
|
||||||
|
} else {
|
||||||
|
|
||||||
// handle self nick change
|
// handle self nick change
|
||||||
} else if (muc_is_room_pending_nick_change(from_room)) {
|
if (muc_is_room_pending_nick_change(from_room)) {
|
||||||
muc_complete_room_nick_change(from_room, from_nick);
|
|
||||||
handle_room_nick_change(from_room, from_nick);
|
handle_room_nick_change(from_room, from_nick);
|
||||||
|
|
||||||
// handle roster complete
|
// handle roster complete
|
||||||
@ -721,6 +724,19 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set own affiliation and role
|
||||||
|
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
|
||||||
|
if (x) {
|
||||||
|
xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(x, STANZA_NAME_ITEM);
|
||||||
|
if (item) {
|
||||||
|
char *role = xmpp_stanza_get_attribute(item, "role");
|
||||||
|
muc_set_role(from_room, role);
|
||||||
|
char *affiliation = xmpp_stanza_get_attribute(item, "affiliation");
|
||||||
|
muc_set_affiliation(from_room, affiliation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// handle presence from room members
|
// handle presence from room members
|
||||||
} else {
|
} else {
|
||||||
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
|
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
|
||||||
|
@ -822,11 +822,11 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
|
|||||||
|
|
||||||
// muc user namespaced x element
|
// muc user namespaced x element
|
||||||
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
|
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
|
||||||
if (x != NULL) {
|
if (x) {
|
||||||
|
|
||||||
// check for status child element with 110 code
|
// check for status child element with 110 code
|
||||||
xmpp_stanza_t *x_children = xmpp_stanza_get_children(x);
|
xmpp_stanza_t *x_children = xmpp_stanza_get_children(x);
|
||||||
while (x_children != NULL) {
|
while (x_children) {
|
||||||
if (g_strcmp0(xmpp_stanza_get_name(x_children), STANZA_NAME_STATUS) == 0) {
|
if (g_strcmp0(xmpp_stanza_get_name(x_children), STANZA_NAME_STATUS) == 0) {
|
||||||
char *code = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_CODE);
|
char *code = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_CODE);
|
||||||
if (g_strcmp0(code, "110") == 0) {
|
if (g_strcmp0(code, "110") == 0) {
|
||||||
@ -838,9 +838,9 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
|
|||||||
|
|
||||||
// check for item child element with jid property
|
// check for item child element with jid property
|
||||||
xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(x, STANZA_NAME_ITEM);
|
xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(x, STANZA_NAME_ITEM);
|
||||||
if (item != NULL) {
|
if (item) {
|
||||||
char *jid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID);
|
char *jid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID);
|
||||||
if (jid != NULL) {
|
if (jid) {
|
||||||
if (g_str_has_prefix(self_jid, jid)) {
|
if (g_str_has_prefix(self_jid, jid)) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -849,7 +849,7 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
|
|||||||
|
|
||||||
// check if 'from' attribute identifies this user
|
// check if 'from' attribute identifies this user
|
||||||
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||||
if (from != NULL) {
|
if (from) {
|
||||||
Jid *from_jid = jid_create(from);
|
Jid *from_jid = jid_create(from);
|
||||||
if (muc_room_is_active(from_jid->barejid)) {
|
if (muc_room_is_active(from_jid->barejid)) {
|
||||||
char *nick = muc_get_room_nick(from_jid->barejid);
|
char *nick = muc_get_room_nick(from_jid->barejid);
|
||||||
@ -861,7 +861,7 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
|
|||||||
// check if a new nickname maps to a pending nick change for this user
|
// check if a new nickname maps to a pending nick change for this user
|
||||||
if (muc_is_room_pending_nick_change(from_jid->barejid)) {
|
if (muc_is_room_pending_nick_change(from_jid->barejid)) {
|
||||||
char *new_nick = from_jid->resourcepart;
|
char *new_nick = from_jid->resourcepart;
|
||||||
if (new_nick != NULL) {
|
if (new_nick) {
|
||||||
char *nick = muc_get_room_nick(from_jid->barejid);
|
char *nick = muc_get_room_nick(from_jid->barejid);
|
||||||
char *old_nick = muc_get_old_nick(from_jid->barejid, new_nick);
|
char *old_nick = muc_get_old_nick(from_jid->barejid, new_nick);
|
||||||
if (g_strcmp0(old_nick, nick) == 0) {
|
if (g_strcmp0(old_nick, nick) == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user