forked from mirrors/treebird
Notifications + rework function names
FossilOrigin-Name: 5a4873ba910b6b8b852821d0bede6a584f406635aa168633318d19600a7bd2de
This commit is contained in:
parent
c407aac8ce
commit
d1d0e1e9fe
13 changed files with 110 additions and 27 deletions
|
@ -100,11 +100,11 @@ void content_account(mastodont_t* api, char** data, size_t size)
|
|||
};
|
||||
|
||||
/* Output */
|
||||
render_base_page(&b);
|
||||
render_base_page(&b, api);
|
||||
|
||||
/* Cleanup */
|
||||
mastodont_storage_cleanup(&storage);
|
||||
mastodont_storage_cleanup(&status_storage);
|
||||
cleanup_statuses(statuses, status_len);
|
||||
mstdnt_cleanup_statuses(statuses, status_len);
|
||||
if (cleanup) free(account_page);
|
||||
}
|
||||
|
|
|
@ -22,24 +22,52 @@
|
|||
#include "base_page.h"
|
||||
#include "easprintf.h"
|
||||
#include "cookie.h"
|
||||
#include "notifications.h"
|
||||
#include "../config.h"
|
||||
|
||||
// Files
|
||||
#include "../static/index.chtml"
|
||||
|
||||
void render_base_page(struct base_page* page)
|
||||
void render_base_page(struct base_page* page, mastodont_t* api)
|
||||
{
|
||||
char* cookie = getenv("HTTP_COOKIE");
|
||||
enum l10n_locale locale = page->locale;
|
||||
char* login_string = "<a href=\"login\" id=\"login-header\">Login / Register</a>";
|
||||
char* sidebar_str = NULL;
|
||||
// Mastodont, used for notifications sidebar
|
||||
struct mstdnt_storage storage;
|
||||
struct mstdnt_notification* notifs;
|
||||
size_t notifs_len;
|
||||
|
||||
if (!g_config.changed && cookie)
|
||||
{
|
||||
if (cookies.theme)
|
||||
g_config.theme = cookies.theme;
|
||||
if (cookies.logged_in && strcmp(cookies.logged_in, "t") == 0)
|
||||
if (cookies.logged_in)
|
||||
login_string = "";
|
||||
}
|
||||
|
||||
// Get / Show notifications on sidebar
|
||||
if (cookies.logged_in)
|
||||
{
|
||||
struct mstdnt_get_notifications_args args = {
|
||||
.exclude_types = 0,
|
||||
.account_id = NULL,
|
||||
.exclude_visibilities = 0,
|
||||
.include_types = 0,
|
||||
.with_muted = 1,
|
||||
.max_id = NULL,
|
||||
.min_id = NULL,
|
||||
.since_id = NULL,
|
||||
.offset = 2,
|
||||
.limit = 15,
|
||||
};
|
||||
|
||||
mastodont_get_notifications(api, &args, &storage, ¬ifs, ¬ifs_len);
|
||||
sidebar_str = construct_notifications_compact(notifs, notifs_len, NULL);
|
||||
|
||||
//mstdnt_cleanup_notifications(notifs, notifs_len);
|
||||
}
|
||||
|
||||
char* data;
|
||||
int len = easprintf(&data, data_index_html,
|
||||
|
@ -65,17 +93,22 @@ void render_base_page(struct base_page* page)
|
|||
L10N[locale][L10N_DIRECT],
|
||||
config_url_prefix,
|
||||
L10N[locale][L10N_CONFIG],
|
||||
page->content);
|
||||
page->content,
|
||||
sidebar_str ? sidebar_str : "<p>Not logged in</p>");
|
||||
|
||||
if (!data)
|
||||
{
|
||||
perror("malloc");
|
||||
return;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
fputs("Content-type: text/html\r\n", stdout);
|
||||
printf("Content-Length: %d\r\n\r\n", len + 1);
|
||||
puts(data);
|
||||
|
||||
// Cleanup
|
||||
/* cleanup_all: */
|
||||
free(data);
|
||||
cleanup:
|
||||
if (sidebar_str) free(sidebar_str);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#ifndef BASE_PAGE_H
|
||||
#define BASE_PAGE_H
|
||||
#include <mastodont.h>
|
||||
#include "l10n.h"
|
||||
#include "local_config.h"
|
||||
|
||||
|
@ -28,6 +29,6 @@ struct base_page
|
|||
char* sidebar_right;
|
||||
};
|
||||
|
||||
void render_base_page(struct base_page* page);
|
||||
void render_base_page(struct base_page* page, mastodont_t* api);
|
||||
|
||||
#endif // BASE_PAGE_H
|
||||
|
|
|
@ -90,7 +90,7 @@ void content_lists(mastodont_t* api, char** data, size_t size)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b);
|
||||
render_base_page(&b, api);
|
||||
|
||||
// Cleanup
|
||||
mastodont_storage_cleanup(&storage);
|
||||
|
|
|
@ -82,7 +82,7 @@ void content_login(mastodont_t* api, char** data, size_t data_size)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b);
|
||||
render_base_page(&b, api);
|
||||
|
||||
// Cleanup
|
||||
mastodont_storage_cleanup(&storage);
|
||||
|
|
|
@ -23,21 +23,57 @@
|
|||
|
||||
// Pages
|
||||
#include "../static/notifications_page.chtml"
|
||||
#include "../static/notifications.chtml"
|
||||
#include "../static/notification.chtml"
|
||||
#include "../static/notification_compact.chtml"
|
||||
|
||||
static char* construct_notifications_voidwrap(void* passed, size_t index, int* res)
|
||||
char* construct_notification(struct mstdnt_notification* notif, int* size)
|
||||
{
|
||||
return construct_notifications((struct mstdnt_notification*)passed + index, res);
|
||||
char* notif_html;
|
||||
return notif_html;
|
||||
}
|
||||
|
||||
char* construct_notifications(struct mstdnt_notification* notifs, size_t size, size_t* ret_size)
|
||||
char* construct_notification_compact(struct mstdnt_notification* notif, int* size)
|
||||
{
|
||||
return construct_func_strings(construct_notifications_voidwrap, notifs, size, ret_size);
|
||||
char* notif_html;
|
||||
|
||||
size_t s = easprintf(¬if_html, data_notification_compact_html,
|
||||
notif->id);
|
||||
|
||||
if (size) *size = s;
|
||||
|
||||
return notif_html;
|
||||
}
|
||||
|
||||
static char* construct_notification_voidwrap(void* passed, size_t index, int* res)
|
||||
{
|
||||
return construct_notification((struct mstdnt_notification*)passed + index, res);
|
||||
}
|
||||
|
||||
static char* construct_notification_compact_voidwrap(void* passed, size_t index, int* res)
|
||||
{
|
||||
return construct_notification_compact((struct mstdnt_notification*)passed + index, res);
|
||||
}
|
||||
|
||||
char* construct_notifications(struct mstdnt_notification* notifs,
|
||||
size_t size,
|
||||
size_t* ret_size)
|
||||
{
|
||||
return construct_func_strings(construct_notification_voidwrap, notifs, size, ret_size);
|
||||
}
|
||||
|
||||
char* construct_notifications_compact(struct mstdnt_notification* notifs,
|
||||
size_t size,
|
||||
size_t* ret_size)
|
||||
{
|
||||
return construct_func_strings(construct_notification_compact_voidwrap,
|
||||
notifs,
|
||||
size,
|
||||
ret_size);
|
||||
}
|
||||
|
||||
void content_notifications(mastodont_t* api, char** data, size_t data_size)
|
||||
{
|
||||
|
||||
|
||||
struct base_page b = {
|
||||
.locale = L10N_EN_US,
|
||||
.content = data_notifications_page_html,
|
||||
|
@ -45,6 +81,6 @@ void content_notifications(mastodont_t* api, char** data, size_t data_size)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b);
|
||||
render_base_page(&b, api);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,17 @@
|
|||
#define NOTIFICATIONS_H
|
||||
#include <mastodont.h>
|
||||
|
||||
|
||||
char* construct_notification(struct mstdnt_notification* notif, int* size);
|
||||
char* construct_notification_compact(struct mstdnt_notification* notif, int* size);
|
||||
char* construct_notifications(struct mstdnt_notification* notifs,
|
||||
size_t size,
|
||||
size_t* ret_size);
|
||||
char* construct_notifications_compact(struct mstdnt_notification* notifs,
|
||||
size_t size,
|
||||
size_t* ret_size);
|
||||
|
||||
// Page contents
|
||||
void content_notifications(mastodont_t* api, char** data, size_t data_size);
|
||||
|
||||
#endif // NOTIFICATION_H
|
||||
|
|
|
@ -48,5 +48,5 @@ void content_config(mastodont_t* api, char** data, size_t size)
|
|||
.sidebar_right = NULL
|
||||
};
|
||||
|
||||
render_base_page(&b);
|
||||
render_base_page(&b, api);
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ void content_status(mastodont_t* api, char** data, size_t data_size, int is_repl
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b);
|
||||
render_base_page(&b, api);
|
||||
|
||||
// Cleanup
|
||||
if (before_html) free(before_html);
|
||||
|
@ -229,8 +229,8 @@ void content_status(mastodont_t* api, char** data, size_t data_size, int is_repl
|
|||
if (after_html) free(after_html);
|
||||
if (output) free(output);
|
||||
if (is_reply) free(stat_reply);
|
||||
cleanup_statuses(statuses_before, stat_before_len);
|
||||
cleanup_statuses(statuses_after, stat_after_len);
|
||||
cleanup_status(&status);
|
||||
mstdnt_cleanup_statuses(statuses_before, stat_before_len);
|
||||
mstdnt_cleanup_statuses(statuses_after, stat_after_len);
|
||||
mstdnt_cleanup_status(&status);
|
||||
mastodont_storage_cleanup(&storage);
|
||||
}
|
||||
|
|
|
@ -74,6 +74,6 @@ void content_test(mastodont_t* api, char** data, size_t data_size)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b);
|
||||
render_base_page(&b, api);
|
||||
if (page) free(page);
|
||||
}
|
||||
|
|
|
@ -70,11 +70,11 @@ void tl_public(mastodont_t* api, int local)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b);
|
||||
render_base_page(&b, api);
|
||||
|
||||
// Cleanup
|
||||
mastodont_storage_cleanup(&storage);
|
||||
cleanup_statuses(statuses, status_count);
|
||||
mstdnt_cleanup_statuses(statuses, status_count);
|
||||
if (cleanup) free(status_format);
|
||||
if (post_box) free(post_box);
|
||||
if (output) free(output);
|
||||
|
@ -121,12 +121,14 @@ void tl_list(mastodont_t* api, char* list_id)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b);
|
||||
render_base_page(&b, api);
|
||||
|
||||
// Cleanup
|
||||
mastodont_storage_cleanup(&storage);
|
||||
mstdnt_cleanup_statuses(statuses, status_count);
|
||||
if (cleanup) free(status_format);
|
||||
if (post_box) free(post_box);
|
||||
if (output) free(output);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
|
||||
<!-- Notifications and such -->
|
||||
<td id="rightbar" class="sidebar">
|
||||
Sidebar
|
||||
%s
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -1 +1 @@
|
|||
notif_compact
|
||||
%s<br>
|
||||
|
|
Loading…
Reference in a new issue