aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2020-05-06 23:30:08 +0300
committerTulir Asokan <tulir@maunium.net>2020-05-06 23:30:08 +0300
commit6cf22290ad6a471fa7556ad84d5c70862fa7726c (patch)
tree4f5e54f07ab97b64d8aa2f1eb5cbbf96e9ddf68c
parente670fd05c2a5a696eeffa447686da7178b07a691 (diff)
Use structs for parsing read receipts and direct chat lists
-rw-r--r--matrix/matrix.go37
1 files changed, 9 insertions, 28 deletions
diff --git a/matrix/matrix.go b/matrix/matrix.go
index 072816d..82ba006 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -692,26 +692,16 @@ func (c *Container) processOwnMembershipChange(evt *event.Event) {
func (c *Container) parseReadReceipt(evt *event.Event) (largestTimestampEvent id.EventID) {
var largestTimestamp int64
- for eventID, rawContent := range evt.Content.Raw {
- content, ok := rawContent.(map[string]interface{})
- if !ok {
- continue
- }
-
- mRead, ok := content["m.read"].(map[string]interface{})
- if !ok {
- continue
- }
- myInfo, ok := mRead[string(c.config.UserID)].(map[string]interface{})
+ for eventID, receipts := range *evt.Content.AsReceipt() {
+ myInfo, ok := receipts.Read[c.config.UserID]
if !ok {
continue
}
- ts, ok := myInfo["ts"].(float64)
- if int64(ts) > largestTimestamp {
- largestTimestamp = int64(ts)
- largestTimestampEvent = id.EventID(eventID)
+ if myInfo.Timestamp > largestTimestamp {
+ largestTimestamp = myInfo.Timestamp
+ largestTimestampEvent = eventID
}
}
return
@@ -738,19 +728,10 @@ func (c *Container) HandleReadReceipt(source EventSource, evt *event.Event) {
func (c *Container) parseDirectChatInfo(evt *event.Event) map[*rooms.Room]bool {
directChats := make(map[*rooms.Room]bool)
- for _, rawRoomIDList := range evt.Content.Raw {
- roomIDList, ok := rawRoomIDList.([]interface{})
- if !ok {
- continue
- }
-
- for _, rawRoomID := range roomIDList {
- roomID, ok := rawRoomID.(string)
- if !ok {
- continue
- }
-
- room := c.GetOrCreateRoom(id.RoomID(roomID))
+ for _, roomIDList := range *evt.Content.AsDirectChats() {
+ for _, roomID := range roomIDList {
+ // TODO we shouldn't create direct chat rooms that we aren't in
+ room := c.GetOrCreateRoom(roomID)
if room != nil && !room.HasLeft {
directChats[room] = true
}