aboutsummaryrefslogtreecommitdiff
path: root/src/chat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/chat.c')
-rw-r--r--src/chat.c68
1 files changed, 49 insertions, 19 deletions
diff --git a/src/chat.c b/src/chat.c
index 8ad21e5..4bf7972 100644
--- a/src/chat.c
+++ b/src/chat.c
@@ -35,18 +35,25 @@ _chat_refresh(MESSENGER_Application *app)
35 35
36 app->accounts.window = NULL; 36 app->accounts.window = NULL;
37 app->chats.window = NULL; 37 app->chats.window = NULL;
38 app->messages.window = NULL; 38 app->current.members.window = NULL;
39 app->current.messages.window = NULL;
39 40
40 if (!account) 41 if (!account)
41 app->accounts.window = stdscr; 42 app->accounts.window = stdscr;
42 else if (app->chat.context) 43 else if (app->chat.context)
43 app->messages.window = stdscr; 44 {
45 if (app->chat.show_members)
46 app->current.members.window = stdscr;
47 else
48 app->current.messages.window = stdscr;
49 }
44 else 50 else
45 app->chats.window = stdscr; 51 app->chats.window = stdscr;
46 52
47 accounts_print(&(app->accounts), app); 53 accounts_print(&(app->accounts), app);
48 chats_print(&(app->chats), app); 54 chats_print(&(app->chats), app);
49 messages_print(&(app->messages)); 55 members_print(&(app->current.members));
56 messages_print(&(app->current.messages));
50} 57}
51 58
52static int 59static int
@@ -63,7 +70,12 @@ _chat_event(MESSENGER_Application *app,
63 if (!account) 70 if (!account)
64 accounts_event(&(app->accounts), app, key); 71 accounts_event(&(app->accounts), app, key);
65 else if (app->chat.context) 72 else if (app->chat.context)
66 messages_event(&(app->messages), app, key); 73 {
74 if (app->chat.show_members)
75 members_event(&(app->current.members), app, key);
76 else
77 messages_event(&(app->current.messages), app, key);
78 }
67 else 79 else
68 chats_event(&(app->chats), app, key); 80 chats_event(&(app->chats), app, key);
69 81
@@ -82,21 +94,7 @@ _chat_message(void *cls,
82{ 94{
83 MESSENGER_Application *app = cls; 95 MESSENGER_Application *app = cls;
84 96
85 UI_MESSAGES_Handle *messages = (UI_MESSAGES_Handle*) ( 97 chat_process_message(&(app->chat), context, message);
86 GNUNET_CHAT_context_get_user_pointer(context)
87 );
88
89 if (messages)
90 {
91 if (GNUNET_CHAT_KIND_DELETION == GNUNET_CHAT_message_get_kind(message))
92 messages_remove(
93 &(app->messages),
94 context,
95 GNUNET_CHAT_message_get_target(message)
96 );
97
98 messages_add(&(app->messages), context, message);
99 }
100 98
101 _chat_event(app, KEY_RESIZE); 99 _chat_event(app, KEY_RESIZE);
102 return GNUNET_YES; 100 return GNUNET_YES;
@@ -160,3 +158,35 @@ chat_stop(MESSENGER_Chat *chat)
160 158
161 chat->quit = GNUNET_YES; 159 chat->quit = GNUNET_YES;
162} 160}
161
162void
163chat_process_message(UNUSED MESSENGER_Chat *chat,
164 struct GNUNET_CHAT_Context *context,
165 const struct GNUNET_CHAT_Message *message)
166{
167 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
168
169 struct GNUNET_CHAT_Contact *sender = GNUNET_CHAT_message_get_sender(message);
170
171 UI_CHAT_Handle *current = (UI_CHAT_Handle*) (
172 GNUNET_CHAT_context_get_user_pointer(context)
173 );
174
175 if (!current)
176 return;
177
178 bool new_member = FALSE;
179
180 if (GNUNET_CHAT_KIND_LEAVE)
181 members_remove(&(current->members), sender);
182 else if (GNUNET_CHAT_KIND_JOIN == kind)
183 new_member = members_add(&(current->members), sender);
184
185 if (GNUNET_CHAT_KIND_DELETION == kind)
186 messages_remove(
187 &(current->messages),
188 GNUNET_CHAT_message_get_target(message)
189 );
190 else if ((GNUNET_CHAT_KIND_JOIN != kind) || (new_member))
191 messages_add(&(current->messages), message);
192}