about summary refs log tree commit diff stats
path: root/src/chat_session.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/chat_session.c')
-rw-r--r--src/chat_session.c236
1 files changed, 64 insertions, 172 deletions
diff --git a/src/chat_session.c b/src/chat_session.c
index 81240f8f..f615bded 100644
--- a/src/chat_session.c
+++ b/src/chat_session.c
@@ -57,7 +57,7 @@ typedef enum {
 typedef struct chat_session_t {
     char *barejid;
     char *resource;
-    gboolean recipient_supports;
+    gboolean supported;
     chat_state_t state;
     GTimer *active_timer;
     gboolean sent;
@@ -65,19 +65,9 @@ typedef struct chat_session_t {
 
 static GHashTable *sessions;
 
-static ChatSession* _chat_session_new(const char * const recipient, gboolean recipient_supports);
-static gboolean _chat_session_exists(const char * const recipient);
+static ChatSession* _chat_session_new(const char * const recipient, gboolean supported);
 static void _chat_session_set_composing(const char * const recipient);
-static void _chat_session_set_sent(const char * const recipient);
-static gboolean _chat_session_get_sent(const char * const recipient);
-static void _chat_session_end(const char * const recipient);
-static gboolean _chat_session_is_inactive(const char * const recipient);
 static void _chat_session_set_active(const char * const recipient);
-static gboolean _chat_session_is_paused(const char * const recipient);
-static gboolean _chat_session_is_gone(const char * const recipient);
-static void _chat_session_set_gone(const char * const recipient);
-static gboolean _chat_session_get_recipient_supports(const char * const recipient);
-static void _chat_session_set_recipient_supports(const char * const recipient, gboolean recipient_supports);
 static void _chat_session_free(ChatSession *session);
 
 void
@@ -95,11 +85,12 @@ chat_sessions_clear(void)
 }
 
 ChatSession*
-_chat_session_new(const char * const barejid, gboolean recipient_supports)
+_chat_session_new(const char * const barejid, gboolean supported)
 {
     ChatSession *new_session = malloc(sizeof(struct chat_session_t));
     new_session->barejid = strdup(barejid);
-    new_session->recipient_supports = recipient_supports;
+    new_session->resource = NULL;
+    new_session->supported = supported;
     new_session->state = CHAT_STATE_STARTED;
     new_session->active_timer = g_timer_new();
     new_session->sent = FALSE;
@@ -107,18 +98,6 @@ _chat_session_new(const char * const barejid, gboolean recipient_supports)
     return new_session;
 }
 
-static gboolean
-_chat_session_exists(const char * const recipient)
-{
-    ChatSession *session = g_hash_table_lookup(sessions, recipient);
-
-    if (session != NULL) {
-        return TRUE;
-    } else {
-        return FALSE;
-    }
-}
-
 static void
 _chat_session_set_composing(const char * const recipient)
 {
@@ -134,46 +113,6 @@ _chat_session_set_composing(const char * const recipient)
 }
 
 static void
-_chat_session_set_sent(const char * const recipient)
-{
-    ChatSession *session = g_hash_table_lookup(sessions, recipient);
-
-    if (session != NULL) {
-        session->sent = TRUE;
-    }
-}
-
-static gboolean
-_chat_session_get_sent(const char * const recipient)
-{
-    ChatSession *session = g_hash_table_lookup(sessions, recipient);
-
-    if (session == NULL) {
-        return FALSE;
-    } else {
-        return session->sent;
-    }
-}
-
-static void
-_chat_session_end(const char * const recipient)
-{
-    g_hash_table_remove(sessions, recipient);
-}
-
-static gboolean
-_chat_session_is_inactive(const char * const recipient)
-{
-    ChatSession *session = g_hash_table_lookup(sessions, recipient);
-
-    if (session == NULL) {
-        return FALSE;
-    } else {
-        return (session->state == CHAT_STATE_INACTIVE);
-    }
-}
-
-static void
 _chat_session_set_active(const char * const recipient)
 {
     ChatSession *session = g_hash_table_lookup(sessions, recipient);
@@ -185,73 +124,18 @@ _chat_session_set_active(const char * const recipient)
     }
 }
 
-static gboolean
-_chat_session_is_paused(const char * const recipient)
-{
-    ChatSession *session = g_hash_table_lookup(sessions, recipient);
-
-    if (session == NULL) {
-        return FALSE;
-    } else {
-        return (session->state == CHAT_STATE_PAUSED);
-    }
-}
-
-static gboolean
-_chat_session_is_gone(const char * const recipient)
-{
-    ChatSession *session = g_hash_table_lookup(sessions, recipient);
-
-    if (session == NULL) {
-        return FALSE;
-    } else {
-        return (session->state == CHAT_STATE_GONE);
-    }
-}
-
-static void
-_chat_session_set_gone(const char * const recipient)
-{
-    ChatSession *session = g_hash_table_lookup(sessions, recipient);
-
-    if (session != NULL) {
-        session->state = CHAT_STATE_GONE;
-    }
-}
-
-static gboolean
-_chat_session_get_recipient_supports(const char * const recipient)
-{
-    ChatSession *session = g_hash_table_lookup(sessions, recipient);
-
-    if (session == NULL) {
-        return FALSE;
-    } else {
-        return session->recipient_supports;
-    }
-}
-
-static void
-_chat_session_set_recipient_supports(const char * const recipient, gboolean recipient_supports)
-{
-    ChatSession *session = g_hash_table_lookup(sessions, recipient);
-
-    if (session != NULL) {
-        session->recipient_supports = recipient_supports;
-    }
-}
-
 gboolean
 chat_session_on_message_send(const char * const barejid)
 {
     gboolean send_state = FALSE;
     if (prefs_get_boolean(PREF_STATES)) {
-        if (!_chat_session_exists(barejid)) {
-            ChatSession *session = _chat_session_new(barejid, TRUE);
+        ChatSession *session = g_hash_table_lookup(sessions, barejid);
+        if (!session) {
+            session = _chat_session_new(barejid, TRUE);
             g_hash_table_insert(sessions, strdup(barejid), session);
 
         }
-        if (_chat_session_get_recipient_supports(barejid)) {
+        if (session->supported) {
             _chat_session_set_active(barejid);
             send_state = TRUE;
         }
@@ -261,13 +145,14 @@ chat_session_on_message_send(const char * const barejid)
 }
 
 void
-chat_session_on_incoming_message(const char * const barejid, gboolean recipient_supports)
+chat_session_on_incoming_message(const char * const barejid, gboolean supported)
 {
-    if (!_chat_session_exists(barejid)) {
-        ChatSession *session = _chat_session_new(barejid, recipient_supports);
+    ChatSession *session = g_hash_table_lookup(sessions, barejid);
+    if (!session) {
+        session = _chat_session_new(barejid, supported);
         g_hash_table_insert(sessions, strdup(barejid), session);
     } else {
-        _chat_session_set_recipient_supports(barejid, recipient_supports);
+        session->supported = supported;
     }
 }
 
@@ -275,8 +160,9 @@ void
 chat_session_on_window_open(const char * const barejid)
 {
     if (prefs_get_boolean(PREF_STATES)) {
-        if (!_chat_session_exists(barejid)) {
-            ChatSession *session = _chat_session_new(barejid, TRUE);
+        ChatSession *session = g_hash_table_lookup(sessions, barejid);
+        if (!session) {
+            session = _chat_session_new(barejid, TRUE);
             g_hash_table_insert(sessions, strdup(barejid), session);
         }
     }
@@ -286,12 +172,13 @@ void
 chat_session_on_window_close(const char * const barejid)
 {
     if (prefs_get_boolean(PREF_STATES)) {
+        ChatSession *session = g_hash_table_lookup(sessions, barejid);
         // send <gone/> chat state before closing
-        if (_chat_session_get_recipient_supports(barejid)) {
-            _chat_session_set_gone(barejid);
+        if (session->supported) {
+            session->state = CHAT_STATE_GONE;
             message_send_gone(barejid);
-            _chat_session_set_sent(barejid);
-            _chat_session_end(barejid);
+            session->sent = TRUE;
+            g_hash_table_remove(sessions, barejid);
         }
     }
 }
@@ -299,19 +186,25 @@ chat_session_on_window_close(const char * const barejid)
 void
 chat_session_on_cancel(const char * const jid)
 {
-    if (prefs_get_boolean(PREF_STATES) && _chat_session_exists(jid)) {
-        _chat_session_set_recipient_supports(jid, FALSE);
+    if (prefs_get_boolean(PREF_STATES)) {
+        ChatSession *session = g_hash_table_lookup(sessions, jid);
+        if (session) {
+            session->supported = FALSE;
+        }
     }
 }
 
 void
 chat_session_on_activity(const char * const barejid)
 {
-    if (_chat_session_get_recipient_supports(barejid)) {
-        _chat_session_set_composing(barejid);
-        if (!_chat_session_get_sent(barejid) || _chat_session_is_paused(barejid)) {
-            message_send_composing(barejid);
-            _chat_session_set_sent(barejid);
+    ChatSession *session = g_hash_table_lookup(sessions, barejid);
+    if (session) {
+        if (session->supported) {
+            _chat_session_set_composing(barejid);
+            if (!session->sent || session->state == CHAT_STATE_PAUSED) {
+                message_send_composing(barejid);
+                session->sent = TRUE;
+            }
         }
     }
 }
@@ -319,43 +212,42 @@ chat_session_on_activity(const char * const barejid)
 void
 chat_session_on_inactivity(const char * const barejid)
 {
-    if (_chat_session_get_recipient_supports(barejid)) {
-        ChatSession *session = g_hash_table_lookup(sessions, barejid);
-        if (session != NULL) {
-            if (session->active_timer != NULL) {
-                gdouble elapsed = g_timer_elapsed(session->active_timer, NULL);
-
-                if ((prefs_get_gone() != 0) && (elapsed > (prefs_get_gone() * 60.0))) {
-                    if (session->state != CHAT_STATE_GONE) {
-                        session->sent = FALSE;
-                    }
-                    session->state = CHAT_STATE_GONE;
+    ChatSession *session = g_hash_table_lookup(sessions, barejid);
+    if (session && session->supported) {
+        if (session->active_timer != NULL) {
+            gdouble elapsed = g_timer_elapsed(session->active_timer, NULL);
 
-                } else if (elapsed > INACTIVE_TIMOUT) {
-                    if (session->state != CHAT_STATE_INACTIVE) {
-                        session->sent = FALSE;
-                    }
-                    session->state = CHAT_STATE_INACTIVE;
+            if ((prefs_get_gone() != 0) && (elapsed > (prefs_get_gone() * 60.0))) {
+                if (session->state != CHAT_STATE_GONE) {
+                    session->sent = FALSE;
+                }
+                session->state = CHAT_STATE_GONE;
 
-                } else if (elapsed > PAUSED_TIMOUT) {
+            } else if (elapsed > INACTIVE_TIMOUT) {
+                if (session->state != CHAT_STATE_INACTIVE) {
+                    session->sent = FALSE;
+                }
+                session->state = CHAT_STATE_INACTIVE;
 
-                    if (session->state == CHAT_STATE_COMPOSING) {
-                        session->sent = FALSE;
-                        session->state = CHAT_STATE_PAUSED;
-                    }
+            } else if (elapsed > PAUSED_TIMOUT) {
+                if (session->state == CHAT_STATE_COMPOSING) {
+                    session->sent = FALSE;
+                    session->state = CHAT_STATE_PAUSED;
                 }
             }
         }
 
-        if (_chat_session_is_gone(barejid) && !_chat_session_get_sent(barejid)) {
-            message_send_gone(barejid);
-            _chat_session_set_sent(barejid);
-        } else if (_chat_session_is_inactive(barejid) && !_chat_session_get_sent(barejid)) {
-            message_send_inactive(barejid);
-            _chat_session_set_sent(barejid);
-        } else if (prefs_get_boolean(PREF_OUTTYPE) && _chat_session_is_paused(barejid) && !_chat_session_get_sent(barejid)) {
-            message_send_paused(barejid);
-            _chat_session_set_sent(barejid);
+        if (session->sent == FALSE) {
+            if (session->state == CHAT_STATE_GONE) {
+                message_send_gone(barejid);
+                session->sent = TRUE;
+            } else if (session->state == CHAT_STATE_INACTIVE) {
+                message_send_inactive(barejid);
+                session->sent = TRUE;
+            } else if (session->state == CHAT_STATE_PAUSED && prefs_get_boolean(PREF_OUTTYPE)) {
+                message_send_paused(barejid);
+                session->sent = TRUE;
+            }
         }
     }
 }
b1 ^
49ae0dd1 ^
8db3c4b1 ^
77f59786 ^
06aefcf5 ^
3c041abb ^
9e63489a ^







08f21ae5 ^
90dc5f6a ^



08f21ae5 ^




9e09af36 ^

33cb688a ^


22601e2d ^



33cb688a ^
22601e2d ^
bbbd9cb0 ^


22601e2d ^


ea87d005 ^
08f21ae5 ^
13ace276 ^
08f21ae5 ^

f70ee6b2 ^
291ca616 ^
f70ee6b2 ^
08f21ae5 ^
08b18f0f ^
08f21ae5 ^
501f5014 ^



451fe138 ^
08f21ae5 ^
13ace276 ^
08f21ae5 ^


13ace276 ^

ec787817 ^
0a053bef ^
ec787817 ^




ea87d005 ^
9e09af36 ^






ad558722 ^
9e09af36 ^



650a672c ^
ad558722 ^
650a672c ^





9e09af36 ^





ad558722 ^
9e09af36 ^

650a672c ^


9e09af36 ^

















49ae0dd1 ^
8db3c4b1 ^
49ae0dd1 ^
9e09af36 ^


d621586e ^
705c14a4 ^

d621586e ^

1f62d7db ^
d621586e ^
1f62d7db ^
d621586e ^
06aefcf5 ^

1f62d7db ^
49ae0dd1 ^
705c14a4 ^
06aefcf5 ^
9e09af36 ^
705c14a4 ^
06aefcf5 ^
9e09af36 ^
650a672c ^
06aefcf5 ^
49ae0dd1 ^
3c041abb ^
9e09af36 ^
49ae0dd1 ^

705c14a4 ^
49ae0dd1 ^
ea87d005 ^
b4cb1f7d ^
4f3b6f02 ^
b4cb1f7d ^
ab7bf8b0 ^
b4cb1f7d ^
ab7bf8b0 ^
b4cb1f7d ^

ea87d005 ^
06aefcf5 ^
a6791aee ^

650a672c ^
06aefcf5 ^

ad558722 ^

06aefcf5 ^

ea87d005 ^
06aefcf5 ^
a6791aee ^

650a672c ^
06aefcf5 ^

ad558722 ^

06aefcf5 ^

ea87d005 ^
d621586e ^

ef81960b ^
ad558722 ^
d621586e ^

d3eff0a9 ^
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271