mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Support legacy delayed delivery (XEP-0091) as well as XEP-0203
This commit is contained in:
parent
4a2004e5a8
commit
a847ad5603
16
src/jabber.c
16
src/jabber.c
@ -550,10 +550,11 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// determine if the notifications happened whilst offline
|
// determine if the notifications happened whilst offline
|
||||||
xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY);
|
GTimeVal tv_stamp;
|
||||||
|
gboolean delayed = stanza_get_delay(stanza, &tv_stamp);
|
||||||
|
|
||||||
// deal with chat states if recipient supports them
|
// deal with chat states if recipient supports them
|
||||||
if (recipient_supports && (delay == NULL)) {
|
if (recipient_supports && (!delayed)) {
|
||||||
if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL) {
|
if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL) {
|
||||||
if (prefs_get_notify_typing() || prefs_get_intype()) {
|
if (prefs_get_notify_typing() || prefs_get_intype()) {
|
||||||
prof_handle_typing(jid);
|
prof_handle_typing(jid);
|
||||||
@ -573,17 +574,8 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
|
|||||||
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
||||||
if (body != NULL) {
|
if (body != NULL) {
|
||||||
char *message = xmpp_stanza_get_text(body);
|
char *message = xmpp_stanza_get_text(body);
|
||||||
if (delay != NULL) {
|
if (delayed) {
|
||||||
char *utc_stamp = xmpp_stanza_get_attribute(delay, STANZA_ATTR_STAMP);
|
|
||||||
GTimeVal tv_stamp;
|
|
||||||
|
|
||||||
if (g_time_val_from_iso8601(utc_stamp, &tv_stamp)) {
|
|
||||||
if (message != NULL) {
|
|
||||||
prof_handle_delayed_message(jid, message, tv_stamp, priv);
|
prof_handle_delayed_message(jid, message, tv_stamp, priv);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log_error("Couldn't parse datetime string of historic message: %s", utc_stamp);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
prof_handle_incoming_message(jid, message, priv);
|
prof_handle_incoming_message(jid, message, priv);
|
||||||
}
|
}
|
||||||
|
32
src/stanza.c
32
src/stanza.c
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
#include <strophe.h>
|
#include <strophe.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -193,3 +194,34 @@ stanza_create_ping_iq(xmpp_ctx_t *ctx)
|
|||||||
|
|
||||||
return iq;
|
return iq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp)
|
||||||
|
{
|
||||||
|
// first check for XEP-0203 delayed delivery
|
||||||
|
xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY);
|
||||||
|
if (delay != NULL) {
|
||||||
|
char *xmlns = xmpp_stanza_get_attribute(delay, STANZA_ATTR_XMLNS);
|
||||||
|
if ((xmlns != NULL) && (strcmp(xmlns, "urn:xmpp:delay") == 0)) {
|
||||||
|
char *stamp = xmpp_stanza_get_attribute(delay, STANZA_ATTR_STAMP);
|
||||||
|
if ((stamp != NULL) && (g_time_val_from_iso8601(stamp, tv_stamp))) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise check for XEP-0091 legacy delayed delivery
|
||||||
|
// stanp format : CCYYMMDDThh:mm:ss
|
||||||
|
xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_X);
|
||||||
|
if (x != NULL) {
|
||||||
|
char *xmlns = xmpp_stanza_get_attribute(x, STANZA_ATTR_XMLNS);
|
||||||
|
if ((xmlns != NULL) && (strcmp(xmlns, "jabber:x:delay") == 0)) {
|
||||||
|
char *stamp = xmpp_stanza_get_attribute(x, STANZA_ATTR_STAMP);
|
||||||
|
if ((stamp != NULL) && (g_time_val_from_iso8601(stamp, tv_stamp))) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#ifndef STANZA_H
|
#ifndef STANZA_H
|
||||||
#define STANZA_H
|
#define STANZA_H
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
#include <strophe.h>
|
#include <strophe.h>
|
||||||
|
|
||||||
#define STANZA_NAME_ACTIVE "active"
|
#define STANZA_NAME_ACTIVE "active"
|
||||||
@ -62,6 +63,7 @@
|
|||||||
#define STANZA_ATTR_JID "jid"
|
#define STANZA_ATTR_JID "jid"
|
||||||
#define STANZA_ATTR_NAME "name"
|
#define STANZA_ATTR_NAME "name"
|
||||||
#define STANZA_ATTR_SUBSCRIPTION "subscription"
|
#define STANZA_ATTR_SUBSCRIPTION "subscription"
|
||||||
|
#define STANZA_ATTR_XMLNS "xmlns"
|
||||||
|
|
||||||
#define STANZA_TEXT_AWAY "away"
|
#define STANZA_TEXT_AWAY "away"
|
||||||
#define STANZA_TEXT_DND "dnd"
|
#define STANZA_TEXT_DND "dnd"
|
||||||
@ -94,4 +96,6 @@ xmpp_stanza_t* stanza_create_ping_iq(xmpp_ctx_t *ctx);
|
|||||||
|
|
||||||
gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza);
|
gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza);
|
||||||
|
|
||||||
|
gboolean stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user