Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle report notifications #2518

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

blabber
Copy link
Collaborator

@blabber blabber commented Jan 22, 2025

This addresses the missing parts from issue #1612. While I already made F6 (research view) and F12 (spaceship view) work as a toggle, making F7 (wonders of the world), F8 (top 5 cities) and F11 (demographics) work like that is a bit special.

These reports are generic notification popups, which the server triggers to be displayed. The flow is

  1. the user presses F7
  2. the client asks the user for the research report
  3. the server sends the research report
  4. the client displays the report in a notification popup by calling popup_notify_dialog

This PR changes the behavior of subsequent calls to popup_notify_dialog. The former behavior was to refresh an existing notification, the new behavior is to close the existing notification. The notification to be manipulated is, in both cases, identified by caption and headline.

A drawback of this implementation is, that toggling a report still needs a round-trip to the server:

  1. the user presses F7, while the wonder of the worlds report is open
  2. the client asks the user for the research report
  3. the server sends the research report
  4. the client registers that there is already an open report, identified by the caption and headline provided from the server, and closes it
  5. the just received report is discarded.

Keeping state in the client and closing the notifications without involving the server would require the usage of magic strings to identify relevant notification (this implementation does use string comparisons too, but these strings are provided by the server and, at least from the clients perspective, less magic).

Giving the notifications an "identity" would require either changes in the server and the protocol, or the client would need to deduce it by using magic strings.

Reported by clangd.
This commit changes the behavior of subsequent calls to
`popup_notify_dialog`. The former behavior was to refresh an existing
notification, the new behavior is to close the existing
notification. The notification to be manipulated is, in both cases,
identified by caption and headline.

The new behavior is more in line with the users expectation to toggle
a report by pressing the corresponding hotkey twice.

A drawback of this implementation is, that toggling a report still
needs a round-trip to the server:

1. the client asks for an already open report
2. the server sends the report
3. the client closes the existing report and discards the report it
   just received

This is necessary as the different reports have no "identity" but are
generic notifications. Keeping state in the client and closing the
notifications without involving the server would require the usage of
magic strings to identify relevant notification (this implementation
does use string comparisons too, but these strings are provided by the
server and, at least from the clients perspective, less magic).

Giving the notifications an "identity" would require either changes in
the server and the protocol, or the client would need to deduce it by
using magic strings.
@blabber
Copy link
Collaborator Author

blabber commented Jan 22, 2025

Marked this as draft to gather feedback about the code change.

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.

1 participant