diff options
| author | Kyren223 <Kyren223@proton.me> | 2025-02-06 16:33:16 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2025-02-06 16:33:16 +0200 |
| commit | 3c05ff093739ca02e6ed2e1e736b59360d111e1e (patch) | |
| tree | 41daa663ed0589ca810cc2faf5ca533219f7a2bb | |
| parent | f10f8396cca77dfa33c2c2d45063a4817b5612e5 (diff) | |
Added notifications display in user signals
| -rw-r--r-- | internal/client/ui/core/core.go | 31 | ||||
| -rw-r--r-- | internal/client/ui/core/frequencylist/frequencylist.go | 2 | ||||
| -rw-r--r-- | internal/client/ui/core/signallist/signallist.go | 36 |
3 files changed, 64 insertions, 5 deletions
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 +} diff --git a/internal/client/ui/core/frequencylist/frequencylist.go b/internal/client/ui/core/frequencylist/frequencylist.go index f2b468c..fb56a49 100644 --- a/internal/client/ui/core/frequencylist/frequencylist.go +++ b/internal/client/ui/core/frequencylist/frequencylist.go @@ -48,7 +48,7 @@ var ( notifSymbol = "◗" notifSymbols = func() []string { notifs := []string{ - " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", } for i, notif := range notifs { notifs[i] = notifStyle.Render(notif) diff --git a/internal/client/ui/core/signallist/signallist.go b/internal/client/ui/core/signallist/signallist.go index 894d652..3036017 100644 --- a/internal/client/ui/core/signallist/signallist.go +++ b/internal/client/ui/core/signallist/signallist.go @@ -33,12 +33,24 @@ var ( signalStyle = lipgloss.NewStyle(). Margin(0, margin).Padding(0, padding).Align(lipgloss.Left) - symbolWidth = 2 - widthWithoutUser = ((margin + padding) * 2) + symbolWidth + widthWithoutUser = ((margin + padding) * 2) ellipsis = "…" BackgroundStyle = lipgloss.NewStyle().Background(colors.BackgroundDim) + + notifSymbols = func() []string { + notifs := []string{ + " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", + } + for i, notif := range notifs { + notifs[i] = notifStyle.Render(notif) + } + return notifs + }() + notifStyle = lipgloss.NewStyle().Inline(true). + Foreground(colors.Red).Background(colors.BackgroundDim) + notifWidth = 2 ) type Model struct { @@ -78,6 +90,7 @@ func (m Model) View() string { signals = signals[m.base:upper] for i, signal := range signals { signalStyle := signalStyle + maxUserWidth := maxUserWidth user := state.State.Users[signal] trustedPublicKey, isTrusted := state.State.Trusteds[user.ID] @@ -90,9 +103,18 @@ func (m Model) View() string { userStyle = ui.UserStyle.Background(colors.BackgroundDim) } + notif := "" + pings := state.State.Notifications[signal] + if pings != 0 { + notif = notifSymbols[min(pings, 10)-1] + maxUserWidth -= notifWidth + } + if m.index == m.base+i { signalStyle = signalStyle.Background(colors.BackgroundHighlight) userStyle = userStyle.Background(colors.BackgroundHighlight) + notif = lipgloss.NewStyle().Background(colors.BackgroundHighlight). + Render(notif) } username := user.Name @@ -113,8 +135,16 @@ func (m Model) View() string { MaxWidth(maxUserWidth-1). Render(username) + ellipsisStyle.Render(ellipsis) } + if m.index == m.base+i { + username = lipgloss.NewStyle().Width(maxUserWidth). + Background(colors.BackgroundHighlight).Render(username) + } else { + username = lipgloss.NewStyle().Width(maxUserWidth). + Background(colors.BackgroundDim).Render(username) + } - builder.WriteString(backgroundStyle.Render(signalStyle.Render(username))) + signal := signalStyle.Render(username + notif) + builder.WriteString(backgroundStyle.Render(signal)) builder.WriteString("\n") } |
