Use structs for parsing read receipts and direct chat lists
This commit is contained in:
parent
e670fd05c2
commit
6cf22290ad
@ -692,26 +692,16 @@ func (c *Container) processOwnMembershipChange(evt *event.Event) {
|
|||||||
|
|
||||||
func (c *Container) parseReadReceipt(evt *event.Event) (largestTimestampEvent id.EventID) {
|
func (c *Container) parseReadReceipt(evt *event.Event) (largestTimestampEvent id.EventID) {
|
||||||
var largestTimestamp int64
|
var largestTimestamp int64
|
||||||
for eventID, rawContent := range evt.Content.Raw {
|
|
||||||
content, ok := rawContent.(map[string]interface{})
|
for eventID, receipts := range *evt.Content.AsReceipt() {
|
||||||
|
myInfo, ok := receipts.Read[c.config.UserID]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
mRead, ok := content["m.read"].(map[string]interface{})
|
if myInfo.Timestamp > largestTimestamp {
|
||||||
if !ok {
|
largestTimestamp = myInfo.Timestamp
|
||||||
continue
|
largestTimestampEvent = eventID
|
||||||
}
|
|
||||||
|
|
||||||
myInfo, ok := mRead[string(c.config.UserID)].(map[string]interface{})
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
ts, ok := myInfo["ts"].(float64)
|
|
||||||
if int64(ts) > largestTimestamp {
|
|
||||||
largestTimestamp = int64(ts)
|
|
||||||
largestTimestampEvent = id.EventID(eventID)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
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 {
|
func (c *Container) parseDirectChatInfo(evt *event.Event) map[*rooms.Room]bool {
|
||||||
directChats := make(map[*rooms.Room]bool)
|
directChats := make(map[*rooms.Room]bool)
|
||||||
for _, rawRoomIDList := range evt.Content.Raw {
|
for _, roomIDList := range *evt.Content.AsDirectChats() {
|
||||||
roomIDList, ok := rawRoomIDList.([]interface{})
|
for _, roomID := range roomIDList {
|
||||||
if !ok {
|
// TODO we shouldn't create direct chat rooms that we aren't in
|
||||||
continue
|
room := c.GetOrCreateRoom(roomID)
|
||||||
}
|
|
||||||
|
|
||||||
for _, rawRoomID := range roomIDList {
|
|
||||||
roomID, ok := rawRoomID.(string)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
room := c.GetOrCreateRoom(id.RoomID(roomID))
|
|
||||||
if room != nil && !room.HasLeft {
|
if room != nil && !room.HasLeft {
|
||||||
directChats[room] = true
|
directChats[room] = true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user