Debian Codegraph @

src/core/xep/chatstates.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2007,2008,2009 Colin DIDIER
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 /*
19 * XEP-0085: Chat State Notifications
20 */
21
22 #include "module.h"
23 #include "signals.h"
24
25 #include "xmpp-servers.h"
26 #include "disco.h"
27
28 #define XMLNS_CHATSTATES "http://jabber.org/protocol/chatstates"
29
30 static void
31 sig_recv_message(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type,
32 const char *id, const char *from, const char *to)
33 {
34 if ((type != LM_MESSAGE_SUB_TYPE_NOT_SET
35 && type != LM_MESSAGE_SUB_TYPE_HEADLINE
36 && type != LM_MESSAGE_SUB_TYPE_NORMAL
37 && type != LM_MESSAGE_SUB_TYPE_CHAT)
38 || server->ischannel(SERVER(server), from))
39 return;
40 if (lm_find_node(lmsg->node, "composing", XMLNS,
41 XMLNS_CHATSTATES) != NULL) {
42 signal_emit("xmpp composing show", 2, server, from);
43 } else if (lm_find_node(lmsg->node, "active", XMLNS,
44 XMLNS_CHATSTATES) != NULL
45 || lm_find_node(lmsg->node, "paused", XMLNS,
46 XMLNS_CHATSTATES) != NULL)
47 signal_emit("xmpp composing hide", 2, server, from);
48 }
49
50 void
51 chatstates_init(void)
52 {
53 disco_add_feature(XMLNS_CHATSTATES);
54 signal_add("xmpp recv message", sig_recv_message);
55 }
56
57 void
58 chatstates_deinit(void)
59 {
60 signal_remove("xmpp recv message", sig_recv_message);
61 }