Skip to content

完善消息去重并增加说明文档 - #580

Merged
CJKmkp merged 4 commits into
InkCanvasForClass:net6from
chenjei2011:feature/notification-dedup-alter
Jul 27, 2026
Merged

完善消息去重并增加说明文档#580
CJKmkp merged 4 commits into
InkCanvasForClass:net6from
chenjei2011:feature/notification-dedup-alter

Conversation

@chenjei2011

Copy link
Copy Markdown
Contributor

功能描述

消息去重机制当遇到多个_deduplicationWindowSeconds秒(目前为2秒)之内的重复消息会进行拦截使重复消息只显示一次

需求动机

当异常代码引起的死循环弹消息发生时能有效拦截避免干扰课堂

ps. 当收到重复消息时,系统会将去重窗口的起始时间更新为当前消息的到达时间,使窗口持续向后“滑动”,当代码异常导致消息在极短时间内(远小于 2 秒)疯狂循环触发时,滚动窗口会随着每一条新消息的到来不断向后“滚动”重置.

@augmentcode

augmentcode Bot commented Jul 20, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR improves the in-app notification deduplication logic to better suppress rapid-fire repeated messages in classroom scenarios.

Changes:

  • Refactors the dedup state tracking in NotificationCenterService and introduces a 2-second sliding window.
  • Expands duplicate detection to require matching Title, Summary, and Source.
  • Updates the window start time on each duplicate to keep “spamming” notifications silent until they stop.
  • Adds a one-time log entry when the first duplicate in a sequence is intercepted.
  • Adds a short Markdown doc describing the deduplication rules and behavior.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

///</summary>
if (string.IsNullOrEmpty(_lastMessage.Title) || string.IsNullOrEmpty(message.Title)) return false;

TimeSpan interval = message.CreatedAt - _lastMessage.Time;

@augmentcode augmentcode Bot Jul 20, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

message.CreatedAt - _lastMessage.Time 可能出现负数(例如消息乱序/时钟差),此时 totalSeconds <= _deduplicationWindowSeconds 仍会成立,导致“更早”的消息被误判为重复并被静默丢弃。考虑对负间隔做保护(例如仅在 interval >= 0 时才参与窗口判定)。

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

///<summary>
///在一定时间内和前条标题相同,内容相同,来源相同的消息返回true
///</summary>
if (string.IsNullOrEmpty(_lastMessage.Title) || string.IsNullOrEmpty(message.Title)) return false;

@augmentcode augmentcode Bot Jul 20, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

这里用 IsNullOrEmpty 会让仅包含空白的 Title 也参与去重,而入口过滤用的是 IsNullOrWhiteSpace,且文档也写了“标题为空不参与去重”。如果希望空白标题不参与,建议统一空/空白判断口径。

Severity: low

Other Locations
  • Ink Canvas/Helpers/NotificationCenterService.cs:71
  • rules/消息去重说明.md:10

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@doudou0720
doudou0720 requested a review from CJKmkp July 20, 2026 03:23
@CJKmkp

CJKmkp commented Jul 20, 2026

Copy link
Copy Markdown
Member

喵喵

@CJKmkp CJKmkp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

可以优化一下时间那里的判断

@chenjei2011

Copy link
Copy Markdown
Contributor Author

可以优化一下时间那里的判断

等我下个星期有空就改,喵)

@CJKmkp

CJKmkp commented Jul 21, 2026

Copy link
Copy Markdown
Member

好的

@CJKmkp
CJKmkp merged commit a46f960 into InkCanvasForClass:net6 Jul 27, 2026
3 checks passed
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