added foreign reaction capabilties (chuckya)

This commit is contained in:
ari melody 2024-07-05 14:32:23 +01:00
parent a9fdd913f3
commit 7f993ee538
Signed by: ari
GPG key ID: CF99829C92678188
3 changed files with 31 additions and 20 deletions

View file

@ -16,8 +16,9 @@ const server_types = {
}; };
export const capabilities = { export const capabilities = {
MARKDOWN_CONTENT: "mdcontent", MARKDOWN_CONTENT: "markdown_content",
REACTIONS: "reactions", REACTIONS: "reactions",
FOREIGN_REACTIONS: "foreign_reactions",
}; };
// if server is falsy, assume user has not begun the login process. // if server is falsy, assume user has not begun the login process.
@ -118,6 +119,7 @@ function getCapabilities(type) {
break; break;
case server_types.CHUCKYA: case server_types.CHUCKYA:
c.push(capabilities.REACTIONS); c.push(capabilities.REACTIONS);
c.push(capabilities.FOREIGN_REACTIONS);
break; break;
case server_types.FIREFISH: case server_types.FIREFISH:
c.push(capabilities.REACTIONS); c.push(capabilities.REACTIONS);

View file

@ -11,7 +11,6 @@
import RepostIcon from '../../../img/icons/repost.svg'; import RepostIcon from '../../../img/icons/repost.svg';
import FavouriteIcon from '../../../img/icons/like.svg'; import FavouriteIcon from '../../../img/icons/like.svg';
import FavouriteIconFill from '../../../img/icons/like_fill.svg'; import FavouriteIconFill from '../../../img/icons/like_fill.svg';
import ReactIcon from '../../../img/icons/react.svg';
import QuoteIcon from '../../../img/icons/quote.svg'; import QuoteIcon from '../../../img/icons/quote.svg';
import MoreIcon from '../../../img/icons/more.svg'; import MoreIcon from '../../../img/icons/more.svg';
@ -45,23 +44,6 @@
post.favourite_count = data.favourites_count; post.favourite_count = data.favourites_count;
if (data.reactions) post.reactions = parseReactions(data.reactions); if (data.reactions) post.reactions = parseReactions(data.reactions);
} }
async function toggleReaction(reaction) {
if (reaction.name.includes('@')) return;
let data;
if (reaction.me)
data = await api.unreactPost(get(server).host, get(app).token, post.id, reaction.name);
else
data = await api.reactPost(get(server).host, get(app).token, post.id, reaction.name);
if (!data) {
console.error(`Failed to favourite post ${post.id}`);
return;
}
post.favourited = data.favourited;
post.favourite_count = data.favourites_count;
if (data.reactions) post.reactions = parseReactions(data.reactions);
}
</script> </script>
<div class="post-actions" aria-label="Post actions" on:mouseup|stopPropagation on:keydown|stopPropagation> <div class="post-actions" aria-label="Post actions" on:mouseup|stopPropagation on:keydown|stopPropagation>

View file

@ -1,8 +1,35 @@
<script> <script>
import * as api from '$lib/api.js';
import { server, capabilities } from '$lib/client/server.js';
import { app } from '$lib/client/app.js';
import { get } from 'svelte/store';
import { parseReactions } from '$lib/post.js';
import ReactionButton from './ReactionButton.svelte'; import ReactionButton from './ReactionButton.svelte';
import ReactIcon from '../../../img/icons/react.svg'; import ReactIcon from '../../../img/icons/react.svg';
export let post; export let post;
async function toggleReaction(reaction) {
if (
reaction.name.includes('@') &&
!$server.capabilities.includes(capabilities.FOREIGN_REACTIONS)
) return;
let data;
if (reaction.me)
data = await api.unreactPost(get(server).host, get(app).token, post.id, reaction.name);
else
data = await api.reactPost(get(server).host, get(app).token, post.id, reaction.name);
if (!data) {
console.error(`Failed to favourite post ${post.id}`);
return;
}
post.favourited = data.favourited;
post.favourite_count = data.favourites_count;
if (data.reactions) post.reactions = parseReactions(data.reactions);
}
</script> </script>
<div class="post-reactions" aria-label="Reactions" on:mouseup|stopPropagation on:keydown|stopPropagation> <div class="post-reactions" aria-label="Reactions" on:mouseup|stopPropagation on:keydown|stopPropagation>
@ -12,7 +39,7 @@
on:click={() => toggleReaction(reaction)} on:click={() => toggleReaction(reaction)}
bind:active={reaction.me} bind:active={reaction.me}
bind:count={reaction.count} bind:count={reaction.count}
disabled={reaction.name.includes('@')} disabled={reaction.name.includes('@') && !$server.capabilities.includes(capabilities.FOREIGN_REACTIONS)}
title={reaction.name} title={reaction.name}
label=""> label="">
{#if reaction.url} {#if reaction.url}