From 3c05ff093739ca02e6ed2e1e736b59360d111e1e Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Thu, 6 Feb 2025 16:33:16 +0200 Subject: Added notifications display in user signals --- internal/client/ui/core/core.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'internal/client/ui/core/core.go') diff --git a/internal/client/ui/core/core.go b/internal/client/ui/core/core.go index 60225d8..80f5d7a 100644 --- a/internal/client/ui/core/core.go +++ b/internal/client/ui/core/core.go @@ -687,7 +687,15 @@ func (m *Model) HasPopup() bool { } func calculateNotifications() { - // TODO: handle notifications for receiver id + for _, signal := range state.Data.Signals { + if _, ok := state.State.Messages[signal]; !ok { + continue + } + + pings := getSignalNotification(signal) + state.State.Notifications[signal] = pings + } + for networkId := range state.State.Networks { for _, frequency := range state.State.Frequencies[networkId] { if _, ok := state.State.Messages[frequency.ID]; !ok { @@ -740,3 +748,24 @@ func getFrequencyNotification(networkId, frequencyId snowflake.ID) (_ int, _ boo return pings, hasNotif } + +func getSignalNotification(signal snowflake.ID) int { + lastReadMsg := state.State.LastReadMessages[signal] + if lastReadMsg == nil { + return 0 + } + + btree := state.State.Messages[signal] + if btree == nil { + return 0 + } + + pings := 0 + + btree.AscendGreaterOrEqual(data.Message{ID: *lastReadMsg + 1}, func(item data.Message) bool { + pings++ + return pings <= 10 + }) + + return pings +} -- cgit v1.3.1