about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-06-21 18:29:20 +0100
committerJames Booth <boothj5@gmail.com>2015-06-21 18:29:20 +0100
commit13a612cbc2978496e6587ff54a8df4165575b5ba (patch)
treeb9b243db7575e5d7ca470421ef56bf9a8c70ebcd
parent8d2d92360370747a34c25319a63d91a2775ffb85 (diff)
downloadprofani-tty-13a612cbc2978496e6587ff54a8df4165575b5ba.tar.gz
Moved window creation to sv_ev_incoming_message
-rw-r--r--src/event/server_events.c23
-rw-r--r--src/ui/core.c27
-rw-r--r--src/ui/ui.h2
-rw-r--r--tests/unittests/ui/stub_ui.c2
4 files changed, 28 insertions, 26 deletions
diff --git a/src/event/server_events.c b/src/event/server_events.c
index 5af19f7f..74eb8ae2 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -43,6 +43,7 @@
 #include "config/preferences.h"
 #include "config/account.h"
 #include "roster_list.h"
+#include "window_list.h"
 
 #ifdef HAVE_LIBOTR
 #include "otr/otr.h"
@@ -171,16 +172,24 @@ sv_ev_carbon(char *barejid, char *message)
 void
 sv_ev_incoming_message(char *barejid, char *resource, char *message)
 {
+    gboolean new_win = FALSE;
+    ProfChatWin *chatwin = wins_get_chat(barejid);
+    if (!chatwin) {
+        ProfWin *window = wins_new_chat(barejid);
+        chatwin = (ProfChatWin*)window;
+        new_win = TRUE;
+    }
+
 #ifdef HAVE_LIBOTR
     gboolean decrypted = FALSE;
     char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
     if (otr_res) {
-        ui_incoming_msg(barejid, resource, otr_res, NULL);
+        ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win);
         chat_log_otr_msg_in(barejid, otr_res, decrypted);
         otr_free_message(otr_res);
     }
 #else
-    ui_incoming_msg(barejid, resource, message, NULL);
+    ui_incoming_msg(chatwin, resource, message, NULL, new_win);
     chat_log_msg_in(barejid, message);
 #endif
 }
@@ -194,7 +203,15 @@ sv_ev_delayed_private_message(const char * const fulljid, char *message, GTimeVa
 void
 sv_ev_delayed_message(char *barejid, char *message, GTimeVal tv_stamp)
 {
-    ui_incoming_msg(barejid, NULL, message, &tv_stamp);
+    gboolean new_win = FALSE;
+    ProfChatWin *chatwin = wins_get_chat(barejid);
+    if (!chatwin) {
+        ProfWin *window = wins_new_chat(barejid);
+        chatwin = (ProfChatWin*)window;
+        new_win = TRUE;
+    }
+
+    ui_incoming_msg(chatwin, NULL, message, &tv_stamp, new_win);
     chat_log_msg_in_delayed(barejid, message, &tv_stamp);
 }
 
diff --git a/src/ui/core.c b/src/ui/core.c
index 10c5d347..ec5ae9af 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -416,21 +416,12 @@ ui_message_receipt(const char * const barejid, const char * const id)
 }
 
 void
-ui_incoming_msg(const char * const barejid, const char * const resource, const char * const message, GTimeVal *tv_stamp)
+ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GTimeVal *tv_stamp, gboolean win_created)
 {
-    gboolean win_created = FALSE;
-
-    ProfChatWin *chatwin = wins_get_chat(barejid);
-    if (chatwin == NULL) {
-        ProfWin *window = wins_new_chat(barejid);
-        chatwin = (ProfChatWin*)window;
-        win_created = TRUE;
-    }
-
-    ProfWin *window = (ProfWin*) chatwin;
+    ProfWin *window = (ProfWin*)chatwin;
     int num = wins_get_num(window);
 
-    char *display_name = roster_get_msg_display_name(barejid, resource);
+    char *display_name = roster_get_msg_display_name(chatwin->barejid, resource);
 
     // currently viewing chat window with sender
     if (wins_is_current(window)) {
@@ -449,12 +440,12 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c
 
         chatwin->unread++;
         if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
-            _win_show_history(chatwin, barejid);
+            _win_show_history(chatwin, chatwin->barejid);
         }
 
         // show users status first, when receiving message via delayed delivery
-        if (tv_stamp && (win_created)) {
-            PContact pcontact = roster_get_contact(barejid);
+        if (tv_stamp && win_created) {
+            PContact pcontact = roster_get_contact(chatwin->barejid);
             if (pcontact) {
                 win_show_contact(window, pcontact);
             }
@@ -1277,12 +1268,6 @@ ui_new_chat_win(const char * const barejid)
     ProfWin *window = wins_new_chat(barejid);
     ProfChatWin *chatwin = (ProfChatWin *)window;
 
-#ifdef HAVE_LIBOTR
-    if (otr_is_secure(barejid)) {
-        chatwin->enc_mode = PROF_ENC_OTR;
-    }
-#endif
-
     if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
         _win_show_history(chatwin, barejid);
     }
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 396bae1c..7cfad86c 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -101,7 +101,7 @@ void ui_handle_stanza(const char * const msg);
 // ui events
 void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity);
 void ui_contact_typing(const char * const barejid, const char * const resource);
-void ui_incoming_msg(const char * const from, const char * const resource,  const char * const message, GTimeVal *tv_stamp);
+void ui_incoming_msg(ProfChatWin *chatwin, const char * const resource,  const char * const message, GTimeVal *tv_stamp, gboolean win_created);
 void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp);
 void ui_message_receipt(const char * const barejid, const char * const id);
 
diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c
index 8ad3f236..085ff03b 100644
--- a/tests/unittests/ui/stub_ui.c
+++ b/tests/unittests/ui/stub_ui.c
@@ -179,7 +179,7 @@ void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activi
 }
 
 void ui_contact_typing(const char * const barejid, const char * const resource) {}
-void ui_incoming_msg(const char * const from, const char * const resource, const char * const message, GTimeVal *tv_stamp) {}
+void ui_incoming_msg(ProfChatWin *chatwin, const char * const resource, const char * const message, GTimeVal *tv_stamp, gboolean win_created) {}
 void ui_message_receipt(const char * const barejid, const char * const id) {}
 
 void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp) {}