mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Show message when room requires config
This commit is contained in:
parent
1a6dc76360
commit
57effcd504
@ -449,6 +449,12 @@ handle_room_nick_change(const char * const room,
|
||||
ui_room_nick_change(room, nick);
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_requires_config(const char * const room)
|
||||
{
|
||||
ui_room_requires_config(room);
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_roster_complete(const char * const room)
|
||||
{
|
||||
|
@ -69,6 +69,7 @@ void handle_contact_online(char *contact, Resource *resource,
|
||||
void handle_leave_room(const char * const room);
|
||||
void handle_room_nick_change(const char * const room,
|
||||
const char * const nick);
|
||||
void handle_room_requires_config(const char * const room);
|
||||
void handle_room_roster_complete(const char * const room);
|
||||
void handle_room_member_presence(const char * const room,
|
||||
const char * const nick, const char * const show,
|
||||
|
@ -1588,6 +1588,28 @@ _ui_room_message(const char * const room_jid, const char * const nick,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_ui_room_requires_config(const char * const room_jid)
|
||||
{
|
||||
ProfWin *window = wins_get_by_recipient(room_jid);
|
||||
if (window == NULL) {
|
||||
log_error("Received room config request, but no window open for %s.", room_jid);
|
||||
} else {
|
||||
int num = wins_get_num(window);
|
||||
|
||||
win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room requires configuration, use '/room config accept' or '/room config cancel'");
|
||||
|
||||
// currently in groupchat window
|
||||
if (wins_is_current(window)) {
|
||||
status_bar_active(num);
|
||||
|
||||
// not currenlty on groupchat window
|
||||
} else {
|
||||
status_bar_new(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_ui_room_subject(const char * const room_jid, const char * const subject)
|
||||
{
|
||||
@ -2063,4 +2085,5 @@ ui_init_module(void)
|
||||
ui_handle_room_join_error = _ui_handle_room_join_error;
|
||||
ui_swap_wins = _ui_swap_wins;
|
||||
ui_update = _ui_update;
|
||||
ui_room_requires_config = _ui_room_requires_config;
|
||||
}
|
||||
|
@ -135,6 +135,7 @@ void (*ui_room_message)(const char * const room_jid, const char * const nick,
|
||||
const char * const message);
|
||||
void (*ui_room_subject)(const char * const room_jid,
|
||||
const char * const subject);
|
||||
void (*ui_room_requires_config)(const char * const room_jid);
|
||||
void (*ui_room_broadcast)(const char * const room_jid,
|
||||
const char * const message);
|
||||
void (*ui_room_member_offline)(const char * const room, const char * const nick);
|
||||
|
@ -708,6 +708,11 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
// handle roster complete
|
||||
} else if (!muc_get_roster_received(from_room)) {
|
||||
handle_room_roster_complete(from_room);
|
||||
|
||||
// room configuration required
|
||||
if (stanza_muc_requires_config(stanza)) {
|
||||
handle_room_requires_config(from_room);
|
||||
}
|
||||
}
|
||||
|
||||
// handle presence from room members
|
||||
|
@ -649,6 +649,52 @@ stanza_is_muc_presence(xmpp_stanza_t * const stanza)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
stanza_muc_requires_config(xmpp_stanza_t * const stanza)
|
||||
{
|
||||
// no stanza, or not presence stanza
|
||||
if ((stanza == NULL) || (g_strcmp0(xmpp_stanza_get_name(stanza), STANZA_NAME_PRESENCE) != 0)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// muc user namespaced x element
|
||||
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
|
||||
if (x != NULL) {
|
||||
|
||||
// check for item element with owner affiliation
|
||||
xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(x, "item");
|
||||
if (item == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
char *affiliation = xmpp_stanza_get_attribute(item, "affiliation");
|
||||
if (g_strcmp0(affiliation, "owner") != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// check for status code 110 and 201
|
||||
gboolean has110 = FALSE;
|
||||
gboolean has201 = FALSE;
|
||||
xmpp_stanza_t *x_children = xmpp_stanza_get_children(x);
|
||||
while (x_children != NULL) {
|
||||
if (g_strcmp0(xmpp_stanza_get_name(x_children), STANZA_NAME_STATUS) == 0) {
|
||||
char *code = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_CODE);
|
||||
if (g_strcmp0(code, "110") == 0) {
|
||||
has110 = TRUE;
|
||||
}
|
||||
if (g_strcmp0(code, "201") == 0) {
|
||||
has201 = TRUE;
|
||||
}
|
||||
}
|
||||
x_children = xmpp_stanza_get_next(x_children);
|
||||
}
|
||||
|
||||
if (has110 && has201) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
|
||||
const char * const self_jid)
|
||||
|
@ -198,6 +198,7 @@ gboolean stanza_is_muc_presence(xmpp_stanza_t * const stanza);
|
||||
gboolean stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
|
||||
const char * const self_jid);
|
||||
gboolean stanza_is_room_nick_change(xmpp_stanza_t * const stanza);
|
||||
gboolean stanza_muc_requires_config(xmpp_stanza_t * const stanza);
|
||||
|
||||
char * stanza_get_new_nick(xmpp_stanza_t * const stanza);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user