aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2020-05-05 18:39:28 +0300
committerTulir Asokan <tulir@maunium.net>2020-05-05 18:39:28 +0300
commit22681875f32fa97f65c9a52e2ee666932706ce95 (patch)
treec5e817a817142c47d40db32285382291aba48347
parent788d932bec16f25a37bb0bbec03a0eaf4bcefffd (diff)
Update mautrix-go and give crypto module access to state store
-rw-r--r--go.mod2
-rw-r--r--go.sum2
-rw-r--r--matrix/matrix.go18
-rw-r--r--matrix/rooms/roomcache.go21
-rw-r--r--ui/messages/filemessage.go4
5 files changed, 41 insertions, 6 deletions
diff --git a/go.mod b/go.mod
index a3248dc..1cf74ae 100644
--- a/go.mod
+++ b/go.mod
@@ -21,7 +21,7 @@ require (
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2
gopkg.in/yaml.v2 v2.2.8
- maunium.net/go/mautrix v0.2.0-beta.4.0.20200429002157-8c3bc8eb8f22
+ maunium.net/go/mautrix v0.2.0-beta.4.0.20200505153708-a120e7a70f5a
maunium.net/go/mauview v0.1.0
maunium.net/go/tcell v0.1.0
)
diff --git a/go.sum b/go.sum
index e9acded..03a0f71 100644
--- a/go.sum
+++ b/go.sum
@@ -92,6 +92,8 @@ maunium.net/go/mautrix v0.2.0-beta.4.0.20200428234424-a14b55c5445f h1:kYrIUjr2v6
maunium.net/go/mautrix v0.2.0-beta.4.0.20200428234424-a14b55c5445f/go.mod h1:SkGZzch8CvU2qKtNpYxtzZ0sQxfVEJ3IsVVLSUBUx9Y=
maunium.net/go/mautrix v0.2.0-beta.4.0.20200429002157-8c3bc8eb8f22 h1:hN7gAmWJqII5aiTnVUHA/QM56ImYJvmQJEGwfMos0ts=
maunium.net/go/mautrix v0.2.0-beta.4.0.20200429002157-8c3bc8eb8f22/go.mod h1:SkGZzch8CvU2qKtNpYxtzZ0sQxfVEJ3IsVVLSUBUx9Y=
+maunium.net/go/mautrix v0.2.0-beta.4.0.20200505153708-a120e7a70f5a h1:5cXujK/NGwGDdllVebkfTfUq/yjfF+lc56Wjjikwl50=
+maunium.net/go/mautrix v0.2.0-beta.4.0.20200505153708-a120e7a70f5a/go.mod h1:SkGZzch8CvU2qKtNpYxtzZ0sQxfVEJ3IsVVLSUBUx9Y=
maunium.net/go/mauview v0.1.0 h1:x2WdkKI2zdriJuPAB0CKlwmnHGE7W9xfM5z6RgG+IIg=
maunium.net/go/mauview v0.1.0/go.mod h1:og9WbzmWe9SNYNyOFlCv8qa9zMcOvG2nzRJ5vYyud9U=
maunium.net/go/tcell v0.1.0 h1:XzsEoGCvOw5nac+tlkSLzQcliLYTN4PrtA7ar2ptjSM=
diff --git a/matrix/matrix.go b/matrix/matrix.go
index 27ed053..fe1aaa5 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -139,7 +139,7 @@ func (c *Container) InitClient() error {
if err != nil {
return err
}
- c.crypto = crypto.NewOlmMachine(c.client, cryptoLogger{}, cryptoStore)
+ c.crypto = crypto.NewOlmMachine(c.client, cryptoLogger{}, cryptoStore, c.config.Rooms)
err = c.crypto.Load()
if err != nil {
return err
@@ -301,7 +301,7 @@ func (c *Container) Stop() {
}
c.history = nil
debug.Print("Flushing crypto store")
- err = c.crypto.Store.Flush()
+ err = c.crypto.CryptoStore.Flush()
if err != nil {
debug.Print("Error flushing crypto store:", err)
}
@@ -356,6 +356,9 @@ func (c *Container) OnLogin() {
debug.Print("Initializing syncer")
c.syncer = NewGomuksSyncer(c.config.Rooms)
c.syncer.OnSync(c.crypto.ProcessSyncResponse)
+ c.syncer.OnEventType(event.StateMember, func(source EventSource, evt *event.Event) {
+ c.crypto.HandleMemberEvent(evt)
+ })
c.syncer.OnEventType(event.EventMessage, c.HandleMessage)
c.syncer.OnEventType(event.EventEncrypted, c.HandleEncrypted)
c.syncer.OnEventType(event.EventSticker, c.HandleMessage)
@@ -993,11 +996,20 @@ func (c *Container) GetHistory(room *rooms.Room, limit int) ([]*muksevt.Event, e
return nil, err
}
debug.Printf("Loaded %d events for %s from server from %s to %s", len(resp.Chunk), room.ID, resp.Start, resp.End)
- for _, evt := range resp.Chunk {
+ for i, evt := range resp.Chunk {
err := evt.Content.ParseRaw(evt.Type)
if err != nil {
debug.Printf("Failed to unmarshal content of event %s (type %s) by %s in %s: %v\n%s", evt.ID, evt.Type.Repr(), evt.Sender, evt.RoomID, err, string(evt.Content.VeryRaw))
}
+
+ if evt.Type == event.EventEncrypted {
+ decrypted, err := c.crypto.DecryptMegolmEvent(evt)
+ if err != nil {
+ debug.Print("Failed to decrypt event:", err)
+ } else {
+ resp.Chunk[i] = decrypted
+ }
+ }
}
for _, evt := range resp.State {
room.UpdateState(evt)
diff --git a/matrix/rooms/roomcache.go b/matrix/rooms/roomcache.go
index ffdcad1..d66078c 100644
--- a/matrix/rooms/roomcache.go
+++ b/matrix/rooms/roomcache.go
@@ -27,6 +27,7 @@ import (
sync "github.com/sasha-s/go-deadlock"
"maunium.net/go/gomuks/debug"
+ "maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
)
@@ -67,6 +68,26 @@ func (cache *RoomCache) EnableUnloading() {
cache.noUnload = false
}
+func (cache *RoomCache) IsEncrypted(roomID id.RoomID) bool {
+ room := cache.Get(roomID)
+ return room != nil && room.Encrypted
+}
+
+func (cache *RoomCache) FindSharedRooms(userID id.UserID) (shared []id.RoomID) {
+ cache.Lock()
+ for _, room := range cache.Map {
+ if !room.Encrypted {
+ continue
+ }
+ member, ok := room.GetMembers()[userID]
+ if ok && member.Membership == event.MembershipJoin {
+ shared = append(shared, room.ID)
+ }
+ }
+ cache.Unlock()
+ return
+}
+
func (cache *RoomCache) LoadList() error {
cache.Lock()
defer cache.Unlock()
diff --git a/ui/messages/filemessage.go b/ui/messages/filemessage.go
index d2455ab..3d5e554 100644
--- a/ui/messages/filemessage.go
+++ b/ui/messages/filemessage.go
@@ -66,9 +66,9 @@ func NewFileMessage(matrix ifc.MatrixContainer, evt *muksevt.Event, displayname
return newUIMessage(evt, displayname, &FileMessage{
Type: content.MsgType,
Body: content.Body,
- URL: content.URL,
+ URL: content.URL.ParseOrIgnore(),
File: file,
- Thumbnail: content.GetInfo().ThumbnailURL,
+ Thumbnail: content.GetInfo().ThumbnailURL.ParseOrIgnore(),
ThumbnailFile: thumbnailFile,
matrix: matrix,
})