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