about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app.c18
-rw-r--r--jabber.c7
-rw-r--r--jabber.h2
-rw-r--r--windows.c14
-rw-r--r--windows.h4
5 files changed, 34 insertions, 11 deletions
diff --git a/app.c b/app.c
index a11ed56f..f6cc32af 100644
--- a/app.c
+++ b/app.c
@@ -87,16 +87,26 @@ static void main_event_loop(void)
         // null terminate the input    
         command[size++] = '\0';
 
-        // newline was hit, check if /quit command issued
+        // deal with input
+
+        // /quit command -> exit
         if (strcmp(command, "/quit") == 0) {
             break;
+
+        // /help -> print help to console
         } else if (strncmp(command, "/help", 5) == 0) {
             cons_help();
             inp_clear();
+
+        // send message to recipient if chat window
         } else {
-            jabber_send(command);
-            show_outgoing_msg("me", command);
-            inp_clear();
+            if (in_chat()) {
+                char recipient[100] = "";
+                get_recipient(recipient);
+                jabber_send(command, recipient);
+                show_outgoing_msg("me", command);
+                inp_clear();
+            }
         }
     }
 
diff --git a/jabber.c b/jabber.c
index cd41a8a6..e00a7c5a 100644
--- a/jabber.c
+++ b/jabber.c
@@ -46,14 +46,14 @@ void jabber_process_events(void)
 }
 
 
-void jabber_send(char *msg)
+void jabber_send(char *msg, char *recipient)
 {
     xmpp_stanza_t *reply, *body, *text;
 
     reply = xmpp_stanza_new(_ctx);
     xmpp_stanza_set_name(reply, "message");
     xmpp_stanza_set_type(reply, "chat");
-    xmpp_stanza_set_attribute(reply, "to", "boothj5@localhost");
+    xmpp_stanza_set_attribute(reply, "to", recipient);
 
     body = xmpp_stanza_new(_ctx);
     xmpp_stanza_set_name(body, "body");
@@ -80,8 +80,7 @@ static int _jabber_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * con
     message = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
 
     char *from = xmpp_stanza_get_attribute(stanza, "from");
-    char *short_from = strtok(from, "@");
-    show_incomming_msg(short_from, message);
+    show_incomming_msg(from, message);
 
     return 1;
 }
diff --git a/jabber.h b/jabber.h
index 6a45edf6..03ded0bd 100644
--- a/jabber.h
+++ b/jabber.h
@@ -4,6 +4,6 @@
 void jabber_connect(char *user, char *passwd);
 void jabber_disconnect(void);
 void jabber_process_events(void);
-void jabber_send(char *msg);
+void jabber_send(char *msg, char *recipient);
 
 #endif
diff --git a/windows.c b/windows.c
index e23414e6..fcddcb7e 100644
--- a/windows.c
+++ b/windows.c
@@ -60,6 +60,16 @@ void switch_to(int i)
     curr_win = i;
 }
 
+int in_chat(void)
+{
+    return (curr_win != 0);
+}
+
+void get_recipient(char *recipient)
+{
+    strcpy(recipient, wins[curr_win].from);
+}
+
 void show_incomming_msg(char *from, char *message) 
 {
     char line[100];
@@ -117,7 +127,9 @@ void show_outgoing_msg(char *from, char* message)
     char line[100];
     sprintf(line, "%s: %s\n", from, message);
 
-//    wprintw(chat_win, line);
+    wprintw(wins[curr_win].win, line);
+    touchwin(wins[curr_win].win);
+    wrefresh(wins[curr_win].win);
 }
 
 void inp_get_command_str(char *cmd)
diff --git a/windows.h b/windows.h
index 90f10577..a4c089dc 100644
--- a/windows.h
+++ b/windows.h
@@ -5,13 +5,15 @@
 #include <ncurses.h>
 
 struct prof_win {
-    char from[70];
+    char from[100];
     WINDOW *win;
 };
 
 void gui_init(void);
 void gui_close(void);
 void switch_to(int i);
+int in_chat(void);
+void get_recipient(char *recipient);
 void show_incomming_msg(char *from, char *message);
 void show_outgoing_msg(char *from, char *message);
 void inp_get_command_str(char *cmd);