IMG react buttons

FossilOrigin-Name: b68a8c576c99dfbf981642f6551d02de7a74a6f3e49136d5d7005a910dfd0d3c
This commit is contained in:
nekobit 2022-06-28 06:12:08 +00:00
parent 0a5e3cd7ee
commit c3e8af299f
18 changed files with 59 additions and 6 deletions

View file

@ -55,6 +55,7 @@ char* read_cookies_env(struct cookie_values* cookies)
{ "lang", &(cookies->lang), key_int },
{ "instance_url", &(cookies->instance_url), key_string },
{ "background_url", &(cookies->background_url), key_string },
{ "interact_img", &(cookies->interact_img), key_int },
{ "client_id", &(cookies->client_id), key_string },
{ "client_secret", &(cookies->client_secret), key_string },
{ "themeclr", &(cookies->themeclr), key_int },

View file

@ -36,6 +36,7 @@ struct cookie_values
struct key jsreply;
struct key jslive;
struct key js;
struct key interact_img;
struct key stat_attachments;
struct key stat_greentexts;
struct key stat_dope;

View file

@ -31,6 +31,7 @@ struct local_config
int jsreply;
int jslive;
int js;
int interact_img;
int stat_attachments;
int stat_greentexts;
int stat_dope;

View file

@ -95,5 +95,6 @@ void load_config(struct session* ssn, mastodont_t* api)
set_config_int(LOAD_CFG_SIM("instanceshowshoutbox", instance_show_shoutbox));
set_config_int(LOAD_CFG_SIM("instancepanel", instance_panel));
set_config_int(LOAD_CFG_SIM("notifembed", notif_embed));
set_config_int(LOAD_CFG_SIM("interact_img", interact_img));
set_config_int(LOAD_CFG_SIM("lang", lang));
}

View file

@ -121,6 +121,7 @@ int main(void)
.jsreply = 1,
.jslive = 0,
.js = 1,
.interact_img = 0,
.stat_attachments = 1,
.stat_greentexts = 1,
.stat_dope = 1,

View file

@ -108,6 +108,7 @@ char* read_post_data(struct post_values* post)
{ "emojoindex", &(post->emojoindex), key_int },
{ "only_media", &(post->only_media), key_int },
{ "replies_only", &(post->replies_only), key_int },
{ "interact_img", &(post->interact_img), key_int },
{ "js", &(post->js), key_int },
{ "statattachments", &(post->stat_attachments), key_int },
{ "statgreentexts", &(post->stat_greentexts), key_int },

View file

@ -39,6 +39,7 @@ struct post_values
struct key jsreply; // Int
struct key jslive; // Int
struct key js; // Int
struct key interact_img; // Int
struct key stat_attachments; // Int
struct key stat_greentexts; // Int
struct key stat_dope; // Int

View file

@ -50,6 +50,14 @@
#include "../static/reactions_btn.ctmpl"
#include "../static/interaction_buttons.ctmpl"
#include "../static/menu_item.ctmpl"
#include "../static/like_btn.ctmpl"
#include "../static/repeat_btn.ctmpl"
#include "../static/reply_btn.ctmpl"
#include "../static/expand_btn.ctmpl"
#include "../static/like_btn_img.ctmpl"
#include "../static/repeat_btn_img.ctmpl"
#include "../static/reply_btn_img.ctmpl"
#include "../static/expand_btn_img.ctmpl"
#define ACCOUNT_INTERACTIONS_LIMIT 11
#define NUM_STR "%u"
@ -226,7 +234,10 @@ char* construct_interaction_buttons(struct session* ssn,
size_t* size,
uint8_t flags)
{
int use_img = ssn->config.interact_img;
char* interaction_html;
char* repeat_btn;
char* like_btn;
char* likeboost_html = NULL;
char* reply_count = NULL;
char* repeat_count = NULL;
@ -269,16 +280,35 @@ char* construct_interaction_buttons(struct session* ssn,
time_str = reltime_to_str(status->created_at);
// TODO cleanup?
if (use_img)
{
struct repeat_btn_img_template rpbdata = { .prefix = config_url_prefix, .repeat_active = status->reblogged ? "active" : "" };
repeat_btn = tmpl_gen_repeat_btn_img(&rpbdata, NULL);
struct like_btn_img_template ldata = { .prefix = config_url_prefix, .favourite_active = status->favourited ? "active" : "" };
like_btn = tmpl_gen_like_btn_img(&ldata, NULL);
}
else {
struct repeat_btn_template rpbdata = { .repeat_active = status->reblogged ? "active" : "" };
repeat_btn = tmpl_gen_repeat_btn(&rpbdata, NULL);
struct like_btn_template ldata = { .favourite_active = status->favourited ? "active" : "" };
like_btn = tmpl_gen_like_btn(&ldata, NULL);
}
struct interaction_buttons_template data = {
// Icons
.reply_btn = use_img ? data_reply_btn_img : data_reply_btn,
.expand_btn = use_img ? data_expand_btn_img : data_expand_btn,
.repeat_btn = repeat_btn,
.like_btn = like_btn,
// Interactions data
.prefix = config_url_prefix,
.status_id = status->id,
.reply_count = reply_count,
.unrepeat = status->reblogged ? "un" : "",
.repeat_active = status->reblogged ? "active" : "",
.repeats_count = repeat_count,
.repeat_text = "Repeat",
.unfavourite = status->favourited ? "un" : "",
.favourite_active = status->favourited ? "active" : "",
.favourites_count = favourites_count,
.favourites_text = "Favorite",
.likeboost_btn = (likeboost_html &&
@ -298,6 +328,8 @@ char* construct_interaction_buttons(struct session* ssn,
free(reactions_btn_html);
free(likeboost_html);
free(time_str);
free(like_btn);
free(repeat_btn);
return interaction_html;
}

View file

@ -55,6 +55,10 @@
<input type="checkbox" id="cfgstatoneclicksoftware" name="statoneclicksoftware" value="1" {{%s:status_oneclicksoftware_on}}>
<label for="cfgstatoneclicksoftware">Show Like-Boost button - Show a button in the status which likes and boosts a post</label>
</li>
<li>
<input type="checkbox" id="interactimg" name="interact_img" value="1" {{%s:status_interact_img_on}}>
<label for="interactimg">Use IMG for interaction buttons - Compatibility</label>
</li>
<!-- <li> -->
<!-- <input type="checkbox" id="cfgstatemojolikes" name="statemojolikes" value="1" {{%s:status_emojo_likes_on}}> -->
<!-- <label for="cfgstatemojolikes">Convert Emoji reacts to likes - Also disables the emoji reaction button</label> -->

1
static/expand_btn.tmpl Normal file
View file

@ -0,0 +1 @@
<svg class="expand" 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="M15 3h6v6M14 10l6.1-6.1M9 21H3v-6M10 14l-6.1 6.1"/></svg>

After

Width:  |  Height:  |  Size: 268 B

View file

@ -0,0 +1 @@
<img class="expand-btn-img" src="/img/compat_icons/maximize.png">

View file

@ -3,7 +3,8 @@
<tr>
<td>
<a target="_parent" href="{{%s:prefix}}/status/{{%s:status_id}}/reply#{{%s:status_id}}" class="pointer statbtn reply-btn">
<svg class="reply" 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="M14 9l6 6-6 6"/><path d="M4 4v7a4 4 0 0 0 4 4h11"/></svg>
{{ %s : reply_btn }}
<span class="count">{{%s:reply_count}}</span>
</label>
</form>
@ -12,7 +13,8 @@
<form action="{{%s:prefix}}/status/{{%s:status_id}}/interact" method="post">
<input class="itype" type="hidden" name="itype" value="{{%s:unrepeat}}repeat">
<label class="repeat-btn pointer statbtn">
<svg class="repeat {{%s:repeat_active}}" 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="M17 2.1l4 4-4 4"/><path d="M3 12.2v-2a4 4 0 0 1 4-4h12.8M7 21.9l-4-4 4-4"/><path d="M21 11.8v2a4 4 0 0 1-4 4H4.2"/></svg>
{{ %s : repeat_btn }}
<span class="count">{{%s:repeats_count}}</span>
<input class="hidden" type="submit" value="{{%s:repeat_text}}">
</label>
@ -22,7 +24,7 @@
<form action="{{%s:prefix}}/status/{{%s:status_id}}/interact" method="post">
<input class="itype" type="hidden" name="itype" value="{{%s:unfavourite}}like">
<label class="pointer statbtn like-btn">
<svg class="like {{%s:favourite_active}}" 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"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon></svg>
{{ %s : like_btn }}
<span class="count">{{%s:favourites_count}}</span>
<input class="hidden" type="submit" value="{{%s:favourites_text}}">
</label>
@ -32,7 +34,7 @@
{{%s:reactions_btn}}
<td>
<a target="_parent" href="{{%s:prefix}}/status/{{%s:status_id}}#{{%s:status_id}}" class="pointer statbtn view-btn">
<svg class="expand" 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="M15 3h6v6M14 10l6.1-6.1M9 21H3v-6M10 14l-6.1 6.1"/></svg>
{{ %s : expand_btn }}
</a>
</td>
<td>

1
static/like_btn.tmpl Normal file
View file

@ -0,0 +1 @@
<svg class="like {{%s:favourite_active}}" 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"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon></svg>

After

Width:  |  Height:  |  Size: 355 B

1
static/like_btn_img.tmpl Normal file
View file

@ -0,0 +1 @@
<img class="like-btn-img {{ %s : favourite_active }}" src="{{ %s : prefix }}/img/compat_icons/star.png">

1
static/repeat_btn.tmpl Normal file
View file

@ -0,0 +1 @@
<svg class="repeat {{%s:repeat_active}}" 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="M17 2.1l4 4-4 4"/><path d="M3 12.2v-2a4 4 0 0 1 4-4h12.8M7 21.9l-4-4 4-4"/><path d="M21 11.8v2a4 4 0 0 1-4 4H4.2"/></svg>

After

Width:  |  Height:  |  Size: 342 B

View file

@ -0,0 +1 @@
<img class="repeat-btn-img {{ %s : repeat_active }}" src="{{ %s : prefix }}/img/compat_icons/repeat.png">

1
static/reply_btn.tmpl Normal file
View file

@ -0,0 +1 @@
<svg class="reply" 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="M14 9l6 6-6 6"/><path d="M4 4v7a4 4 0 0 0 4 4h11"/></svg>

After

Width:  |  Height:  |  Size: 256 B

View file

@ -0,0 +1 @@
<img class="expand-btn-img" src="/img/compat_icons/corner-down-right.png">