Skip to content

feat(notification): 按楼层关联级联删除通知#202

Open
Acture wants to merge 2 commits intomainfrom
feat/delete_notification
Open

feat(notification): 按楼层关联级联删除通知#202
Acture wants to merge 2 commits intomainfrom
feat/delete_notification

Conversation

@Acture
Copy link
Copy Markdown
Contributor

@Acture Acture commented Dec 3, 2025

变更说明

  • 移除 RelatedHoleID,通知只保留楼层维度的关联字段 RelatedFloorID
  • 在隐藏或强制删除帖子时,通过该帖子下的楼层 ID 清理关联通知,并将清理逻辑放入同一个事务中

测试

  • MODE=test GOCACHE=/tmp/treehole-next-go-cache go test ./tests -run 'TestNotificationRelatedFloorIDPersisted|TestDeleteFloorCascadeNotification|TestHideHoleCascadeNotification|TestForceDeleteHoleCascadeNotification'
  • GOCACHE=/tmp/treehole-next-go-build-cache GOMODCACHE=/tmp/treehole-next-go-mod-cache go vet ./...

@Acture Acture requested review from JingYiJun and ppolariss and removed request for ppolariss December 3, 2025 11:47
Acture added 2 commits March 27, 2026 15:38
Add related_floor_id/related_hole_id to Message model so notification
deletions can be traced back to their source content. When floors are
deleted or marked sensitive, or holes are hidden/deleted, associated
notifications and message_user records are now cleaned up.

Fixes:
- Message model now persists RelatedFloorID/RelatedHoleID (previously
  only on Notification struct, never saved to DB)
- SendSensitive correctly sets RelatedFloorID (was incorrectly using
  RelatedHoleID with a floor ID)
- Delete functions accept *gorm.DB for proper transaction support
- Explicit message_user cleanup before message deletion (SQLite
  compatibility, no FK cascade dependency)

Closes #171
- TestDeleteFloorCascadeNotification: verifies notifications are removed
  when a floor is deleted via API
- TestDeleteHoleCascadeNotification: verifies notifications are removed
  when a hole is deleted via API
- TestSendSensitiveRelatedFloorID: ensures SendSensitive sets
  RelatedFloorID (not RelatedHoleID)
- TestNotificationRelatedFieldsPersisted: verifies both related fields
  are correctly persisted to the message table
@Acture Acture force-pushed the feat/delete_notification branch from 0c943b8 to 9f03a27 Compare March 27, 2026 07:53
@Acture Acture requested review from KYLN24, SeleiXi and fsy2001 March 27, 2026 08:07
@KYLN24 KYLN24 requested review from Copilot and removed request for JingYiJun, KYLN24 and fsy2001 March 27, 2026 08:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to cascade-delete notification messages when their related content is removed/hidden (floor deleted, floor deleted due to sensitive flag, hole hidden, hole deleted), by persisting content linkage on message rows and deleting matching messages (and message_user mappings) during content removal.

Changes:

  • Add related_floor_id / related_hole_id fields to Message and plumb them through Notification.Send().
  • Introduce delete helpers DeleteMessageByRelatedFloorID / DeleteMessageByRelatedHoleID and invoke them from floor/hole deletion flows.
  • Add tests to validate persistence and cascade deletion behavior.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/message_test.go Adds tests for message persistence of related IDs and cascade deletion scenarios.
models/notification.go Extends Notification with related IDs and writes them into Message on send.
models/message.go Adds persisted RelatedFloorID / RelatedHoleID columns (indexed) to Message.
models/floor.go Sets RelatedFloorID on multiple floor-generated notification constructors.
apis/report/apis.go Sets RelatedFloorID on punishment notification created from a report.
apis/penalty/api.go Sets RelatedFloorID on penalty notifications.
apis/message/apis.go Adds shared deletion helper and exported delete-by-related-ID functions.
apis/hole/apis.go Calls delete-by-related-hole-ID in hole hide/delete endpoints.
apis/floor/apis.go Calls delete-by-related-floor-ID in floor delete and sensitive-delete flows.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Acture Acture changed the title Notification Deletion for Related Content feat(notification): 按楼层关联级联删除通知 Mar 27, 2026
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