1 /* |
1 /* |
2 * Copyright (C) 2010 Mikael Berthe <mikael@lilotux.net> |
2 * Copyright (C) 2010 Mikael Berthe <mikael@lilotux.net> |
3 |
3 |
4 |
4 |
5 Module "killpresence" -- Ignore current presence of an item |
5 Module "killpresence" -- Ignore current presence of an item |
|
6 |
|
7 * /killpresence fulljid |
|
8 Ignore current presence for the provided JID |
|
9 * /killchatstates fulljid |
|
10 Reset chat states for the provided JID |
6 |
11 |
7 This module is free software: you can redistribute it and/or modify |
12 This module is free software: you can redistribute it and/or modify |
8 it under the terms of the GNU General Public License as published by |
13 it under the terms of the GNU General Public License as published by |
9 the Free Software Foundation, either version 2 of the License, or |
14 the Free Software Foundation, either version 2 of the License, or |
10 (at your option) any later version. |
15 (at your option) any later version. |
66 scr_draw_roster(); |
71 scr_draw_roster(); |
67 |
72 |
68 g_free(jid_utf8); |
73 g_free(jid_utf8); |
69 } |
74 } |
70 |
75 |
|
76 #if defined XEP0022 || defined XEP0085 |
|
77 static void reset_chat_states(const char *fulljid) |
|
78 { |
|
79 char *rname, *barejid; |
|
80 GSList *sl_buddy; |
|
81 struct xep0085 *xep85; |
|
82 struct xep0022 *xep22; |
|
83 |
|
84 rname = strchr(fulljid, JID_RESOURCE_SEPARATOR); |
|
85 if (!rname++) |
|
86 return; |
|
87 |
|
88 barejid = jidtodisp(fulljid); |
|
89 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER); |
|
90 g_free(barejid); |
|
91 |
|
92 if (!sl_buddy) |
|
93 return; |
|
94 |
|
95 xep85 = buddy_resource_xep85(sl_buddy->data, rname); |
|
96 xep22 = buddy_resource_xep22(sl_buddy->data, rname); |
|
97 |
|
98 // Reset Chat States (0085) |
|
99 if (xep85) { |
|
100 if (xep85->support == CHATSTATES_SUPPORT_PROBED) |
|
101 xep85->support = CHATSTATES_SUPPORT_UNKNOWN; |
|
102 xep85->last_state_rcvd = ROSTER_EVENT_NONE; |
|
103 } |
|
104 // Reset Message Events (0022) |
|
105 if (xep22) { |
|
106 if (xep22->support == CHATSTATES_SUPPORT_PROBED) |
|
107 xep22->support = CHATSTATES_SUPPORT_UNKNOWN; |
|
108 xep22->last_state_rcvd = ROSTER_EVENT_NONE; |
|
109 g_free(xep22->last_msgid_sent); |
|
110 g_free(xep22->last_msgid_rcvd); |
|
111 xep22->last_msgid_sent = NULL; |
|
112 xep22->last_msgid_rcvd = NULL; |
|
113 } |
|
114 |
|
115 // Finally reset the roster hint for the UI |
|
116 buddy_resource_setevents(sl_buddy->data, rname, ROSTER_EVENT_NONE); |
|
117 update_roster = TRUE; |
|
118 } |
|
119 #endif |
|
120 |
|
121 static void do_killchatstates(char *args) |
|
122 { |
|
123 #if defined XEP0022 || defined XEP0085 |
|
124 char *jid_utf8; |
|
125 |
|
126 if (!args || !*args) |
|
127 return; |
|
128 |
|
129 jid_utf8 = to_utf8(args); |
|
130 if (!jid_utf8) |
|
131 return; |
|
132 |
|
133 reset_chat_states(jid_utf8); |
|
134 g_free(jid_utf8); |
|
135 #else |
|
136 scr_log_print(LPRINT_NORMAL, "No Chat State support."); |
|
137 #endif |
|
138 } |
|
139 |
|
140 |
71 /* Initialization */ |
141 /* Initialization */ |
72 static void killpresence_init(void) |
142 static void killpresence_init(void) |
73 { |
143 { |
74 /* Add command */ |
144 /* Add command */ |
75 cmd_add("killpresence", "Ignore presence", COMPL_JID, 0, |
145 cmd_add("killpresence", "Ignore presence", COMPL_JID, 0, |
76 do_killpresence, NULL); |
146 do_killpresence, NULL); |
|
147 cmd_add("killchatstates", "Reset chatstates", COMPL_JID, 0, |
|
148 do_killchatstates, NULL); |
77 } |
149 } |
78 |
150 |
79 /* Uninitialization */ |
151 /* Uninitialization */ |
80 static void killpresence_uninit(void) |
152 static void killpresence_uninit(void) |
81 { |
153 { |
82 /* Unregister command */ |
154 /* Unregister command */ |
83 cmd_del("killpresence"); |
155 cmd_del("killpresence"); |
|
156 cmd_del("killchatstates"); |
84 } |
157 } |
85 |
158 |
86 /* vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2: For Vim users... */ |
159 /* vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2: For Vim users... */ |