{
+ let removed = false
for (const reaction of reactions) {
if (account.fullSocialIds.some((it) => it._id === reaction.modifiedBy)) {
await client.removeDoc(reaction._class, reaction.space, reaction._id)
+ removed = true
}
}
+ if (!removed && reactions.length > 0) {
+ // I just want to add my reaction
+ await client.addCollection(ratingPlugin.class.DocReaction, core.space.Workspace, _id, _class, '_reactions', {
+ reactionType: ReactionKind.Emoji,
+ value: 0,
+ emoji: reactions[0].emoji,
+ image: reactions[0].image
+ })
+ }
}
$: hasSelectedStar = _reactions.some(
@@ -101,20 +142,15 @@
-
-
+ kind={'ghost'}
+ size={'small'}
+ disabled={operating}
+ showTooltip={{ label: ratingPlugin.string.AddStar }}
+ label={showMy && starCount > 0 ? getEmbeddedLabel(starCount.toString()) : undefined}
+ />
{#each otherReactions as oreact (oreact[0])}
{@const emoji = oreact[1][0].emoji}
@@ -125,7 +161,7 @@
selected={showMy && data.some((it) => socialIds.has(it.modifiedBy))}
socialIds={data.map((it) => it.modifiedBy)}
count={showMy ? data.length : 0}
- on:click={() => removeReaction(oreact[1])}
+ on:click={() => existingReactionClick(oreact[1])}
/>
{/each}
diff --git a/plugins/rating-resources/src/components/ReactionPresenter.svelte b/plugins/rating-resources/src/components/ReactionPresenter.svelte
index 6d44dde17f2..ddaa9dea138 100644
--- a/plugins/rating-resources/src/components/ReactionPresenter.svelte
+++ b/plugins/rating-resources/src/components/ReactionPresenter.svelte
@@ -65,7 +65,7 @@
}
&.selected {
- background: var(--global-accent-BackgroundColor);
+ background: var(--global-accent-SkyText);
}
}
diff --git a/server-plugins/rating/src/index.ts b/server-plugins/rating/src/index.ts
index b5a07b94845..33f9dd0c3f5 100644
--- a/server-plugins/rating/src/index.ts
+++ b/server-plugins/rating/src/index.ts
@@ -76,24 +76,20 @@ export class RatingMiddleware extends BaseMiddleware {
}
private async validateNewReaction (ctx: MeasureContext, create: TxCreateDoc): Promise {
- if (create.attributes.reactionType !== ReactionKind.Star) {
- // Should allow only one reaction per document per user for Emoji, Like, Usefull
- const current = await this.provideFindAll(ctx, rating.class.DocReaction, {
- attachedTo: create.attachedTo,
- attachedToClass: create.objectClass
- })
- if (
- current.some(
- (it) =>
- it.reactionType === create.attributes.reactionType &&
- (it.value === create.attributes.value ||
- (create.attributes.reactionType === ReactionKind.Emoji && it.emoji === create.attributes.emoji))
- )
- ) {
- throw new Error('Duplicate emoji reaction is not allowed.')
- }
- } else {
- // For stars, we probable need to merge them into one value.
+ // Should allow only one reaction per document per user for Emoji, Like, Usefull
+ const current = await this.provideFindAll(ctx, rating.class.DocReaction, {
+ attachedTo: create.attachedTo,
+ attachedToClass: create.objectClass
+ })
+ if (
+ current.some(
+ (it) =>
+ it.reactionType === create.attributes.reactionType &&
+ (it.value === create.attributes.value ||
+ (create.attributes.reactionType === ReactionKind.Emoji && it.emoji === create.attributes.emoji))
+ )
+ ) {
+ throw new Error('Duplicate emoji reaction is not allowed.')
}
}