More chat stuff, chat embeds, fix segfault
FossilOrigin-Name: 4f3d242139e6ea4c8050858ce6be541c415bbf5c4388f81648495df8f534ff31
This commit is contained in:
parent
db83718dde
commit
969f12e347
8 changed files with 193 additions and 28 deletions
107
dist/treebird20.css
vendored
107
dist/treebird20.css
vendored
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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] = '@';
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
<div class="page-header">
|
||||
<span class="page-header-button">←</span>
|
||||
<img src="{{ %s : avatar }}" class="page-header-image">
|
||||
<a href="{{ %s : prefix }}{{ %s : back_link }}" class="page-header-button">←</a>
|
||||
<img src="{{ %s : avatar }}" class="page-header-image avatar">
|
||||
<a href="{{ %s : prefix }}/@{{%s:acct}}" class="page-header-title">{{ %s : acct }}</a>
|
||||
</div>
|
||||
<div class="chat-view">
|
||||
{{ %s : messages }}
|
||||
</div>
|
||||
<form action="" method="post">
|
||||
<table class="chatbox ui-table">
|
||||
<tr>
|
||||
<td>
|
||||
<textarea></textarea>
|
||||
</td>
|
||||
<td>
|
||||
<input type="submit" class="chatbox-btn btn" value="Send">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
|
|
19
static/contact.tmpl
Normal file
19
static/contact.tmpl
Normal file
|
@ -0,0 +1,19 @@
|
|||
<table class="account-stub">
|
||||
<tr>
|
||||
<td class="pfp-td">
|
||||
<a href="{{%s:prefix}}/@{{%s:acct}}"><img src="{{%s:avatar}}"></a>
|
||||
</td>
|
||||
<td class="account-stub-info-wrapper">
|
||||
<div class="account-stub-info">
|
||||
<a href="{{%s:prefix}}/@{{%s:acct}}">
|
||||
<div class="account-stub-top">
|
||||
<span class="username">{{%s:display_name}}</span>
|
||||
</div>
|
||||
<div class="account-stub-bottom">
|
||||
<span class="instance-info">@{{%s:acct}}</span>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
21
static/embed.tmpl
Normal file
21
static/embed.tmpl
Normal file
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Embed</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="/{{ %s : stylesheet }}.css">
|
||||
<style>
|
||||
html, body
|
||||
{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: unset;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="embed">
|
||||
{{ %s : embed }}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue