From 13675fbf06a0d0fbae2b974596a0fb513ba22340 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 5 Jun 2019 09:33:10 +0200 Subject: Only print room history for new messages upon reconnect If re-establish a connection don't print the room history again. In case there there happened nothing at all since we got the room history on the last connection. And in case there were no new messages during the time we have been disconnected. Instead of printing the room history again we now print 'Re-established Connection'. This adds a bit of overhead since we save the timestamp upon every MUC message. See: https://github.com/profanity-im/profanity/issues/704 --- src/event/server_events.c | 32 +++++++++++++++++++++++++++++++- src/ui/window_list.c | 21 +++++++++++++++++++++ src/ui/window_list.h | 1 + 3 files changed, 53 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/event/server_events.c b/src/event/server_events.c index b76f7cfa..b496e3e2 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -66,6 +66,9 @@ #include "ui/ui.h" +gint _success_connections_counter = 0; +GDateTime *_last_muc_message; + void sv_ev_login_account_success(char *account_name, gboolean secured) { @@ -102,6 +105,15 @@ sv_ev_login_account_success(char *account_name, gboolean secured) log_info("%s logged in successfully", account->jid); + // if we have been connected before + if (_success_connections_counter > 0) + { + cons_show("Connection re-established."); + wins_reestablished_connection(); + } + + _success_connections_counter++; + if (account->startscript) { scripts_exec(account->startscript); } @@ -261,7 +273,19 @@ sv_ev_room_history(const char *const room_jid, const char *const nick, GDateTime *timestamp, const char *const message) { ProfMucWin *mucwin = wins_get_muc(room_jid); - if (mucwin) { + + // if this is the first successful connection + if (_success_connections_counter == 1) { + // save timestamp of last received muc message + // so we dont display, if there was no activity in channel, once we reconnect + if (_last_muc_message) { + g_date_time_unref(_last_muc_message); + } + _last_muc_message = g_date_time_new_now_local(); + } + + gboolean younger = g_date_time_compare(_last_muc_message, timestamp) < 0 ? TRUE : FALSE; + if (mucwin && (_success_connections_counter == 1 || younger )) { mucwin_history(mucwin, nick, timestamp, message); } } @@ -338,6 +362,12 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha } } + // save timestamp of last received muc message + if (_last_muc_message) { + g_date_time_unref(_last_muc_message); + } + _last_muc_message = g_date_time_new_now_local(); + if (prefs_do_room_notify(is_current, mucwin->roomjid, mynick, nick, new_message, mention, triggers != NULL)) { Jid *jidp = jid_create(mucwin->roomjid); notify_room_message(nick, jidp->localpart, num, new_message); diff --git a/src/ui/window_list.c b/src/ui/window_list.c index 43230b57..6e2f82dd 100644 --- a/src/ui/window_list.c +++ b/src/ui/window_list.c @@ -845,6 +845,27 @@ wins_lost_connection(void) g_list_free(values); } +void +wins_reestablished_connection(void) +{ + GList *values = g_hash_table_get_values(windows); + GList *curr = values; + + while (curr) { + ProfWin *window = curr->data; + if (window->type != WIN_CONSOLE) { + win_println(window, THEME_TEXT, '-', "Connection re-established."); + + // if current win, set current_win_dirty + if (wins_is_current(window)) { + win_update_virtual(window); + } + } + curr = g_list_next(curr); + } + g_list_free(values); +} + void wins_swap(int source_win, int target_win) { diff --git a/src/ui/window_list.h b/src/ui/window_list.h index 6045d349..c79e9dd7 100644 --- a/src/ui/window_list.h +++ b/src/ui/window_list.h @@ -83,6 +83,7 @@ void wins_resize_all(void); GSList* wins_get_chat_recipients(void); GSList* wins_get_prune_wins(void); void wins_lost_connection(void); +void wins_reestablished_connection(void); gboolean wins_tidy(void); GSList* wins_create_summary(gboolean unread); void wins_destroy(void); -- cgit 1.4.1-2-gfad0 le='Blame the previous revision' href='/akkartik/mu/blame/078emit-hex.subx?h=main&id=6a51218e12ce75e51301b834e1c48e86aefedc1e'>^
fd91f7f6 ^













71eb22a5 ^
fd91f7f6 ^



6070c23e ^
05dabd81 ^
fd91f7f6 ^



05dabd81 ^
fd91f7f6 ^






















7a583220 ^
fd91f7f6 ^












686a52bd ^
fd91f7f6 ^
686a52bd ^
fd91f7f6 ^










































686a52bd ^
fd91f7f6 ^
686a52bd ^
fd91f7f6 ^








































686a52bd ^
fd91f7f6 ^
686a52bd ^
fd91f7f6 ^








































686a52bd ^
fd91f7f6 ^
686a52bd ^
fd91f7f6 ^
































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241