Update mautrix-go and give crypto module access to state store
This commit is contained in:
parent
788d932bec
commit
22681875f3
2
go.mod
2
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
|
||||
)
|
||||
|
2
go.sum
2
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=
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user