summaryrefslogtreecommitdiff
path: root/internal/client/ui/core/state
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2025-02-02 19:23:50 +0200
committerKyren223 <Kyren223@proton.me>2025-02-02 19:23:50 +0200
commitc77ac77e78268bc2f4265a872b213d4300b3eb66 (patch)
tree1c2f1be6f2c7a724486d24b0c83014032e761f49 /internal/client/ui/core/state
parenta1c20cbfc5a90642e486132d4673646342df13fd (diff)
Added support for offline notifications where the server calculates them
and sends the info to the client when it connects
Diffstat (limited to 'internal/client/ui/core/state')
-rw-r--r--internal/client/ui/core/state/state.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/internal/client/ui/core/state/state.go b/internal/client/ui/core/state/state.go
index ee61a2c..ba9e233 100644
--- a/internal/client/ui/core/state/state.go
+++ b/internal/client/ui/core/state/state.go
@@ -3,6 +3,7 @@ package state
import (
"crypto/ed25519"
"encoding/json"
+ "log"
"slices"
"github.com/google/btree"
@@ -59,6 +60,12 @@ var Data UserData = UserData{
var UserID *snowflake.ID = nil
+var (
+ ReceivedData = false
+ ReceivedNetworks = false
+ AskedForNotifs = false
+)
+
func UpdateNetworks(info *packet.NetworksInfo) {
networks := State.Networks
@@ -111,6 +118,8 @@ func UpdateNetworks(info *packet.NetworksInfo) {
Data: &data,
User: nil,
})
+
+ ReceivedNetworks = true
}
func UpdateFrequencies(info *packet.FrequenciesInfo) {
@@ -215,6 +224,8 @@ func FromJsonUserData(s string) {
if Data.LastReadMessage == nil {
Data.LastReadMessage = map[snowflake.ID]*snowflake.ID{}
}
+
+ ReceivedData = true
}
func UpdateTrusteds(info *packet.TrustInfo) {
@@ -246,3 +257,41 @@ func SendUserDatUpdate() {
User: nil,
})
}
+
+func UpdateNotifications(info *packet.NotificationsInfo) {
+ for i := 0; i < len(info.Source); i++ {
+ ping := info.Pings[i]
+ if ping != nil {
+ State.Notifications[info.Source[i]] = int(*ping)
+ } else {
+ delete(State.Notifications, info.Source[i])
+ }
+ }
+}
+
+func AskForNotifs() {
+ source := []snowflake.ID{}
+
+ source = append(source, Data.Peers...)
+ for networkId := range State.Networks {
+ for _, frequency := range State.Frequencies[networkId] {
+ source = append(source, frequency.ID)
+ }
+ }
+
+ lastReadId := make([]snowflake.ID, 0, len(source))
+
+ for _, source := range source {
+ id := Data.LastReadMessage[source]
+ if id == nil {
+ lastReadId = append(lastReadId, 0)
+ } else {
+ lastReadId = append(lastReadId, *id)
+ }
+ }
+
+ gateway.SendAsync(&packet.GetNotifications{
+ Source: source,
+ LastReadId: lastReadId,
+ })
+}