Status deletion
FossilOrigin-Name: e29e4c081d48cf724df5597e6cb22d9977a47ba91dd1b66921a4ef8b3fd4bc67
This commit is contained in:
parent
edd88c095d
commit
d3e5c4e706
10 changed files with 140 additions and 14 deletions
2
Makefile
2
Makefile
|
@ -62,6 +62,8 @@ $(PAGES_DIR)/emoji_reactions.chtml: $(PAGES_DIR)/emoji_reactions.html
|
|||
./filec $< data_emoji_reactions_html > $@
|
||||
$(PAGES_DIR)/emoji_reaction.chtml: $(PAGES_DIR)/emoji_reaction.html
|
||||
./filec $< data_emoji_reaction_html > $@
|
||||
$(PAGES_DIR)/menu_item.chtml: $(PAGES_DIR)/menu_item.html
|
||||
./filec $< data_menu_item_html > $@
|
||||
$(PAGES_DIR)/test.chtml: $(PAGES_DIR)/test.html
|
||||
./filec $< data_test_html > $@
|
||||
$(PAGES_DIR)/notifications_page.chtml: $(PAGES_DIR)/notifications_page.html
|
||||
|
|
93
dist/js/main.js
vendored
Normal file
93
dist/js/main.js
vendored
Normal file
|
@ -0,0 +1,93 @@
|
|||
Element.prototype.insertAfter = function(element) {
|
||||
element.parentNode.insertBefore(this, element.nextSibling);
|
||||
};
|
||||
|
||||
function construct_quick_reply_form(replyid)
|
||||
{
|
||||
let src = document.createElement("form");
|
||||
src.action = "/status/create";
|
||||
src.method = "post";
|
||||
src.enctype = "multipart/form-data";
|
||||
src.className = "statusbox-quickreply";
|
||||
let hiddeninput = document.createElement("input");
|
||||
hiddeninput.type = "hidden";
|
||||
hiddeninput.name = "replyid"
|
||||
hiddeninput.value = replyid;
|
||||
let statusbox = document.createElement("div");
|
||||
statusbox.className = "statusbox statusbox-ani";
|
||||
|
||||
let textarea = document.createElement("textarea");
|
||||
textarea.placeholder = "Just landed in N.Y.";
|
||||
textarea.rows = 5;
|
||||
textarea.tabindex = 1;
|
||||
textarea.name = "content";
|
||||
|
||||
let statusfooter = document.createElement("div");
|
||||
statusfooter.className = "statusfooter";
|
||||
let statusfooter_sides = {
|
||||
left: document.createElement("div"),
|
||||
right: document.createElement("div"),
|
||||
}
|
||||
let select = document.createElement("select");
|
||||
let files_input = document.createElement("input");
|
||||
statusfooter_sides.left.className = "statusfooter-left";
|
||||
select.innerHTML = `
|
||||
<option value="public">Public</option>
|
||||
<option value="unlisted">Unlisted</option>
|
||||
<option value="private">Private</option>
|
||||
<option value="direct">Direct</option>
|
||||
<option value="local">Local</option>
|
||||
`.trim();
|
||||
files_input.type = "file";
|
||||
files_input.name = "file";
|
||||
files_input.tabindex = 4;
|
||||
files_input.multiple = "";
|
||||
|
||||
statusfooter_sides.right.className = "statusfooter-right";
|
||||
let submitbtn = document.createElement("input");
|
||||
submitbtn.className = "btn post-btn";
|
||||
submitbtn.type = "submit";
|
||||
submitbtn.value = "Post";
|
||||
submitbtn.tabindex = 2;
|
||||
|
||||
|
||||
statusfooter_sides.left.appendChild(select);
|
||||
statusfooter_sides.left.appendChild(files_input);
|
||||
statusfooter_sides.right.appendChild(submitbtn);
|
||||
statusfooter.appendChild(statusfooter_sides.left);
|
||||
statusfooter.appendChild(statusfooter_sides.right);
|
||||
statusbox.appendChild(textarea);
|
||||
statusbox.appendChild(statusfooter);
|
||||
src.appendChild(hiddeninput);
|
||||
src.appendChild(statusbox);
|
||||
return src;
|
||||
}
|
||||
|
||||
function create_reply_form(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
let status = e.target.closest(".status");
|
||||
|
||||
if (status.nextSibling.className === "statusbox-quickreply")
|
||||
{
|
||||
status.nextSibling.remove();
|
||||
}
|
||||
else {
|
||||
let form = construct_quick_reply_form(status.id);
|
||||
form.insertAfter(status);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Main
|
||||
(function() {
|
||||
let reply_btn = document.getElementsByClassName("reply-btn");
|
||||
|
||||
for (let i = 0; i < reply_btn.length; ++i)
|
||||
{
|
||||
reply_btn[i].onclick = create_reply_form;
|
||||
}
|
||||
})();
|
|
@ -157,6 +157,13 @@ static char* account_scrobbles_cb(struct session* ssn, mastodont_t* api, struct
|
|||
return scrobbles_html;
|
||||
}
|
||||
|
||||
void get_account_info(mastodont_t* api, struct session* ssn)
|
||||
{
|
||||
if (mastodont_verify_credentials(api, &(ssn->acct), &(ssn->acct_storage)) == 0)
|
||||
{
|
||||
ssn->logged_in = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void fetch_account_page(struct session* ssn,
|
||||
mastodont_t* api,
|
||||
|
|
|
@ -53,7 +53,7 @@ struct account_page
|
|||
struct mstdnt_relationship* relationship;
|
||||
};
|
||||
|
||||
|
||||
void get_account_info(mastodont_t* api, struct session* ssn);
|
||||
char* construct_account_sidebar(struct mstdnt_account* acct, size_t* size);
|
||||
|
||||
char* construct_account(mastodont_t* api,
|
||||
|
|
|
@ -47,7 +47,6 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t*
|
|||
* main_sidebar_str = NULL,
|
||||
* account_sidebar_str = NULL;
|
||||
// Mastodont, used for notifications sidebar
|
||||
struct mstdnt_account acct = { 0 };
|
||||
struct mstdnt_storage storage = { 0 };
|
||||
struct mstdnt_notification* notifs = NULL;
|
||||
size_t notifs_len = 0;
|
||||
|
@ -63,12 +62,7 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t*
|
|||
// If user is logged in
|
||||
if (keystr(ssn->cookies.logged_in) && keystr(ssn->cookies.access_token))
|
||||
{
|
||||
if (mastodont_verify_credentials(api, &acct, &storage) == 0)
|
||||
{
|
||||
account_sidebar_str = construct_account_sidebar(&acct, NULL);
|
||||
}
|
||||
mstdnt_cleanup_account(&acct);
|
||||
mastodont_storage_cleanup(&storage); // reuse it later
|
||||
account_sidebar_str = construct_account_sidebar(&(ssn->acct), NULL);
|
||||
|
||||
// Get / Show notifications on sidebar
|
||||
if (ssn->config.notif_embed)
|
||||
|
|
10
src/main.c
10
src/main.c
|
@ -120,7 +120,10 @@ int main(void)
|
|||
},
|
||||
.cookies = {{}},
|
||||
.post = {{}},
|
||||
.query = {{}}
|
||||
.query = {{}},
|
||||
.acct = { 0 },
|
||||
.acct_storage = { 0 },
|
||||
.logged_in = 0,
|
||||
};
|
||||
|
||||
// Load cookies
|
||||
|
@ -139,6 +142,9 @@ int main(void)
|
|||
// Read config options
|
||||
load_config(&ssn, &api);
|
||||
|
||||
// Load current account information
|
||||
get_account_info(&api, &ssn);
|
||||
|
||||
handle_paths(&ssn, &api, paths, sizeof(paths)/sizeof(paths[0]));
|
||||
|
||||
// Cleanup
|
||||
|
@ -146,6 +152,8 @@ int main(void)
|
|||
if (post_str) free(post_str);
|
||||
if (get_str) free(get_str);
|
||||
free_files(&(keyfile(ssn.post.files)));
|
||||
if (ssn.logged_in) mstdnt_cleanup_account(&(ssn.acct));
|
||||
mastodont_storage_cleanup(&(ssn.acct_storage));
|
||||
|
||||
++run_count;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#ifndef SESSION_H
|
||||
#define SESSION_H
|
||||
#include <mastodont.h>
|
||||
#include "query.h"
|
||||
#include "local_config.h"
|
||||
#include "cookie.h"
|
||||
|
@ -28,6 +29,9 @@ struct session
|
|||
struct get_values query;
|
||||
struct cookie_values cookies;
|
||||
struct local_config config;
|
||||
int logged_in;
|
||||
struct mstdnt_account acct;
|
||||
struct mstdnt_storage acct_storage;
|
||||
};
|
||||
|
||||
#endif // SESSION_H
|
||||
|
|
21
src/status.c
21
src/status.c
|
@ -45,6 +45,7 @@
|
|||
#include "../static/likeboost.chtml"
|
||||
#include "../static/reactions_btn.chtml"
|
||||
#include "../static/interaction_buttons.chtml"
|
||||
#include "../static/menu_item.chtml"
|
||||
|
||||
#define ACCOUNT_INTERACTIONS_LIMIT 11
|
||||
#define NUM_STR "%u"
|
||||
|
@ -149,6 +150,8 @@ int try_interact_status(struct session* ssn, mastodont_t* api, char* id)
|
|||
mastodont_pin_status(api, id, &storage, NULL);
|
||||
else if (strcmp(keystr(ssn->post.itype), "mute") == 0)
|
||||
mastodont_mute_conversation(api, id, &storage, NULL);
|
||||
else if (strcmp(keystr(ssn->post.itype), "delete") == 0)
|
||||
mastodont_delete_status(api, id, &storage, NULL);
|
||||
else if (strcmp(keystr(ssn->post.itype), "unlike") == 0)
|
||||
mastodont_unfavourite_status(api, id, &storage, NULL);
|
||||
else if (strcmp(keystr(ssn->post.itype), "unrepeat") == 0)
|
||||
|
@ -479,6 +482,7 @@ char* construct_status(struct session* ssn,
|
|||
char* interaction_btns = NULL;
|
||||
char* notif_info = NULL;
|
||||
char* in_reply_to_str = NULL;
|
||||
char* delete_status = NULL;
|
||||
char* interactions_html = NULL;
|
||||
struct mstdnt_status* status = local_status;
|
||||
// Create a "fake" notification header which contains information for
|
||||
|
@ -555,6 +559,11 @@ char* construct_status(struct session* ssn,
|
|||
|
||||
free(repl_str);
|
||||
}
|
||||
|
||||
// Delete status menu item, logged in only
|
||||
if (strcmp(status->account.acct, ssn->acct.acct) == 0)
|
||||
easprintf(&delete_status, data_menu_item_html,
|
||||
config_url_prefix, status->id, "delete", "Delete status");
|
||||
|
||||
if (status->media_attachments_len)
|
||||
attachments = construct_attachments(ssn, status->sensitive, status->media_attachments, status->media_attachments_len, NULL);
|
||||
|
@ -595,6 +604,7 @@ char* construct_status(struct session* ssn,
|
|||
status->id,
|
||||
status->bookmarked ? "un" : "",
|
||||
status->bookmarked ? "Remove Bookmark" : "Bookmark",
|
||||
delete_status ? delete_status : "",
|
||||
in_reply_to_str ? in_reply_to_str : "",
|
||||
parse_content,
|
||||
attachments ? attachments : "",
|
||||
|
@ -606,12 +616,13 @@ char* construct_status(struct session* ssn,
|
|||
// Cleanup
|
||||
if (formatted_display_name != status->account.display_name &&
|
||||
formatted_display_name) free(formatted_display_name);
|
||||
if (interaction_btns) free(interaction_btns);
|
||||
if (in_reply_to_str) free(in_reply_to_str);
|
||||
if (attachments) free(attachments);
|
||||
if (emoji_reactions) free(emoji_reactions);
|
||||
free(interaction_btns);
|
||||
free(in_reply_to_str);
|
||||
free(attachments);
|
||||
free(emoji_reactions);
|
||||
if (notif) free(notif_info);
|
||||
if (interactions_html) free(interactions_html);
|
||||
free(delete_status);
|
||||
free(interactions_html);
|
||||
if (parse_content != status->content &&
|
||||
parse_content) free(parse_content);
|
||||
return stat_html;
|
||||
|
|
6
static/menu_item.html
Normal file
6
static/menu_item.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
<li>
|
||||
<form action="%s/status/%s/interact" method="post">
|
||||
<input type="hidden" name="itype" value="%s">
|
||||
<input type="submit" class="btn-menu" value="%s">
|
||||
</form>
|
||||
</li>
|
|
@ -31,6 +31,7 @@
|
|||
<input type="submit" class="btn-menu" value="%s">
|
||||
</form>
|
||||
</li>
|
||||
%s
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue