mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Show message in console when receiving chat room invites
This commit is contained in:
parent
270dae472f
commit
b6095ca955
@ -316,6 +316,14 @@ prof_handle_leave_room(const char * const room)
|
||||
muc_leave_room(room);
|
||||
}
|
||||
|
||||
void prof_handle_room_invite(jabber_invite_t invite_type,
|
||||
const char * const invitor, const char * const room,
|
||||
const char * const reason)
|
||||
{
|
||||
cons_show_room_invite(invitor, room, reason);
|
||||
win_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_contact_online(char *contact, Resource *resource,
|
||||
GDateTime *last_activity)
|
||||
|
@ -66,6 +66,9 @@ void prof_handle_room_nick_change(const char * const room,
|
||||
const char * const nick);
|
||||
void prof_handle_room_broadcast(const char *const room_jid,
|
||||
const char * const message);
|
||||
void prof_handle_room_invite(jabber_invite_t invite_type,
|
||||
const char * const invitor, const char * const room,
|
||||
const char * const reason);
|
||||
void prof_handle_idle(void);
|
||||
void prof_handle_activity(void);
|
||||
void prof_handle_version_result(const char * const jid,
|
||||
|
@ -176,6 +176,8 @@ void cons_show_account_list(gchar **accounts);
|
||||
void cons_show_room_list(GSList *room, const char * const conference_node);
|
||||
void cons_show_disco_items(GSList *items, const char * const jid);
|
||||
void cons_show_disco_info(const char *from, GSList *identities, GSList *features);
|
||||
void cons_show_room_invite(const char * const invitor, const char * const room,
|
||||
const char * const reason);
|
||||
|
||||
// status bar actions
|
||||
void status_bar_refresh(void);
|
||||
|
@ -1397,6 +1397,20 @@ cons_show_status(const char * const contact)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cons_show_room_invite(const char * const invitor, const char * const room,
|
||||
const char * const reason)
|
||||
{
|
||||
cons_show("");
|
||||
_win_show_time(console->win, '-');
|
||||
wprintw(console->win, "%s has invited you to join %s", invitor, room);
|
||||
if (reason != NULL) {
|
||||
wprintw(console->win, ", \"%s\"", reason);
|
||||
}
|
||||
wprintw(console->win, "\n");
|
||||
cons_show("Type \"/join %s\" to join the room", room);
|
||||
}
|
||||
|
||||
void
|
||||
cons_show_account_list(gchar **accounts)
|
||||
{
|
||||
|
@ -41,6 +41,8 @@ static int _groupchat_message_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
static int _chat_message_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
static int _conference_message_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
|
||||
void
|
||||
message_add_handlers(void)
|
||||
@ -48,9 +50,10 @@ message_add_handlers(void)
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
|
||||
HANDLE(NULL, STANZA_TYPE_ERROR, connection_error_handler);
|
||||
HANDLE(NULL, STANZA_TYPE_GROUPCHAT, _groupchat_message_handler);
|
||||
HANDLE(NULL, STANZA_TYPE_CHAT, _chat_message_handler);
|
||||
HANDLE(NULL, STANZA_TYPE_ERROR, connection_error_handler);
|
||||
HANDLE(NULL, STANZA_TYPE_GROUPCHAT, _groupchat_message_handler);
|
||||
HANDLE(NULL, STANZA_TYPE_CHAT, _chat_message_handler);
|
||||
HANDLE(NULL, NULL, _conference_message_handler);
|
||||
}
|
||||
|
||||
void
|
||||
@ -142,6 +145,85 @@ message_send_gone(const char * const recipient)
|
||||
chat_session_set_sent(recipient);
|
||||
}
|
||||
|
||||
static int
|
||||
_conference_message_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata)
|
||||
{
|
||||
/*
|
||||
* <message to="prof2@panesar" from="test@conference.panesar">
|
||||
* <x xmlns="http://jabber.org/protocol/muc#user">
|
||||
* <invite from="prof4@panesar/2572c43f-aa3d-42fa-a74e-c322a80a90b8">
|
||||
* <reason>Join the room!</reason>
|
||||
* </invite>
|
||||
* </x>
|
||||
* <x jid="test@conference.panesar" xmlns="jabber:x:conference">
|
||||
* Join the room!
|
||||
* </x>
|
||||
* <body>
|
||||
* prof4@panesar/2572c43f-aa3d-42fa-a74e-c322a80a90b8 invited you to the room test@conference.panesar (Join the room!)
|
||||
* </body>
|
||||
* </message>
|
||||
*
|
||||
*/
|
||||
|
||||
xmpp_stanza_t *x_muc = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
|
||||
xmpp_stanza_t *x_groupchat = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE);
|
||||
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||
char *room = NULL;
|
||||
char *invitor = NULL;
|
||||
char *reason = NULL;
|
||||
|
||||
if (from == NULL) {
|
||||
log_warning("Message received with no from attribute, ignoring");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// XEP-0045
|
||||
if (x_muc != NULL) {
|
||||
room = from;
|
||||
|
||||
xmpp_stanza_t *invite = xmpp_stanza_get_child_by_name(x_muc, STANZA_NAME_INVITE);
|
||||
if (invite == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *invitor_jid = xmpp_stanza_get_attribute(invite, STANZA_ATTR_FROM);
|
||||
if (invitor_jid == NULL) {
|
||||
log_warning("Chat room invite received with no from attribute");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Jid *jidp = jid_create(invitor_jid);
|
||||
invitor = jidp->barejid;
|
||||
|
||||
xmpp_stanza_t *reason_st = xmpp_stanza_get_child_by_name(invite, STANZA_NAME_REASON);
|
||||
if (reason_st != NULL) {
|
||||
reason = xmpp_stanza_get_text(reason_st);
|
||||
}
|
||||
|
||||
prof_handle_room_invite(INVITE_MEDIATED, invitor, room, reason);
|
||||
jid_destroy(jidp);
|
||||
|
||||
// XEP-0429
|
||||
} else if (x_groupchat != NULL) {
|
||||
room = xmpp_stanza_get_attribute(x_groupchat, STANZA_ATTR_JID);
|
||||
if (room == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Jid *jidp = jid_create(from);
|
||||
invitor = jidp->barejid;
|
||||
|
||||
reason = xmpp_stanza_get_attribute(x_groupchat, STANZA_ATTR_REASON);
|
||||
|
||||
prof_handle_room_invite(INVITE_DIRECT, invitor, room, reason);
|
||||
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
_groupchat_message_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata)
|
||||
|
@ -49,6 +49,8 @@
|
||||
#define STANZA_NAME_C "c"
|
||||
#define STANZA_NAME_IDENTITY "identity"
|
||||
#define STANZA_NAME_FEATURE "feature"
|
||||
#define STANZA_NAME_INVITE "invite"
|
||||
#define STANZA_NAME_REASON "reason"
|
||||
|
||||
#define STANZA_TYPE_CHAT "chat"
|
||||
#define STANZA_TYPE_GROUPCHAT "groupchat"
|
||||
@ -79,6 +81,7 @@
|
||||
#define STANZA_ATTR_VAR "var"
|
||||
#define STANZA_ATTR_HASH "hash"
|
||||
#define STANZA_ATTR_CATEGORY "category"
|
||||
#define STANZA_ATTR_REASON "reason"
|
||||
|
||||
#define STANZA_TEXT_AWAY "away"
|
||||
#define STANZA_TEXT_DND "dnd"
|
||||
@ -94,6 +97,7 @@
|
||||
#define STANZA_NS_LASTACTIVITY "jabber:iq:last"
|
||||
#define STANZA_NS_DATA "jabber:x:data"
|
||||
#define STANZA_NS_VERSION "jabber:iq:version"
|
||||
#define STANZA_NS_CONFERENCE "jabber:x:conference"
|
||||
|
||||
#define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
|
||||
|
||||
|
@ -46,6 +46,11 @@ typedef enum {
|
||||
PRESENCE_UNSUBSCRIBED
|
||||
} jabber_subscr_t;
|
||||
|
||||
typedef enum {
|
||||
INVITE_DIRECT,
|
||||
INVITE_MEDIATED
|
||||
} jabber_invite_t;
|
||||
|
||||
typedef struct capabilities_t {
|
||||
char *category;
|
||||
char *type;
|
||||
|
Loading…
Reference in New Issue
Block a user