@fabriktor/fx 0.0.162 → 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.
@@ -84,7 +84,6 @@ export type StartFeedSessionOptions = FeedPullContext & {
84
84
  export type AddFeedReactionOptions = {
85
85
  post: FeedPost;
86
86
  reaction_type: FeedReactionType;
87
- replace_existing?: boolean;
88
87
  };
89
88
  export type RemoveFeedReactionOptions = {
90
89
  post: FeedPost;
@@ -371,19 +371,21 @@ 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
- const id = resolvedID(fresh.self.reaction_id);
376
- if (id && !opts.replace_existing)
377
- throw errValidation({
378
- msg: "An action already exists for this post.",
379
- });
380
374
  if (![FeedLike, FeedDislike, FeedReport].includes(opts.reaction_type))
381
375
  throw errValidation({
382
376
  field: "reaction_type",
383
377
  msg: "Unsupported reaction.",
384
378
  });
379
+ const fresh = await this.requireFeedPost(post_id, signal);
380
+ const id = resolvedID(fresh.self.reaction_id);
385
381
  if (id) {
386
- await this.feed.deleteOneFeedReaction({ signal, 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 });
387
389
  signal.throwIfAborted();
388
390
  this.markActionRemoved(post_id, FeedAction.Reaction);
389
391
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.162",
3
+ "version": "0.0.164",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {