113
|
1 |
/* |
|
2 |
* hooks.c -- Hooks layer |
|
3 |
* |
|
4 |
* Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net> |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License as published by |
|
8 |
* the Free Software Foundation; either version 2 of the License, or (at |
|
9 |
* your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but |
|
12 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
* General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
19 |
* USA |
|
20 |
*/ |
|
21 |
|
|
22 |
#include <screen.h> |
|
23 |
|
|
24 |
#include "hooks.h" |
|
25 |
#include "roster.h" |
|
26 |
#include "histolog.h" |
115
|
27 |
#include "utf8.h" |
113
|
28 |
|
|
29 |
|
|
30 |
inline void hk_message_in(const char *jid, time_t timestamp, const char *msg) |
|
31 |
{ |
115
|
32 |
char *buffer = utf8_decode(msg); |
141
|
33 |
int new_guy = FALSE; |
|
34 |
|
|
35 |
// If this user isn't in the roster, we add it |
|
36 |
if (!roster_exists(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT)) { |
|
37 |
roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER); |
|
38 |
new_guy = TRUE; |
|
39 |
} |
|
40 |
|
115
|
41 |
scr_WriteIncomingMessage(jid, buffer); |
|
42 |
hlog_write_message(jid, timestamp, FALSE, buffer); |
|
43 |
free(buffer); |
146
|
44 |
// We need to rebuild the list if the sender is unknown or |
|
45 |
// if the sender is offline/invisible and hide_offline_buddies is set |
|
46 |
if (new_guy || |
|
47 |
(roster_getstatus(jid) == offline && buddylist_get_hide_offline_buddies())) |
|
48 |
{ |
141
|
49 |
buddylist_build(); |
|
50 |
update_roster = TRUE; |
|
51 |
} |
113
|
52 |
} |
|
53 |
|
|
54 |
inline void hk_message_out(const char *jid, time_t timestamp, const char *msg) |
|
55 |
{ |
|
56 |
scr_WriteOutgoingMessage(jid, msg); |
|
57 |
hlog_write_message(jid, timestamp, TRUE, msg); |
|
58 |
} |
|
59 |
|
|
60 |
inline void hk_statuschange(const char *jid, time_t timestamp, |
|
61 |
enum imstatus status) |
|
62 |
{ |
|
63 |
scr_LogPrint("Buddy status has changed: [%c>%c] <%s>", |
|
64 |
imstatus2char[roster_getstatus(jid)], imstatus2char[status], jid); |
|
65 |
roster_setstatus(jid, status); |
120
|
66 |
buddylist_build(); |
|
67 |
scr_DrawRoster(); |
113
|
68 |
hlog_write_status(jid, 0, status); |
|
69 |
} |
|
70 |
|
116
|
71 |
inline void hk_mystatuschange(time_t timestamp, |
|
72 |
enum imstatus old_status, enum imstatus new_status) |
|
73 |
{ |
|
74 |
if (old_status == new_status) |
|
75 |
return; |
|
76 |
|
118
|
77 |
scr_LogPrint("Your status has changed: [%c>%c]", |
116
|
78 |
imstatus2char[old_status], imstatus2char[new_status]); |
|
79 |
//hlog_write_status(NULL, 0, status); |
|
80 |
} |
|
81 |
|