about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-12-14 23:53:35 +0000
committerJames Booth <boothj5@gmail.com>2015-12-14 23:57:06 +0000
commit482eea4fcf68b9f2bd9f8d6f1db98fe313bef141 (patch)
tree04b69abfafd0eb8aa51e932b73e96111548e01bf /src
parent1080c8c2aedf1efab993533971f9d4478d5c77b1 (diff)
downloadprofani-tty-482eea4fcf68b9f2bd9f8d6f1db98fe313bef141.tar.gz
Moved sending of initial presence to sv_ev_roster_received
Diffstat (limited to 'src')
-rw-r--r--src/event/server_events.c31
-rw-r--r--src/xmpp/roster.c29
2 files changed, 31 insertions, 29 deletions
diff --git a/src/event/server_events.c b/src/event/server_events.c
index d5022d35..5b4bed05 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -48,6 +48,7 @@
 #include "window_list.h"
 #include "config/tlscerts.h"
 #include "profanity.h"
+#include "event/client_events.h"
 
 #ifdef HAVE_LIBOTR
 #include "otr/otr.h"
@@ -100,6 +101,36 @@ sv_ev_roster_received(void)
     if (prefs_get_boolean(PREF_ROSTER)) {
         ui_show_roster();
     }
+
+    char *account = jabber_get_account_name();
+
+    // send initial presence
+    resource_presence_t conn_presence = accounts_get_login_presence(account);
+    char *last_activity_str = accounts_get_last_activity(account);
+    if (last_activity_str) {
+        GDateTime *nowdt = g_date_time_new_now_utc();
+
+        GTimeVal lasttv;
+        gboolean res = g_time_val_from_iso8601(last_activity_str, &lasttv);
+        if (res) {
+            GDateTime *lastdt = g_date_time_new_from_timeval_utc(&lasttv);
+            GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt);
+            int diff_secs = (diff_micros / 1000) / 1000;
+            if (prefs_get_boolean(PREF_LASTACTIVITY)) {
+                cl_ev_presence_send(conn_presence, NULL, diff_secs);
+            } else {
+                cl_ev_presence_send(conn_presence, NULL, 0);
+            }
+            g_date_time_unref(lastdt);
+        } else {
+            cl_ev_presence_send(conn_presence, NULL, 0);
+        }
+
+        free(last_activity_str);
+        g_date_time_unref(nowdt);
+    } else {
+        cl_ev_presence_send(conn_presence, NULL, 0);
+    }
 }
 
 void
diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c
index 516d291c..8b646efa 100644
--- a/src/xmpp/roster.c
+++ b/src/xmpp/roster.c
@@ -336,35 +336,6 @@ _roster_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, voi
 
     sv_ev_roster_received();
 
-    char *account = jabber_get_account_name();
-    resource_presence_t conn_presence = accounts_get_login_presence(account);
-
-    char *last_activity_str = accounts_get_last_activity(account);
-    if (last_activity_str) {
-        GDateTime *nowdt = g_date_time_new_now_utc();
-
-        GTimeVal lasttv;
-        gboolean res = g_time_val_from_iso8601(last_activity_str, &lasttv);
-        if (res) {
-            GDateTime *lastdt = g_date_time_new_from_timeval_utc(&lasttv);
-            GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt);
-            int diff_secs = (diff_micros / 1000) / 1000;
-            if (prefs_get_boolean(PREF_LASTACTIVITY)) {
-                cl_ev_presence_send(conn_presence, NULL, diff_secs);
-            } else {
-                cl_ev_presence_send(conn_presence, NULL, 0);
-            }
-            g_date_time_unref(lastdt);
-        } else {
-            cl_ev_presence_send(conn_presence, NULL, 0);
-        }
-
-        free(last_activity_str);
-        g_date_time_unref(nowdt);
-    } else {
-        cl_ev_presence_send(conn_presence, NULL, 0);
-    }
-
     return 1;
 }