mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Check for groupchat
This commit is contained in:
parent
a141a997f8
commit
0deba9e13e
182
src/jabber.c
182
src/jabber.c
@ -34,6 +34,9 @@
|
|||||||
#include "profanity.h"
|
#include "profanity.h"
|
||||||
#include "room_chat.h"
|
#include "room_chat.h"
|
||||||
|
|
||||||
|
// TODO REMOVE
|
||||||
|
#include "ui.h"
|
||||||
|
|
||||||
#define PING_INTERVAL 120000 // 2 minutes
|
#define PING_INTERVAL 120000 // 2 minutes
|
||||||
|
|
||||||
static struct _jabber_conn_t {
|
static struct _jabber_conn_t {
|
||||||
@ -294,7 +297,7 @@ jabber_join(const char * const room_jid, const char * const nick)
|
|||||||
xmpp_send(jabber_conn.conn, presence);
|
xmpp_send(jabber_conn.conn, presence);
|
||||||
xmpp_stanza_release(presence);
|
xmpp_stanza_release(presence);
|
||||||
|
|
||||||
room_join(room_join, nick);
|
room_join(room_jid, nick);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -397,83 +400,87 @@ _message_handler(xmpp_conn_t * const conn,
|
|||||||
type = xmpp_stanza_get_attribute(stanza, "type");
|
type = xmpp_stanza_get_attribute(stanza, "type");
|
||||||
from = xmpp_stanza_get_attribute(stanza, "from");
|
from = xmpp_stanza_get_attribute(stanza, "from");
|
||||||
|
|
||||||
if (type != NULL) {
|
if (room_jid_is_room_chat(from)) {
|
||||||
if (strcmp(type, "error") == 0) {
|
cons_show("CHAT ROOM MESSAGE RECIEVED");
|
||||||
char *err_msg = NULL;
|
} else {
|
||||||
xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, "error");
|
|
||||||
if (error == NULL) {
|
if (type != NULL) {
|
||||||
log_debug("error message without <error/> received");
|
if (strcmp(type, "error") == 0) {
|
||||||
return 1;
|
char *err_msg = NULL;
|
||||||
} else {
|
xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, "error");
|
||||||
xmpp_stanza_t *err_cond = xmpp_stanza_get_children(error);
|
if (error == NULL) {
|
||||||
if (err_cond == NULL) {
|
log_debug("error message without <error/> received");
|
||||||
log_debug("error message without <defined-condition/> received");
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
err_msg = xmpp_stanza_get_name(err_cond);
|
xmpp_stanza_t *err_cond = xmpp_stanza_get_children(error);
|
||||||
|
if (err_cond == NULL) {
|
||||||
|
log_debug("error message without <defined-condition/> received");
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
err_msg = xmpp_stanza_get_name(err_cond);
|
||||||
|
}
|
||||||
|
// TODO: process 'type' attribute from <error/> [RFC6120, 8.3.2]
|
||||||
}
|
}
|
||||||
// TODO: process 'type' attribute from <error/> [RFC6120, 8.3.2]
|
prof_handle_error_message(from, err_msg);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
prof_handle_error_message(from, err_msg);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
char from_cpy[strlen(from) + 1];
|
||||||
|
strcpy(from_cpy, from);
|
||||||
|
char *short_from = strtok(from_cpy, "/");
|
||||||
|
|
||||||
char from_cpy[strlen(from) + 1];
|
//determine chatstate support of recipient
|
||||||
strcpy(from_cpy, from);
|
gboolean recipient_supports = FALSE;
|
||||||
char *short_from = strtok(from_cpy, "/");
|
|
||||||
|
|
||||||
//determine chatstate support of recipient
|
if ((xmpp_stanza_get_child_by_name(stanza, "active") != NULL) ||
|
||||||
gboolean recipient_supports = FALSE;
|
(xmpp_stanza_get_child_by_name(stanza, "composing") != NULL) ||
|
||||||
|
(xmpp_stanza_get_child_by_name(stanza, "paused") != NULL) ||
|
||||||
|
(xmpp_stanza_get_child_by_name(stanza, "gone") != NULL) ||
|
||||||
|
(xmpp_stanza_get_child_by_name(stanza, "inactive") != NULL)) {
|
||||||
|
recipient_supports = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
if ((xmpp_stanza_get_child_by_name(stanza, "active") != NULL) ||
|
// create of update session
|
||||||
(xmpp_stanza_get_child_by_name(stanza, "composing") != NULL) ||
|
if (!chat_session_exists(short_from)) {
|
||||||
(xmpp_stanza_get_child_by_name(stanza, "paused") != NULL) ||
|
chat_session_start(short_from, recipient_supports);
|
||||||
(xmpp_stanza_get_child_by_name(stanza, "gone") != NULL) ||
|
|
||||||
(xmpp_stanza_get_child_by_name(stanza, "inactive") != NULL)) {
|
|
||||||
recipient_supports = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create of update session
|
|
||||||
if (!chat_session_exists(short_from)) {
|
|
||||||
chat_session_start(short_from, recipient_supports);
|
|
||||||
} else {
|
|
||||||
chat_session_set_recipient_supports(short_from, recipient_supports);
|
|
||||||
}
|
|
||||||
|
|
||||||
// deal with chat states
|
|
||||||
if (recipient_supports) {
|
|
||||||
|
|
||||||
// handle <composing/>
|
|
||||||
if (xmpp_stanza_get_child_by_name(stanza, "composing") != NULL) {
|
|
||||||
if (prefs_get_notify_typing() || prefs_get_intype()) {
|
|
||||||
prof_handle_typing(short_from);
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle <paused/>
|
|
||||||
} else if (xmpp_stanza_get_child_by_name(stanza, "paused") != NULL) {
|
|
||||||
// do something
|
|
||||||
|
|
||||||
// handle <inactive/>
|
|
||||||
} else if (xmpp_stanza_get_child_by_name(stanza, "inactive") != NULL) {
|
|
||||||
// do something
|
|
||||||
|
|
||||||
// handle <gone/>
|
|
||||||
} else if (xmpp_stanza_get_child_by_name(stanza, "gone") != NULL) {
|
|
||||||
prof_handle_gone(short_from);
|
|
||||||
|
|
||||||
// handle <active/>
|
|
||||||
} else {
|
} else {
|
||||||
// do something
|
chat_session_set_recipient_supports(short_from, recipient_supports);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// check for and deal with message
|
// deal with chat states
|
||||||
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, "body");
|
if (recipient_supports) {
|
||||||
if (body != NULL) {
|
|
||||||
char *message = xmpp_stanza_get_text(body);
|
// handle <composing/>
|
||||||
prof_handle_incoming_message(short_from, message);
|
if (xmpp_stanza_get_child_by_name(stanza, "composing") != NULL) {
|
||||||
|
if (prefs_get_notify_typing() || prefs_get_intype()) {
|
||||||
|
prof_handle_typing(short_from);
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle <paused/>
|
||||||
|
} else if (xmpp_stanza_get_child_by_name(stanza, "paused") != NULL) {
|
||||||
|
// do something
|
||||||
|
|
||||||
|
// handle <inactive/>
|
||||||
|
} else if (xmpp_stanza_get_child_by_name(stanza, "inactive") != NULL) {
|
||||||
|
// do something
|
||||||
|
|
||||||
|
// handle <gone/>
|
||||||
|
} else if (xmpp_stanza_get_child_by_name(stanza, "gone") != NULL) {
|
||||||
|
prof_handle_gone(short_from);
|
||||||
|
|
||||||
|
// handle <active/>
|
||||||
|
} else {
|
||||||
|
// do something
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for and deal with message
|
||||||
|
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, "body");
|
||||||
|
if (body != NULL) {
|
||||||
|
char *message = xmpp_stanza_get_text(body);
|
||||||
|
prof_handle_incoming_message(short_from, message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -596,30 +603,35 @@ _presence_handler(xmpp_conn_t * const conn,
|
|||||||
char *short_jid = strtok(jid_cpy, "/");
|
char *short_jid = strtok(jid_cpy, "/");
|
||||||
|
|
||||||
char *from = xmpp_stanza_get_attribute(stanza, "from");
|
char *from = xmpp_stanza_get_attribute(stanza, "from");
|
||||||
char *short_from = strtok(from, "/");
|
|
||||||
char *type = xmpp_stanza_get_attribute(stanza, "type");
|
|
||||||
char *show_str, *status_str;
|
|
||||||
|
|
||||||
xmpp_stanza_t *status = xmpp_stanza_get_child_by_name(stanza, "status");
|
if (room_jid_is_room_chat(from)) {
|
||||||
if (status != NULL)
|
cons_show("CHAT ROOM PRESENCE RECIEVED");
|
||||||
status_str = xmpp_stanza_get_text(status);
|
|
||||||
else
|
|
||||||
status_str = NULL;
|
|
||||||
|
|
||||||
if ((type != NULL) && (strcmp(type, "unavailable") == 0)) {
|
|
||||||
if (strcmp(short_jid, short_from) !=0) {
|
|
||||||
prof_handle_contact_offline(short_from, "offline", status_str);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
char *short_from = strtok(from, "/");
|
||||||
|
char *type = xmpp_stanza_get_attribute(stanza, "type");
|
||||||
|
char *show_str, *status_str;
|
||||||
|
|
||||||
xmpp_stanza_t *show = xmpp_stanza_get_child_by_name(stanza, "show");
|
xmpp_stanza_t *status = xmpp_stanza_get_child_by_name(stanza, "status");
|
||||||
if (show != NULL)
|
if (status != NULL)
|
||||||
show_str = xmpp_stanza_get_text(show);
|
status_str = xmpp_stanza_get_text(status);
|
||||||
else
|
else
|
||||||
show_str = "online";
|
status_str = NULL;
|
||||||
|
|
||||||
if (strcmp(short_jid, short_from) !=0) {
|
if ((type != NULL) && (strcmp(type, "unavailable") == 0)) {
|
||||||
prof_handle_contact_online(short_from, show_str, status_str);
|
if (strcmp(short_jid, short_from) !=0) {
|
||||||
|
prof_handle_contact_offline(short_from, "offline", status_str);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
xmpp_stanza_t *show = xmpp_stanza_get_child_by_name(stanza, "show");
|
||||||
|
if (show != NULL)
|
||||||
|
show_str = xmpp_stanza_get_text(show);
|
||||||
|
else
|
||||||
|
show_str = "online";
|
||||||
|
|
||||||
|
if (strcmp(short_jid, short_from) !=0) {
|
||||||
|
prof_handle_contact_online(short_from, show_str, status_str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,3 +42,19 @@ room_join(const char * const jid, const char * const nick)
|
|||||||
rooms = g_slist_append(rooms, new_room);
|
rooms = g_slist_append(rooms, new_room);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
room_jid_is_room_chat(const char * const jid)
|
||||||
|
{
|
||||||
|
GSList *current = rooms;
|
||||||
|
while (current != NULL) {
|
||||||
|
muc_room *room = current->data;
|
||||||
|
if (g_str_has_prefix(jid, room->jid)) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
current = g_slist_next(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -20,4 +20,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
void room_join(const char * const jid, const char * const nick);
|
void room_join(const char * const jid, const char * const nick);
|
||||||
|
gboolean room_jid_is_room_chat(const char * const jid);
|
||||||
|
Loading…
Reference in New Issue
Block a user