Changeset fb2338d


Ignore:
Timestamp:
2015-10-30T10:28:32Z (8 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
884577f
Parents:
345577b
git-author:
dequis <dx@…> (13-09-15 04:45:43)
git-committer:
dequis <dx@…> (30-10-15 10:28:32)
Message:

jabber: Self message handling (echo removal) in MUCs

XMPP MUCs always echo own messages, and send messages from other
clients. So, we must display everything except the messages we just
sent.

This implementation uses the jabber stanza cache to add an ID to the
message and attach it to a callback which always returns XT_ABORT.
This way, if we do get the echo, the message packet handler can call
jabber_cache_handle_packet(), and if it returns XT_ABORT, it can skip
that particular message.

Every other message that looks like it comes from our own JID and wasn't
handled by the cache will be displayed, with the OPT_SELFMESSAGE flag

Stanza cache entries expire after some time, so it's not a problem if
the server doesn't echo messages for some reason.

I actually wrote this forever ago, for hipchat, but it works the same
way for standard XMPP MUCs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/conference.c

    r345577b rfb2338d  
    2626
    2727static xt_status jabber_chat_join_failed(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
     28static xt_status jabber_chat_self_message(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
    2829
    2930struct groupchat *jabber_chat_join(struct im_connection *ic, const char *room, const char *nick, const char *password)
     
    127128}
    128129
     130static xt_status jabber_chat_self_message(struct im_connection *ic, struct xt_node *node, struct xt_node *orig)
     131{
     132        /* This is a self message sent by this bitlbee - just drop it */
     133        return XT_ABORT;
     134}
     135
    129136struct groupchat *jabber_chat_by_jid(struct im_connection *ic, const char *name)
    130137{
     
    171178        node = jabber_make_packet("message", "groupchat", jc->name, node);
    172179
    173         if (!jabber_write_packet(ic, node)) {
    174                 xt_free_node(node);
    175                 return 0;
    176         }
    177         xt_free_node(node);
    178 
    179         return 1;
     180        jabber_cache_add(ic, node, jabber_chat_self_message);
     181
     182        return !jabber_write_packet(ic, node);
    180183}
    181184
     
    403406        char *final_from = NULL;
    404407        char *bare_jid = NULL;
     408        guint32 flags = 0;
    405409
    406410        from = (bud) ? bud->full_jid : xt_find_attr(node, "from");
     
    466470                imcb_chat_log(chat, "From conference server: %s", body->text);
    467471                return;
    468         } else if (jc && jc->flags & JCFLAG_MESSAGE_SENT && bud == jc->me) {
    469                 /* exclude self-messages since they would get filtered out
    470                  * but not the ones in the backlog */
     472        } else if (jc && jc->flags & JCFLAG_MESSAGE_SENT && bud == jc->me &&
     473                   (jabber_cache_handle_packet(ic, node) == XT_ABORT)) {
     474                /* Self message marked by this bitlbee, don't show it */
    471475                return;
    472476        }
    473477
    474         if (bud && jc && bud != jc->me) {
     478        if (bud) {
    475479                bare_jid = jabber_get_bare_jid(bud->ext_jid ? bud->ext_jid : bud->full_jid);
    476480                final_from = bare_jid;
     481                flags = (bud == jc->me) ? OPT_SELFMESSAGE : 0;
    477482        } else {
    478483                final_from = nick;
    479484        }
    480485
    481         imcb_chat_msg(chat, final_from, body->text, 0, jabber_get_timestamp(node));
     486        imcb_chat_msg(chat, final_from, body->text, flags, jabber_get_timestamp(node));
    482487
    483488        g_free(bare_jid);
Note: See TracChangeset for help on using the changeset viewer.