]> git.0d.be Git - empathy.git/blob - libempathy/empathy-idle.c
03b27a11a5b9f4786a555e4ef0109fa2ed248974
[empathy.git] / libempathy / empathy-idle.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007-2008 Collabora Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
20  */
21
22 #include <config.h>
23
24 #include <string.h>
25
26 #include <glib/gi18n-lib.h>
27 #include <dbus/dbus-glib.h>
28
29 #include <telepathy-glib/account-manager.h>
30 #include <telepathy-glib/dbus.h>
31 #include <telepathy-glib/util.h>
32
33 #include "empathy-idle.h"
34 #include "empathy-utils.h"
35 #include "empathy-connectivity.h"
36
37 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
38 #include "empathy-debug.h"
39
40 /* Number of seconds before entering extended autoaway. */
41 #define EXT_AWAY_TIME (30*60)
42
43 /* Number of seconds to consider an account in the "just connected" state
44  * for. */
45 #define ACCOUNT_IS_JUST_CONNECTED_SECONDS 10
46
47 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIdle)
48 typedef struct {
49         DBusGProxy     *gs_proxy;
50         EmpathyConnectivity *connectivity;
51         gulong state_change_signal_id;
52
53         gboolean ready;
54
55         TpConnectionPresenceType      state;
56         gchar          *status;
57         gboolean        auto_away;
58
59         TpConnectionPresenceType      away_saved_state;
60         TpConnectionPresenceType      saved_state;
61         gchar          *saved_status;
62
63         gboolean        is_idle;
64         guint           ext_away_timeout;
65
66         TpAccountManager *manager;
67
68         /* pointer to a TpAccount --> glong of time of connection */
69         GHashTable *connect_times;
70
71         TpConnectionPresenceType requested_presence_type;
72         gchar *requested_status_message;
73
74 } EmpathyIdlePriv;
75
76 typedef enum {
77         SESSION_STATUS_AVAILABLE,
78         SESSION_STATUS_INVISIBLE,
79         SESSION_STATUS_BUSY,
80         SESSION_STATUS_IDLE,
81         SESSION_STATUS_UNKNOWN
82 } SessionStatus;
83
84 enum {
85         PROP_0,
86         PROP_STATE,
87         PROP_STATUS,
88         PROP_AUTO_AWAY
89 };
90
91 G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT);
92
93 static EmpathyIdle * idle_singleton = NULL;
94
95 static const gchar *presence_type_to_status[NUM_TP_CONNECTION_PRESENCE_TYPES] = {
96         NULL,
97         "offline",
98         "available",
99         "away",
100         "xa",
101         "hidden",
102         "busy",
103         NULL,
104         NULL,
105 };
106
107 static void
108 idle_presence_changed_cb (TpAccountManager *manager,
109                           TpConnectionPresenceType state,
110                           gchar          *status,
111                           gchar          *status_message,
112                           EmpathyIdle    *idle)
113 {
114         EmpathyIdlePriv *priv;
115
116         priv = GET_PRIV (idle);
117
118         if (state == TP_CONNECTION_PRESENCE_TYPE_UNSET)
119                 /* Assume our presence is offline if MC reports UNSET */
120                 state = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
121
122         DEBUG ("Presence changed to '%s' (%d) \"%s\"", status, state,
123                 status_message);
124
125         g_free (priv->status);
126         priv->state = state;
127         if (EMP_STR_EMPTY (status_message))
128                 priv->status = NULL;
129         else
130                 priv->status = g_strdup (status_message);
131
132         g_object_notify (G_OBJECT (idle), "state");
133         g_object_notify (G_OBJECT (idle), "status");
134 }
135
136 static gboolean
137 idle_ext_away_cb (EmpathyIdle *idle)
138 {
139         EmpathyIdlePriv *priv;
140
141         priv = GET_PRIV (idle);
142
143         DEBUG ("Going to extended autoaway");
144         empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY);
145         priv->ext_away_timeout = 0;
146
147         return FALSE;
148 }
149
150 static void
151 idle_ext_away_stop (EmpathyIdle *idle)
152 {
153         EmpathyIdlePriv *priv;
154
155         priv = GET_PRIV (idle);
156
157         if (priv->ext_away_timeout) {
158                 g_source_remove (priv->ext_away_timeout);
159                 priv->ext_away_timeout = 0;
160         }
161 }
162
163 static void
164 idle_ext_away_start (EmpathyIdle *idle)
165 {
166         EmpathyIdlePriv *priv;
167
168         priv = GET_PRIV (idle);
169
170         if (priv->ext_away_timeout != 0) {
171                 return;
172         }
173         priv->ext_away_timeout = g_timeout_add_seconds (EXT_AWAY_TIME,
174                                                         (GSourceFunc) idle_ext_away_cb,
175                                                         idle);
176 }
177
178 static void
179 idle_session_status_changed_cb (DBusGProxy    *gs_proxy,
180                                 SessionStatus  status,
181                                 EmpathyIdle   *idle)
182 {
183         EmpathyIdlePriv *priv;
184         gboolean is_idle;
185
186         priv = GET_PRIV (idle);
187
188         is_idle = (status == SESSION_STATUS_IDLE);
189
190         DEBUG ("Session idle state changed, %s -> %s",
191                 priv->is_idle ? "yes" : "no",
192                 is_idle ? "yes" : "no");
193
194         if (!priv->auto_away ||
195             (priv->saved_state == TP_CONNECTION_PRESENCE_TYPE_UNSET &&
196              (priv->state <= TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
197               priv->state == TP_CONNECTION_PRESENCE_TYPE_HIDDEN))) {
198                 /* We don't want to go auto away OR we explicitely asked to be
199                  * offline, nothing to do here */
200                 priv->is_idle = is_idle;
201                 return;
202         }
203
204         if (is_idle && !priv->is_idle) {
205                 TpConnectionPresenceType new_state;
206                 /* We are now idle */
207
208                 idle_ext_away_start (idle);
209
210                 if (priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
211                         /* We are disconnected, when coming back from away
212                          * we want to restore the presence before the
213                          * disconnection. */
214                         priv->away_saved_state = priv->saved_state;
215                 } else {
216                         priv->away_saved_state = priv->state;
217                 }
218
219                 new_state = TP_CONNECTION_PRESENCE_TYPE_AWAY;
220                 if (priv->state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY) {
221                         new_state = TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY;
222                 }
223
224                 DEBUG ("Going to autoaway. Saved state=%d, new state=%d",
225                         priv->away_saved_state, new_state);
226                 empathy_idle_set_state (idle, new_state);
227         } else if (!is_idle && priv->is_idle) {
228                 const gchar *new_status;
229                 /* We are no more idle, restore state */
230
231                 idle_ext_away_stop (idle);
232
233                 if (priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_AWAY ||
234                     priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY) {
235                         priv->away_saved_state = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
236                         new_status = NULL;
237                 } else {
238                         new_status = priv->status;
239                 }
240
241                 /* Only try and set the presence if the away saved state is not
242                  * unset. This is an odd case because it means that the session
243                  * didn't notify us of the state change to idle, and as a
244                  * result, we couldn't save the current state at that time.
245                  */
246                 if (priv->away_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
247                         DEBUG ("Restoring state to %d, reset status to %s",
248                                 priv->away_saved_state, new_status);
249
250                         empathy_idle_set_presence (idle,
251                                                    priv->away_saved_state,
252                                                    new_status);
253                 } else {
254                         DEBUG ("Away saved state is unset. This means that we "
255                                "weren't told when the session went idle. "
256                                "As a result, I'm not trying to set presence");
257                 }
258
259                 priv->away_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
260         }
261
262         priv->is_idle = is_idle;
263 }
264
265 static void
266 idle_state_change_cb (EmpathyConnectivity *connectivity,
267                       gboolean new_online,
268                       EmpathyIdle *idle)
269 {
270         EmpathyIdlePriv *priv;
271
272         priv = GET_PRIV (idle);
273
274         if (!new_online) {
275                 /* We are no longer connected */
276                 DEBUG ("Disconnected: Save state %d (%s)",
277                                 priv->state, priv->status);
278                 priv->saved_state = priv->state;
279                 g_free (priv->saved_status);
280                 priv->saved_status = g_strdup (priv->status);
281                 empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
282         }
283         else if (new_online
284                         && priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
285                 /* We are now connected */
286                 DEBUG ("Reconnected: Restore state %d (%s)",
287                                 priv->saved_state, priv->saved_status);
288                 empathy_idle_set_presence (idle,
289                                 priv->saved_state,
290                                 priv->saved_status);
291                 priv->saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
292                 g_free (priv->saved_status);
293                 priv->saved_status = NULL;
294         }
295 }
296
297 static void
298 idle_finalize (GObject *object)
299 {
300         EmpathyIdlePriv *priv;
301
302         priv = GET_PRIV (object);
303
304         g_free (priv->status);
305         g_free (priv->requested_status_message);
306
307         if (priv->gs_proxy) {
308                 g_object_unref (priv->gs_proxy);
309         }
310
311         g_signal_handler_disconnect (priv->connectivity,
312                                      priv->state_change_signal_id);
313         priv->state_change_signal_id = 0;
314
315         g_object_unref (priv->connectivity);
316
317         g_hash_table_destroy (priv->connect_times);
318         priv->connect_times = NULL;
319
320         idle_ext_away_stop (EMPATHY_IDLE (object));
321 }
322
323 static GObject *
324 idle_constructor (GType type,
325                   guint n_props,
326                   GObjectConstructParam *props)
327 {
328         GObject *retval;
329
330         if (idle_singleton) {
331                 retval = g_object_ref (idle_singleton);
332         } else {
333                 retval = G_OBJECT_CLASS (empathy_idle_parent_class)->constructor
334                         (type, n_props, props);
335
336                 idle_singleton = EMPATHY_IDLE (retval);
337                 g_object_add_weak_pointer (retval, (gpointer) &idle_singleton);
338         }
339
340         return retval;
341 }
342
343 static void
344 idle_get_property (GObject    *object,
345                    guint       param_id,
346                    GValue     *value,
347                    GParamSpec *pspec)
348 {
349         EmpathyIdlePriv *priv;
350         EmpathyIdle     *idle;
351
352         priv = GET_PRIV (object);
353         idle = EMPATHY_IDLE (object);
354
355         switch (param_id) {
356         case PROP_STATE:
357                 g_value_set_enum (value, empathy_idle_get_state (idle));
358                 break;
359         case PROP_STATUS:
360                 g_value_set_string (value, empathy_idle_get_status (idle));
361                 break;
362         case PROP_AUTO_AWAY:
363                 g_value_set_boolean (value, empathy_idle_get_auto_away (idle));
364                 break;
365         default:
366                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
367                 break;
368         };
369 }
370
371 static void
372 idle_set_property (GObject      *object,
373                    guint         param_id,
374                    const GValue *value,
375                    GParamSpec   *pspec)
376 {
377         EmpathyIdlePriv *priv;
378         EmpathyIdle     *idle;
379
380         priv = GET_PRIV (object);
381         idle = EMPATHY_IDLE (object);
382
383         switch (param_id) {
384         case PROP_STATE:
385                 empathy_idle_set_state (idle, g_value_get_enum (value));
386                 break;
387         case PROP_STATUS:
388                 empathy_idle_set_status (idle, g_value_get_string (value));
389                 break;
390         case PROP_AUTO_AWAY:
391                 empathy_idle_set_auto_away (idle, g_value_get_boolean (value));
392                 break;
393         default:
394                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
395                 break;
396         };
397 }
398
399 static void
400 empathy_idle_class_init (EmpathyIdleClass *klass)
401 {
402         GObjectClass *object_class = G_OBJECT_CLASS (klass);
403
404         object_class->finalize = idle_finalize;
405         object_class->constructor = idle_constructor;
406         object_class->get_property = idle_get_property;
407         object_class->set_property = idle_set_property;
408
409         g_object_class_install_property (object_class,
410                                          PROP_STATE,
411                                          g_param_spec_uint ("state",
412                                                             "state",
413                                                             "state",
414                                                             0, NUM_TP_CONNECTION_PRESENCE_TYPES,
415                                                             TP_CONNECTION_PRESENCE_TYPE_UNSET,
416                                                             G_PARAM_READWRITE));
417         g_object_class_install_property (object_class,
418                                          PROP_STATUS,
419                                          g_param_spec_string ("status",
420                                                               "status",
421                                                               "status",
422                                                               NULL,
423                                                               G_PARAM_READWRITE));
424
425          g_object_class_install_property (object_class,
426                                           PROP_AUTO_AWAY,
427                                           g_param_spec_boolean ("auto-away",
428                                                                 "Automatic set presence to away",
429                                                                 "Should it set presence to away if inactive",
430                                                                 FALSE,
431                                                                 G_PARAM_READWRITE));
432
433         g_type_class_add_private (object_class, sizeof (EmpathyIdlePriv));
434 }
435
436 static void
437 account_status_changed_cb (TpAccount  *account,
438                            guint       old_status,
439                            guint       new_status,
440                            guint       reason,
441                            gchar      *dbus_error_name,
442                            GHashTable *details,
443                            gpointer    user_data)
444 {
445         EmpathyIdle *idle = EMPATHY_IDLE (user_data);
446         EmpathyIdlePriv *priv = GET_PRIV (idle);
447         GTimeVal val;
448
449         if (new_status == TP_CONNECTION_STATUS_CONNECTED) {
450                 g_get_current_time (&val);
451                 g_hash_table_insert (priv->connect_times, account,
452                                      GINT_TO_POINTER (val.tv_sec));
453         } else if (new_status == TP_CONNECTION_STATUS_DISCONNECTED) {
454                 g_hash_table_remove (priv->connect_times, account);
455         }
456 }
457
458 static void
459 account_manager_ready_cb (GObject *source_object,
460                           GAsyncResult *result,
461                           gpointer user_data)
462 {
463         EmpathyIdle *idle = EMPATHY_IDLE (user_data);
464         TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
465         EmpathyIdlePriv *priv = GET_PRIV (idle);
466         TpConnectionPresenceType state;
467         gchar *status, *status_message;
468         GList *accounts, *l;
469         GError *error = NULL;
470
471         priv->ready = TRUE;
472
473         if (!tp_account_manager_prepare_finish (account_manager, result, &error)) {
474                 DEBUG ("Failed to prepare account manager: %s", error->message);
475                 g_error_free (error);
476                 return;
477         }
478
479         state = tp_account_manager_get_most_available_presence (priv->manager,
480                 &status, &status_message);
481
482         idle_presence_changed_cb (account_manager, state, status,
483                 status_message, idle);
484
485         accounts = tp_account_manager_get_valid_accounts (priv->manager);
486         for (l = accounts; l != NULL; l = l->next) {
487                 empathy_signal_connect_weak (l->data, "status-changed",
488                                              G_CALLBACK (account_status_changed_cb),
489                                              G_OBJECT (idle));
490         }
491         g_list_free (accounts);
492
493         g_free (status);
494         g_free (status_message);
495 }
496
497 static void
498 empathy_idle_init (EmpathyIdle *idle)
499 {
500         EmpathyIdlePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (idle,
501                 EMPATHY_TYPE_IDLE, EmpathyIdlePriv);
502
503         idle->priv = priv;
504         priv->is_idle = FALSE;
505
506         priv->manager = tp_account_manager_dup ();
507
508         tp_account_manager_prepare_async (priv->manager, NULL,
509             account_manager_ready_cb, idle);
510
511         g_signal_connect (priv->manager, "most-available-presence-changed",
512                 G_CALLBACK (idle_presence_changed_cb), idle);
513
514         priv->gs_proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
515                                                     "org.gnome.SessionManager",
516                                                     "/org/gnome/SessionManager/Presence",
517                                                     "org.gnome.SessionManager.Presence");
518         if (priv->gs_proxy) {
519                 dbus_g_proxy_add_signal (priv->gs_proxy, "StatusChanged",
520                                          G_TYPE_UINT, G_TYPE_INVALID);
521                 dbus_g_proxy_connect_signal (priv->gs_proxy, "StatusChanged",
522                                              G_CALLBACK (idle_session_status_changed_cb),
523                                              idle, NULL);
524         } else {
525                 DEBUG ("Failed to get gs proxy");
526         }
527
528         priv->connectivity = empathy_connectivity_dup_singleton ();
529         priv->state_change_signal_id = g_signal_connect (priv->connectivity,
530             "state-change", G_CALLBACK (idle_state_change_cb), idle);
531
532         priv->connect_times = g_hash_table_new (g_direct_hash, g_direct_equal);
533 }
534
535 EmpathyIdle *
536 empathy_idle_dup_singleton (void)
537 {
538         return g_object_new (EMPATHY_TYPE_IDLE, NULL);
539 }
540
541 TpConnectionPresenceType
542 empathy_idle_get_state (EmpathyIdle *idle)
543 {
544         EmpathyIdlePriv *priv;
545
546         priv = GET_PRIV (idle);
547
548         if (G_UNLIKELY (!priv->ready))
549                 g_critical (G_STRLOC ": %s called before AccountManager ready",
550                                 G_STRFUNC);
551
552         return priv->state;
553 }
554
555 void
556 empathy_idle_set_state (EmpathyIdle *idle,
557                         TpConnectionPresenceType   state)
558 {
559         EmpathyIdlePriv *priv;
560
561         priv = GET_PRIV (idle);
562
563         empathy_idle_set_presence (idle, state, priv->status);
564 }
565
566 const gchar *
567 empathy_idle_get_status (EmpathyIdle *idle)
568 {
569         EmpathyIdlePriv *priv;
570
571         priv = GET_PRIV (idle);
572
573         if (G_UNLIKELY (!priv->ready))
574                 g_critical (G_STRLOC ": %s called before AccountManager ready",
575                                 G_STRFUNC);
576
577         if (!priv->status) {
578                 return empathy_presence_get_default_message (priv->state);
579         }
580
581         return priv->status;
582 }
583
584 void
585 empathy_idle_set_status (EmpathyIdle *idle,
586                          const gchar *status)
587 {
588         EmpathyIdlePriv *priv;
589
590         priv = GET_PRIV (idle);
591
592         empathy_idle_set_presence (idle, priv->state, status);
593 }
594
595 static void
596 empathy_idle_do_set_presence (EmpathyIdle *idle,
597                            TpConnectionPresenceType status_type,
598                            const gchar *status_message)
599 {
600         EmpathyIdlePriv *priv = GET_PRIV (idle);
601         const gchar *status;
602
603         g_assert (status_type > 0 && status_type < NUM_TP_CONNECTION_PRESENCE_TYPES);
604
605         status = presence_type_to_status[status_type];
606
607         g_return_if_fail (status != NULL);
608
609         /* We possibly should be sure that the account manager is prepared, but
610          * sometimes this isn't possible, like when exiting. In other words,
611          * we need a callback to empathy_idle_set_presence to be sure the
612          * presence is set on all accounts successfully.
613          * However, in practice, this is fine as we've already prepared the
614          * account manager here in _init. */
615         tp_account_manager_set_all_requested_presences (priv->manager,
616                 status_type, status, status_message);
617 }
618
619 void
620 empathy_idle_set_presence (EmpathyIdle *idle,
621                            TpConnectionPresenceType   state,
622                            const gchar *status)
623 {
624         EmpathyIdlePriv *priv;
625         const gchar     *default_status;
626
627         priv = GET_PRIV (idle);
628
629         DEBUG ("Changing presence to %s (%d)", status, state);
630
631         g_free (priv->requested_status_message);
632         priv->requested_presence_type = state;
633         priv->requested_status_message = g_strdup (status);
634
635         /* Do not set translated default messages */
636         default_status = empathy_presence_get_default_message (state);
637         if (!tp_strdiff (status, default_status)) {
638                 status = NULL;
639         }
640
641         if (state != TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
642                         !empathy_connectivity_is_online (priv->connectivity)) {
643                 DEBUG ("Empathy is not online");
644
645                 priv->saved_state = state;
646                 if (tp_strdiff (priv->status, status)) {
647                         g_free (priv->saved_status);
648                         priv->saved_status = NULL;
649                         if (!EMP_STR_EMPTY (status)) {
650                                 priv->saved_status = g_strdup (status);
651                         }
652                 }
653                 return;
654         }
655
656         empathy_idle_do_set_presence (idle, state, status);
657 }
658
659 gboolean
660 empathy_idle_get_auto_away (EmpathyIdle *idle)
661 {
662         EmpathyIdlePriv *priv = GET_PRIV (idle);
663
664         return priv->auto_away;
665 }
666
667 void
668 empathy_idle_set_auto_away (EmpathyIdle *idle,
669                             gboolean     auto_away)
670 {
671         EmpathyIdlePriv *priv = GET_PRIV (idle);
672
673         priv->auto_away = auto_away;
674
675         g_object_notify (G_OBJECT (idle), "auto-away");
676 }
677
678 TpConnectionPresenceType
679 empathy_idle_get_requested_presence (EmpathyIdle *idle,
680     gchar **status,
681     gchar **status_message)
682 {
683         EmpathyIdlePriv *priv = GET_PRIV (idle);
684
685         if (status != NULL) {
686                 *status = g_strdup (presence_type_to_status[priv->requested_presence_type]);
687         }
688
689         if (status_message != NULL) {
690                 *status_message = g_strdup (priv->requested_status_message);
691         }
692
693         return priv->requested_presence_type;
694 }
695
696 /* This function returns %TRUE if EmpathyIdle considers the account
697  * @account as having just connected recently. Otherwise, it returns
698  * %FALSE. In doubt, %FALSE is returned. */
699 gboolean
700 empathy_idle_account_is_just_connected (EmpathyIdle *idle,
701                                         TpAccount *account)
702 {
703         EmpathyIdlePriv *priv = GET_PRIV (idle);
704         GTimeVal val;
705         gpointer ptr;
706         glong t;
707
708         if (tp_account_get_connection_status (account, NULL)
709             != TP_CONNECTION_STATUS_CONNECTED) {
710                 return FALSE;
711         }
712
713         ptr = g_hash_table_lookup (priv->connect_times, account);
714
715         if (ptr == NULL) {
716                 return FALSE;
717         }
718
719         t = GPOINTER_TO_INT (ptr);
720
721         g_get_current_time (&val);
722
723         return (val.tv_sec - t) < ACCOUNT_IS_JUST_CONNECTED_SECONDS;
724 }