summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2024-12-19 18:42:53 +0200
committerKyren223 <Kyren223@proton.me>2024-12-19 18:42:53 +0200
commit6d91f3f9af3efc6e77ec89979fee18366c7b8847 (patch)
tree5a21422d668aa18d219b97880b74ae7da194fa78
parentff032e5e0769cb33fa9075838b2cac3398e725f8 (diff)
Implemented processing data
-rw-r--r--go.mod5
-rw-r--r--go.sum6
-rw-r--r--internal/client/ui/core/core.go24
-rw-r--r--internal/client/ui/core/state/state.go11
-rw-r--r--internal/packet/types.go3
5 files changed, 42 insertions, 7 deletions
diff --git a/go.mod b/go.mod
index 82d9319..3f44c98 100644
--- a/go.mod
+++ b/go.mod
@@ -6,10 +6,11 @@ require (
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.1.1
github.com/charmbracelet/lipgloss v0.13.0
+ github.com/davecgh/go-spew v1.1.1
+ github.com/google/btree v1.1.3
github.com/mattn/go-sqlite3 v1.14.24
github.com/stretchr/testify v1.9.0
github.com/vmihailenco/msgpack/v5 v5.4.1
- github.com/davecgh/go-spew v1.1.1
)
require (
@@ -30,7 +31,7 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/crypto v0.28.0
- golang.org/x/sync v0.8.0 // indirect
+ golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
diff --git a/go.sum b/go.sum
index 9700776..3078e6b 100644
--- a/go.sum
+++ b/go.sum
@@ -16,6 +16,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
+github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg=
+github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
@@ -49,8 +51,8 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
-golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
-golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
+golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
+golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
diff --git a/internal/client/ui/core/core.go b/internal/client/ui/core/core.go
index 5115274..57bac20 100644
--- a/internal/client/ui/core/core.go
+++ b/internal/client/ui/core/core.go
@@ -11,6 +11,7 @@ import (
"github.com/charmbracelet/bubbles/timer"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
+ "github.com/google/btree"
"github.com/kyren223/eko/internal/client/gateway"
"github.com/kyren223/eko/internal/client/ui"
"github.com/kyren223/eko/internal/client/ui/core/chat"
@@ -213,6 +214,29 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd {
network.Frequencies = frequencies
}
+ case *packet.MessagesInfo:
+ for _, id := range msg.RemoveMessages {
+ for _, btree := range state.State.Messages {
+ btree.Delete(data.Message{ID: id})
+ }
+ }
+
+ for _, message := range msg.Messages {
+ msgSource := message.FrequencyID
+ if msgSource == nil {
+ msgSource = message.ReceiverID
+ }
+ bt := state.State.Messages[*msgSource]
+ if bt == nil {
+ bt = btree.NewG(2, func(a, b data.Message) bool {
+ return a.ID < b.ID
+ })
+ state.State.Messages[*msgSource] = bt
+ }
+ bt.ReplaceOrInsert(message)
+
+ }
+
case tea.KeyMsg:
key := msg.Type
switch key {
diff --git a/internal/client/ui/core/state/state.go b/internal/client/ui/core/state/state.go
index e40cdc9..ed5ca85 100644
--- a/internal/client/ui/core/state/state.go
+++ b/internal/client/ui/core/state/state.go
@@ -1,11 +1,18 @@
package state
import (
+ "github.com/google/btree"
+ "github.com/kyren223/eko/internal/data"
"github.com/kyren223/eko/internal/packet"
+ "github.com/kyren223/eko/pkg/snowflake"
)
type state struct {
- Networks []packet.FullNetwork
+ Messages map[snowflake.ID]*btree.BTreeG[data.Message]
+ Networks []packet.FullNetwork
}
-var State state = state{}
+var State state = state{
+ Networks: []packet.FullNetwork{},
+ Messages: map[snowflake.ID]*btree.BTreeG[data.Message]{},
+}
diff --git a/internal/packet/types.go b/internal/packet/types.go
index 6df3d65..a336624 100644
--- a/internal/packet/types.go
+++ b/internal/packet/types.go
@@ -180,7 +180,8 @@ func (m *RequestMessages) Type() PacketType {
}
type MessagesInfo struct {
- Messages []data.Message
+ Messages []data.Message
+ RemoveMessages []snowflake.ID
}
func (m *MessagesInfo) Type() PacketType {