From 95bca87556963c2bacbc7a3ce9f6aecae5fa6f87 Mon Sep 17 00:00:00 2001 From: nekobit Date: Tue, 5 Jul 2022 09:44:38 +0000 Subject: [PATCH] Messages FossilOrigin-Name: 74fe969864d4419e2a040bda2e5482806ed3fd390dafe66c7ec9962304cd763d --- dist/treebird20.css | 54 ++++++++++++++++++++++++- src/conversations.c | 96 +++++++++++++++++++++++++++++++++++++++++++++ src/conversations.h | 11 ++++++ src/main.c | 1 + static/message.tmpl | 6 +++ 5 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 static/message.tmpl diff --git a/dist/treebird20.css b/dist/treebird20.css index 4018230..e1d5d01 100644 --- a/dist/treebird20.css +++ b/dist/treebird20.css @@ -781,14 +781,16 @@ svg.in-reply-to-icon font-size: 10px; } -.time::before +.status .time:before, +.notification-compact .time:before { content: "•"; padding-right: 10px; font-size: 10px; } -.time +.status .time, +.notification-compact .time { color: #606060; vertical-align: middle; @@ -1948,6 +1950,54 @@ input[type=checkbox].hidden:not(:checked) + .list-edit-content padding: 4px; } +/* Chats */ + +.message-wrapper +{ + display: block; +} + +.message-wrapper .message +{ + position: relative; + display: inline-block; + background-color: #e8e8e8; + border-radius: 3px; + margin: 7px; + margin-left: 12px; + padding: 10px 14px; + box-shadow: 0px 1px 6px rgba(0, 0, 0, 0.04); + color: #000; +} + +.message-wrapper .message:before { + content: " "; + position: absolute; + left: 0; + top: 0; + margin-left: -10px; + margin-top: 5px; + border-width: 5px; + border-style: solid; + border-color: transparent #e8e8e8 transparent transparent; +} + +.message .content +{ + +} + +.message .time +{ + color: #606060; + font-size: .7rem; + float: right; + margin-left: 6px; + position: relative; + top: 4px; +} + + /* Instance information */ #instance-panel { diff --git a/src/conversations.c b/src/conversations.c index 221311d..6ae47ea 100644 --- a/src/conversations.c +++ b/src/conversations.c @@ -27,6 +27,14 @@ // Files #include "../static/chat.ctmpl" #include "../static/chats_page.ctmpl" +#include "../static/message.ctmpl" + +struct construct_message_args +{ + struct mstdnt_message* msg; + struct mstdnt_account* you; + struct mstdnt_account* them; +}; char* construct_chat(struct mstdnt_chat* chat, size_t* size) { @@ -53,6 +61,40 @@ char* construct_chats(struct mstdnt_chat* chats, size_t size, size_t* ret_size) return construct_func_strings(construct_chat_voidwrap, chats, size, ret_size); } +char* construct_message(struct mstdnt_message* msg, + struct mstdnt_account* you, + struct mstdnt_account* them, + size_t* size) +{ + char* result; + struct message_template data = { + .id = msg->id, + .content = msg->content + }; + result = tmpl_gen_message(&data, size); + return result; +} + +static char* construct_message_voidwrap(void* passed, size_t index, size_t* res) +{ + struct construct_message_args* args = passed; + return construct_message(args->msg + index, args->you, args->them, res); +} + +char* construct_messages(struct mstdnt_message* messages, + struct mstdnt_account* you, + struct mstdnt_account* them, + size_t size, + size_t* ret_size) +{ + struct construct_message_args args = { + .msg = messages, + .you = you, + .them = them, + }; + return construct_func_strings(construct_message_voidwrap, &args, size, ret_size); +} + char* construct_chats_view(char* lists_string, size_t* size) { struct chats_page_template data = { @@ -106,3 +148,57 @@ void content_chats(struct session* ssn, mastodont_t* api, char** data) free(chats_html); // TOOD cleanup chats } + +void content_chat_view(struct session* ssn, mastodont_t* api, char** data) +{ + struct mstdnt_args m_args; + set_mstdnt_args(&m_args, ssn); + struct mstdnt_message* messages = NULL; + /* struct mstdnt_account acct; */ + size_t messages_len = 0; + struct mstdnt_storage storage = { 0 }; + struct mstdnt_storage acct_storage = { 0 }; + // char* chats_page = NULL; + char* messages_html = NULL; + + struct mstdnt_chats_args args = { + .with_muted = MSTDNT_TRUE, + .max_id = keystr(ssn->post.max_id), + .since_id = NULL, + .min_id = keystr(ssn->post.min_id), + .offset = keyint(ssn->query.offset), + .limit = 20, + }; + + + if (mastodont_get_chat_messages(api, &m_args, data[0], + &args, &storage, &messages, &messages_len)) + { + messages_html = construct_error(storage.error, E_ERROR, 1, NULL); + } + else { + // Get other account + /* if (messages_len) */ + /* mastodont_get_account(api, &m_args, 1, messages[0].account_id */ + messages_html = construct_messages(messages, &(ssn->acct), NULL, messages_len, NULL); + if (!messages_html) + messages_html = construct_error("This is the start of something new...", E_NOTICE, 1, NULL); + /* messages_html = construct_chats_view(chats_html, NULL); */ + } + + struct base_page b = { + .category = BASE_CAT_CHATS, + .content = messages_html, + .sidebar_left = NULL + }; + + // Outpuot + render_base_page(&b, ssn, api); + + // Cleanup + mastodont_storage_cleanup(&storage); + //free(chats_page); + free(messages_html); + // TOOD cleanup chats +} + diff --git a/src/conversations.h b/src/conversations.h index 5ed0a75..a49a7fa 100644 --- a/src/conversations.h +++ b/src/conversations.h @@ -25,7 +25,18 @@ char* construct_chat(struct mstdnt_chat* chat, size_t* size); char* construct_chats(struct mstdnt_chat* chats, size_t size, size_t* ret_size); char* construct_chats_view(char* lists_string, size_t* size); +// Message +char* construct_message(struct mstdnt_message* message, + struct mstdnt_account* your_profile, + struct mstdnt_account* their_profile, + size_t* size); +char* construct_messages(struct mstdnt_message* message, + struct mstdnt_account* your_profile, + struct mstdnt_account* their_profile, + size_t size, + size_t* ret_size); void content_chats(struct session* ssn, mastodont_t* api, char** data); +void content_chat_view(struct session* ssn, mastodont_t* api, char** data); #endif // LISTS_H diff --git a/src/main.c b/src/main.c index b9ddab2..2af8684 100644 --- a/src/main.c +++ b/src/main.c @@ -106,6 +106,7 @@ int main(void) { "/notifications_compact", content_notifications_compact }, { "/notifications", content_notifications }, { "/tag/:", content_tl_tag }, + { "/chats/:", content_chat_view }, { "/chats", content_chats }, // API { "/treebird_api/v1/notifications", api_notifications }, diff --git a/static/message.tmpl b/static/message.tmpl new file mode 100644 index 0000000..07c6fb4 --- /dev/null +++ b/static/message.tmpl @@ -0,0 +1,6 @@ +
+
+ {{ %s : content }} + 12:00 +
+