6 |
6 |
7 This modules stores messages received in a MUC room while |
7 This modules stores messages received in a MUC room while |
8 you are away (or not available) if they contain your nickname. |
8 you are away (or not available) if they contain your nickname. |
9 When you're back, you can display them in the status window with |
9 When you're back, you can display them in the status window with |
10 the /lastmsg command. |
10 the /lastmsg command. |
11 Note that this module is dumb: if your nick is foo and somebody |
|
12 says "foobar" the message will be stored! |
|
13 |
11 |
14 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 |
15 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 |
16 the Free Software Foundation, either version 2 of the License, or |
14 the Free Software Foundation, either version 2 of the License, or |
17 (at your option) any later version. |
15 (at your option) any later version. |
26 */ |
24 */ |
27 |
25 |
28 #include <mcabber/modules.h> |
26 #include <mcabber/modules.h> |
29 #include <mcabber/commands.h> |
27 #include <mcabber/commands.h> |
30 #include <mcabber/hooks.h> |
28 #include <mcabber/hooks.h> |
31 #include <mcabber/xmpp.h> |
|
32 #include <mcabber/logprint.h> |
29 #include <mcabber/logprint.h> |
33 |
30 |
34 static void lastmsg_init(void); |
31 static void lastmsg_init(void); |
35 static void lastmsg_uninit(void); |
32 static void lastmsg_uninit(void); |
36 |
33 |
37 /* Module description */ |
34 /* Module description */ |
38 module_info_t info_lastmsg = { |
35 module_info_t info_lastmsg = { |
39 .branch = MCABBER_BRANCH, |
36 .branch = MCABBER_BRANCH, |
40 .api = MCABBER_API_VERSION, |
37 .api = MCABBER_API_VERSION, |
41 .version = "0.01", |
38 .version = "0.02", |
42 .description = "Add a command /lastmsg", |
39 .description = "Add a command /lastmsg", |
43 .requires = NULL, |
40 .requires = NULL, |
44 .init = lastmsg_init, |
41 .init = lastmsg_init, |
45 .uninit = lastmsg_uninit, |
42 .uninit = lastmsg_uninit, |
46 .next = NULL, |
43 .next = NULL, |
76 |
73 |
77 static void last_message_hh(guint32 hid, hk_arg_t *args, gpointer userdata) |
74 static void last_message_hh(guint32 hid, hk_arg_t *args, gpointer userdata) |
78 { |
75 { |
79 enum imstatus status; |
76 enum imstatus status; |
80 const gchar *bjid, *res, *msg; |
77 const gchar *bjid, *res, *msg; |
81 gboolean muc = FALSE; |
78 gboolean muc = FALSE, urgent = FALSE; |
82 |
79 |
83 status = xmpp_getstatus(); |
80 status = xmpp_getstatus(); |
84 |
81 |
85 if (status != notavail && status != away) |
82 if (status != notavail && status != away) |
86 return; |
83 return; |
96 else if (!g_strcmp0(args->name, "message")) |
93 else if (!g_strcmp0(args->name, "message")) |
97 msg = args->value; |
94 msg = args->value; |
98 else if (!g_strcmp0(args->name, "groupchat")) { |
95 else if (!g_strcmp0(args->name, "groupchat")) { |
99 if (!g_strcmp0(args->value, "true")) |
96 if (!g_strcmp0(args->value, "true")) |
100 muc = TRUE; |
97 muc = TRUE; |
|
98 } else if (!g_strcmp0(args->name, "urgent")) { |
|
99 if (!g_strcmp0(args->value, "true")) |
|
100 urgent = TRUE; |
101 } |
101 } |
102 } |
102 } |
103 |
103 |
104 if (muc && bjid && res && msg) { |
104 if (muc && urgent && bjid && res && msg) { |
105 GSList *room_elt; |
|
106 struct lastm_T *lastm_item; |
105 struct lastm_T *lastm_item; |
107 const gchar *mynick = NULL; |
|
108 |
|
109 room_elt = roster_find(bjid, jidsearch, ROSTER_TYPE_ROOM); |
|
110 if (room_elt) |
|
111 mynick = buddy_getnickname(room_elt->data); |
|
112 |
|
113 if (!mynick || !g_strcmp0(res, mynick)) |
|
114 return; |
|
115 |
|
116 if (!g_strstr_len(msg, -1, mynick)) |
|
117 return; |
|
118 |
106 |
119 lastm_item = g_new(struct lastm_T, 1); |
107 lastm_item = g_new(struct lastm_T, 1); |
120 lastm_item->mucname = g_strdup(bjid); |
108 lastm_item->mucname = g_strdup(bjid); |
121 lastm_item->nickname = g_strdup(res); |
109 lastm_item->nickname = g_strdup(res); |
122 lastm_item->msg = g_strdup(msg); |
110 lastm_item->msg = g_strdup(msg); |
153 |
141 |
154 hk_add_handler(last_message_hh, HOOK_MESSAGE_IN, NULL); |
142 hk_add_handler(last_message_hh, HOOK_MESSAGE_IN, NULL); |
155 hk_add_handler(last_status_hh, HOOK_MY_STATUS_CHANGE, NULL); |
143 hk_add_handler(last_status_hh, HOOK_MY_STATUS_CHANGE, NULL); |
156 } |
144 } |
157 |
145 |
158 /* Deinitialization */ |
146 /* Uninitialization */ |
159 static void lastmsg_uninit(void) |
147 static void lastmsg_uninit(void) |
160 { |
148 { |
161 /* Unregister command */ |
149 /* Unregister command */ |
162 cmd_del("lastmsg"); |
150 cmd_del("lastmsg"); |
163 hk_del_handler(last_message_hh, NULL); |
151 hk_del_handler(last_message_hh, NULL); |