Skip to content

Post deleted event serialization#1619

Draft
mike182uk wants to merge 3 commits intomainfrom
cursor/BER-3166-post-deleted-event-serialization-bd92
Draft

Post deleted event serialization#1619
mike182uk wants to merge 3 commits intomainfrom
cursor/BER-3166-post-deleted-event-serialization-bd92

Conversation

@mike182uk
Copy link
Member

Refactor PostDeletedEvent to implement SerializableEvent and use primitive data to comply with ADR-0011 and ensure event data persistence after post deletion.

The PostDeletedEvent previously contained the full Post entity, which is problematic for deletion events as the post may no longer exist in the database when the event is processed. This change ensures all necessary data for federation and other consumers is explicitly stored as primitive, serializable fields within the event itself.


Linear Issue: BER-3166

Open in Web Open in Cursor 

cursoragent and others added 2 commits February 26, 2026 15:08
- Replace Post entity with primitive fields in PostDeletedEvent
- Add toJSON/fromJSON for serialization support
- Update all consumers (FediverseBridge, FeedUpdateService,
  NotificationEventService, GhostPostService) to use new getters
- Change FeedService.removePostFromDiscoveryFeeds to accept postId
- Change NotificationService.removePostNotifications to accept postId
- Register PostDeletedEvent with EventSerializer in app.ts
- Add comprehensive unit tests for serialization/deserialization
- Update existing tests across all affected services

Co-authored-by: Michael Barrett <mike182uk@users.noreply.github.com>
- Remove unused Post import from feed.service.ts
- Fix formatting in feed.service.integration.test.ts
- Handle nullable apFollowers in post repository event emission

Co-authored-by: Michael Barrett <mike182uk@users.noreply.github.com>
@cursor
Copy link

cursor bot commented Feb 26, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@coderabbitai
Copy link

coderabbitai bot commented Feb 26, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cursor/BER-3166-post-deleted-event-serialization-bd92

Comment @coderabbitai help to get the list of available commands and usage tips.

await deleteActivity.toJsonLd(),
);

await this.sendActivityToFollowers(post.author, deleteActivity);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursoragent Why did you change this to use ctx.sendActivity directly?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking a look!

Open in Web Open in Cursor 

const post = event.getPost();
const postId = event.getPostId();

if (post.id !== null) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursoragent Hm, why did we account for this originally if we don't need to now?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking a look!

Open in Web Open in Cursor 

return this.authorIsInternal;
}

static getName(): string {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursoragent Lets add non-static version whilst we are here

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking a look!

Open in Web Open in Cursor 


// Remove the post from discovery feeds
await feedService.removePostFromDiscoveryFeeds(post);
await feedService.removePostFromDiscoveryFeeds(post.id as number);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursoragent Why do we need as number?

Copy link

@cursor cursor bot Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed. The as number was needed because Post.id is typed as number | null, and the method now accepts number. But as number is a blunt type assertion — I've replaced it with post.id!, which is the more idiomatic non-null assertion for cases where we know the post has been saved and therefore has an id.

Open in Web Open in Cursor 

- Revert to using sendActivityToFollowers in FediverseBridge instead
  of inlining ctx.sendActivity directly
- Add non-static getName() instance method to PostDeletedEvent
- Replace 'as number' casts with non-null assertions in tests
- Add test for instance getName() method

Co-authored-by: Michael Barrett <mike182uk@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants