Skip to content

Commit

Permalink
Handle OTK counts and device lists coming in through the transaction …
Browse files Browse the repository at this point in the history
…websocket
  • Loading branch information
tulir committed Jul 24, 2021
1 parent 02f00b9 commit 50398a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
40 changes: 22 additions & 18 deletions appservice/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,29 +130,33 @@ func (as *AppService) PutTransaction(w http.ResponseWriter, r *http.Request) {
Message: "Failed to parse body JSON",
}.Write(w)
} else {
if as.Registration.EphemeralEvents {
if txn.EphemeralEvents != nil {
as.handleEvents(txn.EphemeralEvents, event.EphemeralEventType)
} else if txn.MSC2409EphemeralEvents != nil {
as.handleEvents(txn.MSC2409EphemeralEvents, event.EphemeralEventType)
}
}
as.handleEvents(txn.Events, event.UnknownEventType)
if txn.DeviceLists != nil {
as.handleDeviceLists(txn.DeviceLists)
} else if txn.MSC3202DeviceLists != nil {
as.handleDeviceLists(txn.MSC3202DeviceLists)
}
if txn.DeviceOTKCount != nil {
as.handleOTKCounts(txn.DeviceOTKCount)
} else if txn.MSC3202DeviceOTKCount != nil {
as.handleOTKCounts(txn.MSC3202DeviceOTKCount)
}
as.handleTransaction(&txn)
WriteBlankOK(w)
}
as.lastProcessedTransaction = txnID
}

func (as *AppService) handleTransaction(txn *Transaction) {
if as.Registration.EphemeralEvents {
if txn.EphemeralEvents != nil {
as.handleEvents(txn.EphemeralEvents, event.EphemeralEventType)
} else if txn.MSC2409EphemeralEvents != nil {
as.handleEvents(txn.MSC2409EphemeralEvents, event.EphemeralEventType)
}
}
as.handleEvents(txn.Events, event.UnknownEventType)
if txn.DeviceLists != nil {
as.handleDeviceLists(txn.DeviceLists)
} else if txn.MSC3202DeviceLists != nil {
as.handleDeviceLists(txn.MSC3202DeviceLists)
}
if txn.DeviceOTKCount != nil {
as.handleOTKCounts(txn.DeviceOTKCount)
} else if txn.MSC3202DeviceOTKCount != nil {
as.handleOTKCounts(txn.MSC3202DeviceOTKCount)
}
}

func (as *AppService) handleOTKCounts(otks map[id.UserID]mautrix.OTKCount) {
for userID, otkCounts := range otks {
otkCounts.UserID = userID
Expand Down
7 changes: 1 addition & 6 deletions appservice/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"sync/atomic"

"github.com/gorilla/websocket"

"maunium.net/go/mautrix/event"
)

type WebsocketRequest struct {
Expand Down Expand Up @@ -188,10 +186,7 @@ func (as *AppService) consumeWebsocket(stopFunc func(error), ws *websocket.Conn)
return
}
if msg.Command == "" || msg.Command == "transaction" {
if as.Registration.EphemeralEvents && msg.EphemeralEvents != nil {
as.handleEvents(msg.EphemeralEvents, event.EphemeralEventType)
}
as.handleEvents(msg.Events, event.UnknownEventType)
as.handleTransaction(&msg.Transaction)
} else if msg.Command == "connect" {
as.Log.Debugln("Websocket connect confirmation received")
} else if msg.Command == "response" || msg.Command == "error" {
Expand Down

0 comments on commit 50398a6

Please sign in to comment.