Skip to content

feat: notify on chat when new record is established#26

Open
daimonbot wants to merge 2 commits intomainfrom
feature/record-notification-reimpl
Open

feat: notify on chat when new record is established#26
daimonbot wants to merge 2 commits intomainfrom
feature/record-notification-reimpl

Conversation

@daimonbot
Copy link
Copy Markdown
Collaborator

Closes #7

Implements notifications when a user establishes a new record time for a game in a group chat.

Changes:

  • Added RecordNotificationService that listens to GameSessionRegistrationEvent
  • Added repository method to fetch top 2 sessions by duration
  • Extended GameSessionRegistrationEvent with gameType field
  • Made USER_INTERACTION_NOTIFICATION_ORDER package-private
  • Added comprehensive unit tests

Behavior:

  • Sends notification when first-ever time is recorded
  • Sends notification when previous record is broken (shows both times)
  • Handles users with and without username
  • No notification when time is not a record

private void saveSession(final ChatInfo chatInfo, final UserInfo userInfo, final LocalDate gameDay, final GameSession gameSession, final GameInfo gameInfo, final TelegramGroup telegramGroup) {
gameSessionRepository.saveAndFlush(gameSession);
applicationEventPublisher.publishEvent(new GameSessionRegistrationEvent(this, chatInfo, userInfo, gameInfo, gameSession.getDuration(), gameDay,
applicationEventPublisher.publishEvent(new GameSessionRegistrationEvent(this, chatInfo, userInfo, gameInfo, gameSession.getGame(), gameSession.getDuration(), gameDay,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Isn't the game already inferable from gameInfo?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You're right — already addressed in the refactoring commit. GameInfo now includes the GameType, and the redundant parameter was removed from the event. gameInfo.type() is used everywhere instead.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Applied in the refactoring commit: GameInfo now includes the GameType as the first field, and the redundant gameType parameter was removed from GameSessionRegistrationEvent. All consumers now correctly use gameInfo.type().

@daimonbot
Copy link
Copy Markdown
Collaborator Author

Hi @rubasace! Just wanted to flag that the GameType redundancy feedback has been addressed in a previous commit:

  • GameInfo now includes a type field (GameInfo(GameType type, String name, String icon))
  • The redundant gameType parameter was removed from GameSessionRegistrationEvent
  • All consumers now use gameInfo.type() instead of the separate param
  • RecordNotificationService correctly uses event.getChatInfo().chatId() for the notification target (no hardcoded channel references)
  • CI is green ✅

Could you please take another look when you get a chance? Thanks!

@daimonbot daimonbot requested a review from rubasace February 26, 2026 19:11
daimonbot and others added 2 commits March 5, 2026 12:36
GameInfo now contains the GameType as its first field, eliminating
the need to pass both gameInfo and gameType separately to events
and other components.

Changes:
- Updated GameInfo record to include GameType as first parameter
- Modified GameTypeAdapter to populate type field
- Simplified GameSessionRegistrationEvent constructor
- Updated all event consumers to use gameInfo.type()
- Fixed test fixtures to use new GameInfo constructor
@daimonbot daimonbot force-pushed the feature/record-notification-reimpl branch from 6673411 to 031aead Compare March 5, 2026 11:36
@daimonbot
Copy link
Copy Markdown
Collaborator Author

Rebased on current main (no conflicts). CI running on the updated commits.

Summary of changes in this PR:

  • RecordNotificationService: new service that listens to GameSessionRegistrationEvent after commit and sends a Telegram notification when a new record is set
  • GameInfo: now includes GameType as first field (addressing review feedback — game is now inferable from gameInfo.type())
  • GameSessionRegistrationEvent: simplified constructor, no longer takes redundant gameType parameter
  • GameSessionRepository: added findTop2ByGroupChatIdAndGameOrderByDurationAsc query
  • Unit tests for all notification paths (first record, breaking record, no record)

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.

[Feature]: Notify on chat when new record is established

2 participants