aboutsummaryrefslogtreecommitdiff
path: root/src/chat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/chat.c')
-rw-r--r--src/chat.c82
1 files changed, 42 insertions, 40 deletions
diff --git a/src/chat.c b/src/chat.c
index c4b67b2..4645c6b 100644
--- a/src/chat.c
+++ b/src/chat.c
@@ -25,36 +25,24 @@
25#include "chat.h" 25#include "chat.h"
26 26
27#include "application.h" 27#include "application.h"
28#include "ui/accounts.h"
29 28
30UI_ACCOUNTS_Handle accounts; 29static void
31 30_chat_refresh(MESSENGER_Application *app)
32int lc = 0;
33
34static int
35_chat_message(UNUSED void *cls,
36 UNUSED struct GNUNET_CHAT_Context *context,
37 UNUSED const struct GNUNET_CHAT_Message *message)
38{ 31{
39 // MESSENGER_Application *app = cls; 32 const struct GNUNET_CHAT_Account *account = GNUNET_CHAT_get_connected(
40 33 app->chat.handle
41 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(
42 message
43 ); 34 );
44 35
45 move(lc++, 50); 36 app->accounts.window = NULL;
46 printw("TEST %d", (int) kind); 37 app->messages.window = NULL;
47 38
48 return GNUNET_YES; 39 if (!account)
49} 40 app->accounts.window = stdscr;
41 else if (app->chat.context)
42 app->messages.window = stdscr;
50 43
51static void 44 accounts_print(&(app->accounts), app);
52_chat_refresh(MESSENGER_Application *app) 45 messages_print(&(app->messages), app);
53{
54 // TODO
55
56 accounts.window = stdscr;
57 accounts_print(&accounts, app);
58} 46}
59 47
60static int 48static int
@@ -64,19 +52,44 @@ _chat_event(MESSENGER_Application *app,
64 if (key < 0) 52 if (key < 0)
65 goto refresh; 53 goto refresh;
66 54
55 const struct GNUNET_CHAT_Account *account = GNUNET_CHAT_get_connected(
56 app->chat.handle
57 );
58
67 if ('q' == key) 59 if ('q' == key)
68 return 1; 60 return 1;
69 61
70 move(lc++, 0); 62 if (!account)
71 printw("KEY %d", key); 63 accounts_event(&(app->accounts), app, key);
64 else if (app->chat.context)
65 messages_event(&(app->messages), app, key);
66 else
67 {
68 struct GNUNET_CHAT_Group *test = GNUNET_CHAT_group_create(
69 app->chat.handle,
70 "test"
71 );
72 72
73 accounts_event(&accounts, app, key); 73 app->chat.context = GNUNET_CHAT_group_get_context(test);
74 }
74 75
75refresh: 76refresh:
76 _chat_refresh(app); 77 _chat_refresh(app);
77 return 0; 78 return 0;
78} 79}
79 80
81int lc = 0;
82
83static int
84_chat_message(void *cls,
85 UNUSED struct GNUNET_CHAT_Context *context,
86 UNUSED const struct GNUNET_CHAT_Message *message)
87{
88 MESSENGER_Application *app = cls;
89 _chat_event(app, KEY_RESIZE);
90 return GNUNET_YES;
91}
92
80static void 93static void
81_chat_idle(void *cls) 94_chat_idle(void *cls)
82{ 95{
@@ -107,11 +120,12 @@ chat_start(MESSENGER_Chat *chat,
107{ 120{
108 chat->handle = GNUNET_CHAT_start( 121 chat->handle = GNUNET_CHAT_start(
109 cfg, 122 cfg,
110 "appdir",
111 &_chat_message, 123 &_chat_message,
112 app 124 app
113 ); 125 );
114 126
127 chat->context = NULL;
128
115 chat->idle = GNUNET_SCHEDULER_add_now( 129 chat->idle = GNUNET_SCHEDULER_add_now(
116 &_chat_idle, 130 &_chat_idle,
117 app 131 app
@@ -127,18 +141,6 @@ chat_stop(MESSENGER_Chat *chat)
127 chat->idle = NULL; 141 chat->idle = NULL;
128 } 142 }
129 143
130 if (chat->key)
131 {
132 GNUNET_SCHEDULER_cancel(chat->key);
133 chat->key = NULL;
134 }
135
136 if (chat->fdset)
137 {
138 GNUNET_NETWORK_fdset_destroy(chat->fdset);
139 chat->fdset = NULL;
140 }
141
142 GNUNET_CHAT_stop(chat->handle); 144 GNUNET_CHAT_stop(chat->handle);
143 chat->handle = NULL; 145 chat->handle = NULL;
144} 146}