# HG changeset patch # User Mikael Berthe # Date 1270329691 -7200 # Node ID e9bb68c35bf3bb4a8388dcf8275f6d3497c927d7 # Parent 1867a9047524bcee7757b707fa73a368454a5246 [killpresence] Add command killchatstates diff -r 1867a9047524 -r e9bb68c35bf3 killpresence/killpresence.c --- a/killpresence/killpresence.c Sat Apr 03 20:32:32 2010 +0200 +++ b/killpresence/killpresence.c Sat Apr 03 23:21:31 2010 +0200 @@ -4,6 +4,11 @@ Module "killpresence" -- Ignore current presence of an item + * /killpresence fulljid + Ignore current presence for the provided JID + * /killchatstates fulljid + Reset chat states for the provided JID + This module is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or @@ -68,12 +73,79 @@ g_free(jid_utf8); } +#if defined XEP0022 || defined XEP0085 +static void reset_chat_states(const char *fulljid) +{ + char *rname, *barejid; + GSList *sl_buddy; + struct xep0085 *xep85; + struct xep0022 *xep22; + + rname = strchr(fulljid, JID_RESOURCE_SEPARATOR); + if (!rname++) + return; + + barejid = jidtodisp(fulljid); + sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER); + g_free(barejid); + + if (!sl_buddy) + return; + + xep85 = buddy_resource_xep85(sl_buddy->data, rname); + xep22 = buddy_resource_xep22(sl_buddy->data, rname); + + // Reset Chat States (0085) + if (xep85) { + if (xep85->support == CHATSTATES_SUPPORT_PROBED) + xep85->support = CHATSTATES_SUPPORT_UNKNOWN; + xep85->last_state_rcvd = ROSTER_EVENT_NONE; + } + // Reset Message Events (0022) + if (xep22) { + if (xep22->support == CHATSTATES_SUPPORT_PROBED) + xep22->support = CHATSTATES_SUPPORT_UNKNOWN; + xep22->last_state_rcvd = ROSTER_EVENT_NONE; + g_free(xep22->last_msgid_sent); + g_free(xep22->last_msgid_rcvd); + xep22->last_msgid_sent = NULL; + xep22->last_msgid_rcvd = NULL; + } + + // Finally reset the roster hint for the UI + buddy_resource_setevents(sl_buddy->data, rname, ROSTER_EVENT_NONE); + update_roster = TRUE; +} +#endif + +static void do_killchatstates(char *args) +{ +#if defined XEP0022 || defined XEP0085 + char *jid_utf8; + + if (!args || !*args) + return; + + jid_utf8 = to_utf8(args); + if (!jid_utf8) + return; + + reset_chat_states(jid_utf8); + g_free(jid_utf8); +#else + scr_log_print(LPRINT_NORMAL, "No Chat State support."); +#endif +} + + /* Initialization */ static void killpresence_init(void) { /* Add command */ cmd_add("killpresence", "Ignore presence", COMPL_JID, 0, do_killpresence, NULL); + cmd_add("killchatstates", "Reset chatstates", COMPL_JID, 0, + do_killchatstates, NULL); } /* Uninitialization */ @@ -81,6 +153,7 @@ { /* Unregister command */ cmd_del("killpresence"); + cmd_del("killchatstates"); } /* vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2: For Vim users... */