Chats page
FossilOrigin-Name: 397b4d1c5981fe12defbe8d643a4cc8deba637d3ccbbf465c919fe91ab512d78
This commit is contained in:
parent
c0ccb74569
commit
434ec2e8bd
8 changed files with 166 additions and 0 deletions
|
@ -149,6 +149,8 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t*
|
|||
.bookmarks = L10N[locale][L10N_BOOKMARKS],
|
||||
.active_direct = CAT_TEXT(page->category, BASE_CAT_DIRECT),
|
||||
.direct = L10N[locale][L10N_DIRECT],
|
||||
.active_chats = CAT_TEXT(page->category, BASE_CAT_CHATS),
|
||||
.chats = "Chats",
|
||||
.active_config = CAT_TEXT(page->category, BASE_CAT_CONFIG),
|
||||
.config = L10N[locale][L10N_CONFIG],
|
||||
.sidebar_leftbar = page->sidebar_left,
|
||||
|
|
|
@ -34,6 +34,7 @@ enum base_category
|
|||
BASE_CAT_FAVOURITES,
|
||||
BASE_CAT_BOOKMARKS,
|
||||
BASE_CAT_DIRECT,
|
||||
BASE_CAT_CHATS,
|
||||
BASE_CAT_CONFIG,
|
||||
};
|
||||
|
||||
|
|
108
src/conversations.c
Normal file
108
src/conversations.c
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Treebird - Lightweight frontend for Pleroma
|
||||
* Copyright (C) 2022 Nekobit
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "../config.h"
|
||||
#include "conversations.h"
|
||||
#include "helpers.h"
|
||||
#include "string_helpers.h"
|
||||
#include "error.h"
|
||||
#include "base_page.h"
|
||||
|
||||
// Files
|
||||
#include "../static/chat.ctmpl"
|
||||
#include "../static/chats_page.ctmpl"
|
||||
|
||||
char* construct_chat(struct mstdnt_chat* chat, size_t* size)
|
||||
{
|
||||
char* result;
|
||||
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 = "",
|
||||
};
|
||||
result = tmpl_gen_chat(&data, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
static char* construct_chat_voidwrap(void* passed, size_t index, size_t* res)
|
||||
{
|
||||
return construct_chat((struct mstdnt_chat*)passed + index, res);
|
||||
}
|
||||
|
||||
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_chats_view(char* lists_string, size_t* size)
|
||||
{
|
||||
struct chats_page_template data = {
|
||||
.content = lists_string,
|
||||
};
|
||||
return tmpl_gen_chats_page(&data, size);
|
||||
}
|
||||
|
||||
void content_chats(struct session* ssn, mastodont_t* api, char** data)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
struct mstdnt_chat* chats = NULL;
|
||||
size_t chats_len = 0;
|
||||
struct mstdnt_storage storage = { 0 };
|
||||
char* chats_page = NULL;
|
||||
char* chats_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_chats_v2(api, &m_args, &args, &storage, &chats, &chats_len))
|
||||
{
|
||||
chats_page = construct_error(storage.error, E_ERROR, 1, NULL);
|
||||
}
|
||||
else {
|
||||
chats_html = construct_chats(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);
|
||||
}
|
||||
|
||||
struct base_page b = {
|
||||
.category = BASE_CAT_CHATS,
|
||||
.content = chats_page,
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
// Outpuot
|
||||
render_base_page(&b, ssn, api);
|
||||
|
||||
// Cleanup
|
||||
mastodont_storage_cleanup(&storage);
|
||||
free(chats_page);
|
||||
free(chats_html);
|
||||
// TOOD cleanup chats
|
||||
}
|
31
src/conversations.h
Normal file
31
src/conversations.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Treebird - Lightweight frontend for Pleroma
|
||||
* Copyright (C) 2022 Nekobit
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CONVERSATIONS_H
|
||||
#define CONVERSATIONS_H
|
||||
#include <stddef.h>
|
||||
#include <mastodont.h>
|
||||
#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_chats_view(char* lists_string, size_t* size);
|
||||
|
||||
void content_chats(struct session* ssn, mastodont_t* api, char** data);
|
||||
|
||||
#endif // LISTS_H
|
|
@ -40,6 +40,7 @@
|
|||
#include "about.h"
|
||||
#include "local_config_set.h"
|
||||
#include "global_cache.h"
|
||||
#include "conversations.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
@ -105,6 +106,7 @@ int main(void)
|
|||
{ "/notifications_compact", content_notifications_compact },
|
||||
{ "/notifications", content_notifications },
|
||||
{ "/tag/:", content_tl_tag },
|
||||
{ "/chats", content_chats },
|
||||
// API
|
||||
{ "/treebird_api/v1/notifications", api_notifications },
|
||||
{ "/treebird_api/v1/interact", api_status_interact }
|
||||
|
|
20
static/chat.tmpl
Normal file
20
static/chat.tmpl
Normal file
|
@ -0,0 +1,20 @@
|
|||
<a href="{{%s:prefix}}/chats/{{%s:id}}">
|
||||
<table class="account-stub">
|
||||
<tr>
|
||||
<td class="pfp-td">
|
||||
<img src="{{%s:avatar}}">
|
||||
</td>
|
||||
<td class="account-stub-info-wrapper">
|
||||
<div class="account-stub-info">
|
||||
<div class="account-stub-top">
|
||||
<span class="username">{{%s:display_name}}</span>
|
||||
<span class="instance-info">@{{%s:acct}}</span>
|
||||
</div>
|
||||
<div class="account-stub-bottom">
|
||||
<span class="chat-msg-preview">{{ %s : last_message }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</a>
|
1
static/chats_page.tmpl
Normal file
1
static/chats_page.tmpl
Normal file
|
@ -0,0 +1 @@
|
|||
{{ %s : content }}
|
|
@ -49,6 +49,7 @@
|
|||
<li><a class="sidebarbtn {{ %s : active_favourites }}" href="{{ %s : prefix}}/favourites">{{ %s : favourites }}</a></li>
|
||||
<li><a class="sidebarbtn {{ %s : active_bookmarks }}" href="{{ %s : prefix}}/bookmarks">{{ %s : bookmarks }}</a></li>
|
||||
<li><a class="sidebarbtn {{ %s : active_direct }}" href="{{ %s : prefix}}/direct">{{ %s : direct }}</a></li>
|
||||
<li><a class="sidebarbtn {{ %s : active_chats }}" href="{{ %s : prefix}}/chats">{{ %s : chats }}</a></li>
|
||||
<li><a class="sidebarbtn {{ %s : active_config }}" href="{{ %s : prefix}}/config">{{ %s : config }}</a></li>
|
||||
</ul>
|
||||
{{ %s : sidebar_leftbar }}
|
||||
|
|
Loading…
Reference in a new issue