aboutsummaryrefslogtreecommitdiff
path: root/src/ui/messages.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/messages.c')
-rw-r--r--src/ui/messages.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/ui/messages.c b/src/ui/messages.c
new file mode 100644
index 0000000..780dd45
--- /dev/null
+++ b/src/ui/messages.c
@@ -0,0 +1,80 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file ui/messages.c
23 */
24
25#include "messages.h"
26
27#include "../application.h"
28
29void
30messages_event(UI_MESSAGES_Handle *messages,
31 struct MESSENGER_Application *app,
32 int key)
33{
34 // TODO
35}
36
37int
38_messages_iterate_print(void *cls,
39 struct GNUNET_CHAT_Context *context,
40 const struct GNUNET_CHAT_Message *message)
41{
42 UI_MESSAGES_Handle *messages = cls;
43
44 const int y = messages->line_index++;
45
46 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
47 const char *text = GNUNET_CHAT_message_get_text(message);
48
49 struct GNUNET_TIME_Absolute timestamp = GNUNET_CHAT_message_get_timestamp(
50 message
51 );
52
53 wmove(messages->window, y, 0);
54 wprintw(
55 messages->window,
56 "%s | [%d]: %s",
57 GNUNET_TIME_absolute2s(timestamp),
58 (int) kind,
59 text
60 );
61
62 return GNUNET_YES;
63}
64
65void
66messages_print(UI_MESSAGES_Handle *messages,
67 struct MESSENGER_Application *app)
68{
69 if (!(messages->window))
70 return;
71
72 struct GNUNET_CHAT_Context *context = app->chat.context;
73
74 messages->line_index = 0;
75 GNUNET_CHAT_context_iterate_messages(
76 context,
77 _messages_iterate_print,
78 messages
79 );
80}