FossilOrigin-Name: 74fe969864d4419e2a040bda2e5482806ed3fd390dafe66c7ec9962304cd763d
This commit is contained in:
nekobit 2022-07-05 09:44:38 +00:00
parent 434ec2e8bd
commit 95bca87556
5 changed files with 166 additions and 2 deletions

54
dist/treebird20.css vendored
View file

@ -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
{

View file

@ -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
}

View file

@ -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

View file

@ -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 },

6
static/message.tmpl Normal file
View file

@ -0,0 +1,6 @@
<div class="message-wrapper">
<div class="message" id="{{ %s : id }}">
<span class="content">{{ %s : content }}</span>
<span class="time">12:00</span>
</div>
</div>