From 97bd6b561d3c27698d1467c4d7521b6f685d25ae Mon Sep 17 00:00:00 2001 From: nekobit Date: Fri, 8 Jul 2022 06:15:52 +0000 Subject: [PATCH] Contacts improvement FossilOrigin-Name: 2322ec181715393e20da17a234610d61189d082cf32e09b61d79aeaca0e7615b --- dist/js/main.js | 4 +-- dist/treebird20.css | 44 +++++++++++++++++++++--- src/conversations.c | 58 ++++++++++++++++++++++++++++---- src/conversations.h | 11 ++++-- src/notifications.c | 2 ++ static/chat.tmpl | 15 ++++----- static/notification_compact.tmpl | 2 +- 7 files changed, 113 insertions(+), 23 deletions(-) diff --git a/dist/js/main.js b/dist/js/main.js index 85a1501..57b0d9b 100644 --- a/dist/js/main.js +++ b/dist/js/main.js @@ -134,8 +134,8 @@ function change_count_text(val, sum) function interact_action(status, type) { - let like = status.querySelector(".like"); - let repeat = status.querySelector(".repeat"); + let like = status.querySelector(".statbtn .like"); + let repeat = status.querySelector(".statbtn .repeat"); let svg; if (type.value === "like" || type.value === "unlike") diff --git a/dist/treebird20.css b/dist/treebird20.css index 3d4c973..e5f3637 100644 --- a/dist/treebird20.css +++ b/dist/treebird20.css @@ -38,6 +38,7 @@ ul #main-page { + position: relative; margin: 8px; margin-top: 0; width: 1000px; @@ -46,6 +47,7 @@ ul box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.1); border: 1px solid rgba(200, 200, 200, 0.7); border-radius: 5px; + overflow: hidden; } .hidden, @@ -662,7 +664,12 @@ svg.in-reply-to-icon { color: #808080; font-size: 12px; - padding: 2px 0 2px 0; + padding: 4px 0 2px 0; +} + +.notification-compact .notification-content.is-mention +{ + color: #101010; } .notification-compact .notification-stats @@ -740,7 +747,7 @@ svg.in-reply-to-icon border-spacing: 0px; } -.status-hide:checked + .status .status-table +.status-hide:checked + .status { padding: 5px 10px; } @@ -1237,7 +1244,7 @@ p} display: inline-block; position: relative; left: 155px; - top: 185px; + top: 192px; font-weight: bold; text-shadow: 0px 2px 6px #000; } @@ -2046,6 +2053,23 @@ input[type=checkbox].hidden:not(:checked) + .list-edit-content } /* Chats */ +.contact +{ + padding: 4px; +} + +.contact-right +{ + padding: 4px; + margin-left: 3px; +} + +.last-message +{ + margin-top: 6px; + color: #808080; +} + .message-container { position: relative; @@ -2157,6 +2181,18 @@ input[type=checkbox].hidden:not(:checked) + .list-edit-content border-color: transparent transparent transparent #ffc7c7; } +.empty-chat-text +{ + font-style: italic; + color: #404040; +} + +.empty-chat-text:after +{ + content: "..."; +} + + .chat-view { overflow: auto; @@ -2447,7 +2483,7 @@ input[type=submit].chatbox-btn #rightbar { - position: fixed; + position: absolute; right: 0px; height: 100%; z-index: 100; diff --git a/src/conversations.c b/src/conversations.c index 4c04422..5dee6ae 100644 --- a/src/conversations.c +++ b/src/conversations.c @@ -39,29 +39,74 @@ struct construct_message_args size_t msg_size; // Read messages backwards }; -char* construct_chat(struct mstdnt_chat* chat, size_t* size) +struct construct_chats_args +{ + mastodont_t* api; + struct mstdnt_args* args; + struct mstdnt_chat* chats; +}; + +char* construct_chat(mastodont_t* api, + struct mstdnt_args* m_args, + struct mstdnt_chat* chat, + size_t* size) { char* result; + char* msg_id = NULL; + char* last_message = "Chat created"; + + // Get latest message + struct mstdnt_storage storage = { 0 }; + struct mstdnt_message* messages = NULL; + size_t messages_len = 0; + + struct mstdnt_chats_args args = { + .with_muted = MSTDNT_TRUE, + .offset = 0, + .limit = 1, + }; + + if (mastodont_get_chat_messages(api, m_args, chat->id, &args, &storage, + &messages, &messages_len) == 0 && messages_len == 1) + { + last_message = messages[0].content; + msg_id = messages[0].id; + } + struct chat_template data = { .id = chat->id, .prefix = config_url_prefix, .acct = chat->account.acct, .avatar = chat->account.avatar, .display_name = chat->account.display_name, - .last_message = "", + .message_id = msg_id, + .last_message = last_message, }; result = tmpl_gen_chat(&data, size); + mastodont_storage_cleanup(&storage); + // TODO cleanup messages return result; } static char* construct_chat_voidwrap(void* passed, size_t index, size_t* res) { - return construct_chat((struct mstdnt_chat*)passed + index, res); + struct construct_chats_args* args = passed; + return construct_chat(args->api, args->args, args->chats + index, res); } -char* construct_chats(struct mstdnt_chat* chats, size_t size, size_t* ret_size) +char* construct_chats(mastodont_t* api, + struct mstdnt_args* m_args, + struct mstdnt_chat* chats, + size_t size, + size_t* ret_size) { - return construct_func_strings(construct_chat_voidwrap, chats, size, ret_size); + struct construct_chats_args args = { + .api = api, + .args = m_args, + .chats = chats, + }; + + return construct_func_strings(construct_chat_voidwrap, &args, size, ret_size); } char* construct_message(struct mstdnt_message* msg, @@ -135,7 +180,7 @@ void content_chats(struct session* ssn, mastodont_t* api, char** data) chats_page = construct_error(storage.error, E_ERROR, 1, NULL); } else { - chats_html = construct_chats(chats, chats_len, NULL); + chats_html = construct_chats(api, &m_args, chats, chats_len, NULL); if (!chats_html) chats_html = construct_error("No chats", E_NOTICE, 1, NULL); chats_page = construct_chats_view(chats_html, NULL); @@ -207,6 +252,7 @@ char* construct_chat_view(struct session* ssn, mastodont_t* api, char* id, size_ mastodont_storage_cleanup(&storage); mastodont_storage_cleanup(&acct_storage); free(messages_html); + // TODO cleanup messages return chats_page; } diff --git a/src/conversations.h b/src/conversations.h index 9dba5a5..b6117b6 100644 --- a/src/conversations.h +++ b/src/conversations.h @@ -22,8 +22,15 @@ #include #include "session.h" -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_chat(mastodont_t* api, + struct mstdnt_args* m_args, + struct mstdnt_chat* chat, + size_t* size); +char* construct_chats(mastodont_t* api, + struct mstdnt_args* m_args, + 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, diff --git a/src/notifications.c b/src/notifications.c index 81d7719..6c17841 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -126,6 +126,8 @@ char* construct_notification_compact(struct session* ssn, .display_name = display_name, .action = type_str, .notif_svg = type_svg, + .is_status = (notif->type == MSTDNT_NOTIFICATION_STATUS || + notif->type == MSTDNT_NOTIFICATION_MENTION ? "is-mention" : NULL), /* Might show follower address */ .content = (notif->type == MSTDNT_NOTIFICATION_FOLLOW ? notif->account->acct : status_format), diff --git a/static/chat.tmpl b/static/chat.tmpl index 5a9d392..c5680cb 100644 --- a/static/chat.tmpl +++ b/static/chat.tmpl @@ -1,16 +1,15 @@ - - + + -
+
+
+ {{%s:display_name}}
- diff --git a/static/notification_compact.tmpl b/static/notification_compact.tmpl index ad68017..700a66e 100644 --- a/static/notification_compact.tmpl +++ b/static/notification_compact.tmpl @@ -10,7 +10,7 @@ {{%s:action}} {{%s:notif_svg}}
-
{{%s:content}}
+
{{%s:content}}
{{%s:stats}}