Replying respects post visibility

FossilOrigin-Name: d5409d1ac1e3dff4878cde1a5a8a710bbfd69fc53569a0d2d74745743c597b88
This commit is contained in:
nekobit 2022-07-11 04:49:25 +00:00
parent da5e8039db
commit f110b7480a
4 changed files with 41 additions and 17 deletions

7
dist/treebird.css vendored
View File

@ -14,7 +14,6 @@ html
{
background-attachment: fixed !important;
background-size: cover !important;
background-color: unset !important;
background-color: #eee;
}
@ -936,6 +935,7 @@ svg.in-reply-to-icon
font-weight: bold;
text-overflow: ellipsis;
white-space: nowrap;
vertical-align: middle;
min-width: 0;
}
@ -1414,6 +1414,11 @@ p}
background-color: #d3d3d3;
}
.statusbox .post-group input[type=radio].hidden:disabled + .visibility-icon
{
display: none;
}
.statusbox .post-group input[type=radio].hidden:checked + .visibility-icon svg
{
stroke: #000;

View File

@ -31,21 +31,40 @@
#define ID_REPLY_SIZE 256
#define ID_RESPONSE "<input type=\"hidden\" name=\"replyid\" value=\"%s\">"
char* construct_post_box(char* reply_id,
char* construct_post_box(struct mstdnt_status* reply_status,
char* default_content,
size_t* size)
{
#define C_S "checked"
#define D_S "disabled"
char* reply_html;
char id_reply[ID_REPLY_SIZE];
enum mstdnt_visibility_type vis = MSTDNT_VISIBILITY_PUBLIC;
// Put hidden post request
snprintf(id_reply, ID_REPLY_SIZE, ID_RESPONSE, reply_id);
// Put hidden post request and check visibility
if (reply_status)
{
snprintf(id_reply, ID_REPLY_SIZE, ID_RESPONSE, reply_status->id);
vis = reply_status->visibility;
}
// Construct box
/*
* Mastodont-c orders the visibility type from smallest (PUBLIC) to
* largest (LOCAL), so we take advantage of the enum values
*/
struct post_template tdata = {
.prefix = config_url_prefix,
.reply_input = reply_id ? id_reply : NULL,
.content = default_content
.reply_input = reply_status ? id_reply : NULL,
.content = default_content,
.public_checked = vis == MSTDNT_VISIBILITY_PUBLIC ? C_S : NULL,
// You can reply with public to unlisted posts
.public_disabled = vis > MSTDNT_VISIBILITY_UNLISTED ? D_S : NULL,
.unlisted_checked = vis == MSTDNT_VISIBILITY_UNLISTED ? C_S : NULL,
.unlisted_disabled = vis > MSTDNT_VISIBILITY_UNLISTED ? D_S : NULL,
.private_checked = vis == MSTDNT_VISIBILITY_PRIVATE ? C_S : NULL,
.private_disabled = vis > MSTDNT_VISIBILITY_PRIVATE ? D_S : NULL,
.direct_checked = vis == MSTDNT_VISIBILITY_DIRECT ? C_S : NULL,
.local_checked = vis == MSTDNT_VISIBILITY_LOCAL ? C_S : NULL,
};
return tmpl_gen_post(&tdata, size);
}
@ -54,9 +73,9 @@ char* construct_post_box(char* reply_id,
* - Misskey does not return <span>, but we still regex to make sure it's a highlight
* - The order of parameters in a tag can be changed (mastodon does this),
* so we just grep for regex href
* - Misskey/Mastodon adds an @ symbol in the href param, while pleroma adds /users
* - Misskey/Mastodon adds an @ symbol in the href param, while pleroma adds /users and honk adds /u
*/
#define REGEX_REPLY "<a .*?href=\"https?:\\/\\/(.*?)\\/(?:@|users/)?(.*?)?\".*?>@(?:<span>)?.*?(?:<\\/span>)?"
#define REGEX_REPLY "<a .*?href=\"https?:\\/\\/(.*?)\\/(?:@|users/|u/)?(.*?)?\".*?>@(?:<span>)?.*?(?:<\\/span>)?"
char* reply_status(struct session* ssn, char* id, struct mstdnt_status* status)
{
@ -156,7 +175,7 @@ char* reply_status(struct session* ssn, char* id, struct mstdnt_status* status)
pcre2_match_data_free(re_data);
stat_reply = construct_post_box(id, replies, NULL);
stat_reply = construct_post_box(status, replies, NULL);
pcre2_code_free(re);
free(replies);
free(instance_domain);

View File

@ -22,7 +22,7 @@
#include <stddef.h>
#include <mastodont.h>
char* construct_post_box(char* reply_id,
char* construct_post_box(struct mstdnt_status* reply_id,
char* default_content,
size_t* size);

View File

@ -5,7 +5,7 @@
<div class="statusfooter">
<div class="statusfooter-left">
<select tabindex="3" name="contenttype" class="content-type">
<option value="plaintext">Plain</option>
<option value="plaintext">Plain Text</option>
<option value="markdown">Markdown</option>
<option value="html">HTML</option>
<option value="bbcode">BBCode</option>
@ -13,35 +13,35 @@
<div class="post-group">
<!-- Local -->
<label>
<input type="radio" name="visibility" value="local" class="hidden">
<input type="radio" name="visibility" value="local" class="hidden" {{ %s : local_checked }}>
<div class="visibility-icon vis-local">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 9v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V9"/><path d="M9 22V12h6v10M2 10.6L12 2l10 8.6"/></svg>
</div>
</label>
<!-- Direct -->
<label>
<input type="radio" name="visibility" value="direct" class="hidden">
<input type="radio" name="visibility" value="direct" class="hidden" {{ %s : direct_checked }}>
<div class="visibility-icon vis-direct">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"></path><polyline points="22,6 12,13 2,6"></polyline></svg>
</div>
</label>
<!-- Private -->
<label>
<input type="radio" name="visibility" value="private" class="hidden">
<input type="radio" name="visibility" value="private" class="hidden" {{ %s : private_checked }} {{ %s : private_disabled }}>
<div class="visibility-icon vis-private">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>
</div>
</label>
<!-- Unlisted -->
<label>
<input type="radio" name="visibility" value="unlisted" class="hidden">
<input type="radio" name="visibility" value="unlisted" class="hidden" {{ %s : unlisted_checked }} {{ %s : unlisted_disabled }}>
<div class="visibility-icon vis-unlisted">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 9.9-1"></path></svg>
</div>
</label>
<!-- Public -->
<label>
<input type="radio" name="visibility" value="public" class="hidden" checked>
<input type="radio" name="visibility" value="public" class="hidden" {{ %s : public_checked }} {{ %s : public_disabled }}>
<div class="visibility-icon vis-public">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="2" y1="12" x2="22" y2="12"></line><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"></path></svg>
</div>