From 969f12e347b91ff79418031bc759252304fbd6b5 Mon Sep 17 00:00:00 2001 From: nekobit Date: Thu, 7 Jul 2022 01:36:05 +0000 Subject: [PATCH] More chat stuff, chat embeds, fix segfault FossilOrigin-Name: 4f3d242139e6ea4c8050858ce6be541c415bbf5c4388f81648495df8f534ff31 --- dist/treebird20.css | 107 ++++++++++++++++++++++++++++++++++++++---- src/conversations.c | 58 +++++++++++++++++------ src/conversations.h | 2 + src/main.c | 1 + src/reply.c | 2 +- static/chat_view.tmpl | 11 +++-- static/contact.tmpl | 19 ++++++++ static/embed.tmpl | 21 +++++++++ 8 files changed, 193 insertions(+), 28 deletions(-) create mode 100644 static/contact.tmpl create mode 100644 static/embed.tmpl diff --git a/dist/treebird20.css b/dist/treebird20.css index 1cfe7be..db85c10 100644 --- a/dist/treebird20.css +++ b/dist/treebird20.css @@ -18,13 +18,11 @@ html body { - background-attachment: fixed !important; - background-size: cover !important; + background-attachment: fixed; + background-size: cover; background-color: unset; font-family: sans-serif, Arial, Helvetica; - min-height: 100%; color: #040404; - } /* Basic elements */ @@ -91,7 +89,7 @@ table.ui-table td { padding: 0; margin: 0; - border-collapse: collapse !important; + border-collapse: collapse; vertical-align: top; } @@ -278,6 +276,51 @@ table.ui-table td max-width: 250px; } +.page-header +{ + padding: 8px; + margin: 0; + background: linear-gradient(#f3f3f3, #e8e8e8); + border-bottom: 1px solid #bbb; +} + +.page-header-button +{ + background-color: #ddd; + border: 1px solid #bbb; + padding: 4px 6px; + font-size: 1.1rem; + border-radius: 4px; + margin-right: 4px; + text-decoration: none; + text-align: middle; + display: inline-block; + vertical-align: middle; +} + +.page-header-button:hover +{ + background-color: #ccc; +} + +.page-header .page-header-title +{ + color: #000; + text-decoration: none; + vertical-align: middle; + font-size: 1.1rem; + +} + +.page-header .page-header-image.avatar +{ + width: 32px; + height: 32px; + margin-right: 6px; + border-radius: 4px; + background-size: cover; + vertical-align: middle; +} /************************************************* * COMMON ELEMENTS * @@ -1954,6 +1997,7 @@ input[type=checkbox].hidden:not(:checked) + .list-edit-content .message-container { + position: relative; display: block; margin: 10px; } @@ -1961,7 +2005,8 @@ input[type=checkbox].hidden:not(:checked) + .list-edit-content .message-container .avatar { display: inline-block; - vertical-align: middle; + position: absolute; + top: 0px; width: 38px; height: 38px; border-radius: 4px; @@ -1975,6 +2020,7 @@ input[type=checkbox].hidden:not(:checked) + .list-edit-content display: inline-block; vertical-align: middle; max-width: 70%; + margin-left: 42px; } .message-wrapper .message @@ -1999,7 +2045,13 @@ input[type=checkbox].hidden:not(:checked) + .list-edit-content border-width: 5px; border-style: solid; border-color: transparent #e8e8e8 transparent transparent; -} +} + +.message .content +{ + display: inline-block; + text-align: left; +} .message .time { @@ -2013,7 +2065,7 @@ input[type=checkbox].hidden:not(:checked) + .list-edit-content .message-you .avatar { - float: right; + right: 4px; } .message-you .message .time @@ -2029,7 +2081,7 @@ input[type=checkbox].hidden:not(:checked) + .list-edit-content .message-you .message-wrapper { margin-left: 0; - margin-right: 12px; + margin-right: 52px; } .message-you .message-wrapper .message @@ -2054,6 +2106,43 @@ input[type=checkbox].hidden:not(:checked) + .list-edit-content border-color: transparent transparent transparent #ffc7c7; } +.chat-view +{ + overflow: auto; + height: 550px; + min-height: 400px; +} + +.chatbox +{ + border-top: 1px solid #cacaca; + width: 100%; +} + +.chatbox.ui-table +{ + border-collapse: collapse; + padding: 0; +} + +.chatbox.ui-table textarea +{ + resize: none; + margin: 0; + padding: 0; + border: 0; + width: 100%; + height: 40px; + border-right: 1px solid #cacaca; +} + +input[type=submit].chatbox-btn +{ + width: 100%; + display: block; + border: unset; + padding: 12px 0px; +} /* Instance information */ #instance-panel diff --git a/src/conversations.c b/src/conversations.c index cf2e518..4c04422 100644 --- a/src/conversations.c +++ b/src/conversations.c @@ -29,6 +29,7 @@ #include "../static/chats_page.ctmpl" #include "../static/message.ctmpl" #include "../static/chat_view.ctmpl" +#include "../static/embed.ctmpl" struct construct_message_args { @@ -156,7 +157,7 @@ void content_chats(struct session* ssn, mastodont_t* api, char** data) // TOOD cleanup chats } -void content_chat_view(struct session* ssn, mastodont_t* api, char** data) +char* construct_chat_view(struct session* ssn, mastodont_t* api, char* id, size_t* len) { struct mstdnt_args m_args; set_mstdnt_args(&m_args, ssn); @@ -177,45 +178,72 @@ void content_chat_view(struct session* ssn, mastodont_t* api, char** data) .offset = keyint(ssn->query.offset), .limit = 20, }; + + if (len) *len = 0; - if (mastodont_get_chat_messages(api, &m_args, data[0], + if (mastodont_get_chat_messages(api, &m_args, id, &args, &storage, &messages, &messages_len) || - mastodont_get_chat(api, &m_args, data[0], + mastodont_get_chat(api, &m_args, id, &storage_chat, &chat)) { - messages_html = construct_error(storage.error, E_ERROR, 1, NULL); + chats_page = construct_error(storage.error, E_ERROR, 1, NULL); } else { messages_html = construct_messages(messages, &(ssn->acct), &(chat.account), 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 chat_view_template tmpl = { + .back_link = "/chats", .prefix = config_url_prefix, .avatar = chat.account.avatar, .acct = chat.account.acct, .messages = messages_html }; - chats_page = tmpl_gen_chat_view(&tmpl, NULL); + chats_page = tmpl_gen_chat_view(&tmpl, len); } + mastodont_storage_cleanup(&storage); + mastodont_storage_cleanup(&acct_storage); + free(messages_html); + return chats_page; +} + +void content_chat_view(struct session* ssn, mastodont_t* api, char** data) +{ + char* chat_view = construct_chat_view(ssn, api, data[0], NULL); struct base_page b = { .category = BASE_CAT_CHATS, - .content = chats_page, + .content = chat_view, .sidebar_left = NULL }; - // Outpuot + // Output render_base_page(&b, ssn, api); - - // Cleanup - mastodont_storage_cleanup(&storage); - mastodont_storage_cleanup(&acct_storage); - free(chats_page); - free(messages_html); - // TOOD cleanup chats + + free(chat_view); +} + + +void content_chat_embed(struct session* ssn, mastodont_t* api, char** data) +{ + size_t result_len; + char* result; + char* chat_view = construct_chat_view(ssn, api, data[0], NULL); + + struct embed_template tmpl = { + .stylesheet = "treebird20", + .embed = chat_view, + }; + + result = tmpl_gen_embed(&tmpl, &result_len); + + // Output + send_result(NULL, NULL, result, result_len); + + free(chat_view); + free(result); } diff --git a/src/conversations.h b/src/conversations.h index a49a7fa..9dba5a5 100644 --- a/src/conversations.h +++ b/src/conversations.h @@ -37,6 +37,8 @@ char* construct_messages(struct mstdnt_message* message, size_t* ret_size); void content_chats(struct session* ssn, mastodont_t* api, char** data); +char* construct_chat_view(struct session* ssn, mastodont_t* api, char* id, size_t* len); +void content_chat_embed(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 2af8684..57983db 100644 --- a/src/main.c +++ b/src/main.c @@ -108,6 +108,7 @@ int main(void) { "/tag/:", content_tl_tag }, { "/chats/:", content_chat_view }, { "/chats", content_chats }, + { "/chats_embed/:", content_chat_embed }, // API { "/treebird_api/v1/notifications", api_notifications }, { "/treebird_api/v1/interact", api_status_interact } diff --git a/src/reply.c b/src/reply.c index 7ef2f30..2b59ef8 100644 --- a/src/reply.c +++ b/src/reply.c @@ -92,7 +92,7 @@ char* reply_status(struct session* ssn, char* id, struct mstdnt_status* status) if (port_val) *port_val = '\0'; // Load first reply - if (strcmp(status->account.acct, ssn->acct.acct) != 0) + if (ssn->logged_in && strcmp(status->account.acct, ssn->acct.acct) != 0) { replies = malloc(replies_size = strlen(status->account.acct)+2); replies[0] = '@'; diff --git a/static/chat_view.tmpl b/static/chat_view.tmpl index 22de856..236066f 100644 --- a/static/chat_view.tmpl +++ b/static/chat_view.tmpl @@ -1,15 +1,20 @@
{{ %s : messages }} +
+
+
+ +
- +
diff --git a/static/contact.tmpl b/static/contact.tmpl new file mode 100644 index 0000000..0588754 --- /dev/null +++ b/static/contact.tmpl @@ -0,0 +1,19 @@ + + + + + +
+ +
diff --git a/static/embed.tmpl b/static/embed.tmpl new file mode 100644 index 0000000..20b1112 --- /dev/null +++ b/static/embed.tmpl @@ -0,0 +1,21 @@ + + + + Embed + + + + + +
+ {{ %s : embed }} +
+ +