Debian Codegraph @

src/fe-common/xep/fe-carbons.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 /*
2 * Copyright (C) 2017 Stephen Paul Weber
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 #include "module.h"
19 #include "levels.h"
20 #include "module-formats.h"
21 #include "printtext.h"
22 #include "settings.h"
23 #include "signals.h"
24 #include "window-items.h"
25 #include "fe-messages.h"
26 #include "fe-queries.h"
27 #include "fe-common/core/module-formats.h"
28 #include "fe-common/core/fe-messages.h"
29 #include "fe-common/irc/module-formats.h"
30
31 #include "xmpp-servers.h"
32 #include "rosters-tools.h"
33 #include "xep/muc.h"
34
35 static void
36 sig_message_carbons_sent(SERVER_REC *server, const char *msg, const char *nick,
37 const char *target, gpointer gpointer_type)
38 {
39 void *item;
40 char *freemsg = NULL;
41 int level, type;
42
43 g_return_if_fail(server != NULL);
44 g_return_if_fail(msg != NULL);
45 g_return_if_fail(nick != NULL);
46 g_return_if_fail(target != NULL);
47
48 type = GPOINTER_TO_INT(gpointer_type);
49 level = MSGLEVEL_NO_ACT | MSGLEVEL_NOHILIGHT
50 | (type == SEND_TARGET_CHANNEL ? MSGLEVEL_PUBLIC : MSGLEVEL_MSGS);
51 item = type == SEND_TARGET_CHANNEL ?
52 (void *)get_muc((XMPP_SERVER_REC *)server, target) :
53 query_find(server, target);
54
55 if (settings_get_bool("emphasis"))
56 msg = freemsg = expand_emphasis(item, msg);
57
58 if (type == SEND_TARGET_CHANNEL) {
59 char *nickmode = channel_get_nickmode(item, nick);
60 printformat_module(CORE_MODULE_NAME, server, target,
61 level, TXT_OWN_MSG_CHANNEL, nick, target, msg, nickmode);
62 } else if(item) { // If no query, why do we want to see carbons?
63 printformat_module(CORE_MODULE_NAME, server, target,
64 level, TXT_OWN_MSG_PRIVATE_QUERY, target, msg, nick);
65 }
66
67 g_free_not_null(freemsg);
68 }
69
70 void
71 fe_carbons_init(void)
72 {
73 signal_add("message xmpp carbons sent", sig_message_carbons_sent);
74 }
75
76 void
77 fe_carbons_deinit(void)
78 {
79 signal_remove("message xmpp carbons sent", sig_message_carbons_sent);
80 }