@fabriktor/fx 0.0.163 → 0.0.164

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -371,16 +371,24 @@ export class FeedFX {
371
371
  async addReaction(opts) {
372
372
  const post_id = feedPostID(opts.post);
373
373
  return await this.runAction(post_id, FeedAction.Reaction, async (signal) => {
374
- const fresh = await this.requireFeedPost(post_id, signal);
375
- if (resolvedID(fresh.self.reaction_id))
376
- throw errValidation({
377
- msg: "An action already exists for this post.",
378
- });
379
374
  if (![FeedLike, FeedDislike, FeedReport].includes(opts.reaction_type))
380
375
  throw errValidation({
381
376
  field: "reaction_type",
382
377
  msg: "Unsupported reaction.",
383
378
  });
379
+ const fresh = await this.requireFeedPost(post_id, signal);
380
+ const id = resolvedID(fresh.self.reaction_id);
381
+ if (id) {
382
+ const current = await this.readOwnReaction({ id, signal });
383
+ if (!current)
384
+ throw errValidation({ msg: msgFeedReactionMissing });
385
+ if (current.reaction_type === opts.reaction_type ||
386
+ current.reaction_type === FeedReport)
387
+ throw errValidation({ msg: msgFeedReactionAlreadyExists });
388
+ await this.feed.deleteOneFeedReaction({ id, signal });
389
+ signal.throwIfAborted();
390
+ this.markActionRemoved(post_id, FeedAction.Reaction);
391
+ }
384
392
  const out = await this.feed.insertOneFeedReaction({
385
393
  signal,
386
394
  in: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.163",
3
+ "version": "0.0.164",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {