mirror of
https://github.com/Kyren223/eko.git
synced 2026-07-13 23:50:25 +00:00
Added notifications display in user signals
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ var (
|
||||
notifSymbol = "◗"
|
||||
notifSymbols = func() []string {
|
||||
notifs := []string{
|
||||
" ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
|
||||
" ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
|
||||
}
|
||||
for i, notif := range notifs {
|
||||
notifs[i] = notifStyle.Render(notif)
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user