Handle tag events
This commit is contained in:
@ -18,7 +18,6 @@ package matrix
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -255,9 +254,23 @@ func (c *Container) HandlePushRules(evt *gomatrix.Event) {
|
||||
|
||||
// HandleTag is the event handler for the m.tag account data event.
|
||||
func (c *Container) HandleTag(evt *gomatrix.Event) {
|
||||
debug.Print("Received updated tags for", evt.RoomID)
|
||||
dat, _ := json.MarshalIndent(&evt.Content, "", " ")
|
||||
debug.Print(string(dat))
|
||||
room := c.config.Session.GetRoom(evt.RoomID)
|
||||
|
||||
tags, _ := evt.Content["tags"].(map[string]interface{})
|
||||
newTags := make([]rooms.RoomTag, len(tags))
|
||||
index := 0
|
||||
for tag, infoifc := range tags {
|
||||
info, _ := infoifc.(map[string]interface{})
|
||||
order, _ := info["order"].(float64)
|
||||
newTags[index] = rooms.RoomTag{
|
||||
Tag: tag,
|
||||
Order: order,
|
||||
}
|
||||
index++
|
||||
}
|
||||
|
||||
mainView := c.ui.MainView()
|
||||
mainView.UpdateTags(room, newTags)
|
||||
}
|
||||
|
||||
func (c *Container) processOwnMembershipChange(evt *gomatrix.Event) {
|
||||
|
@ -34,6 +34,14 @@ const (
|
||||
MemberRoomName
|
||||
)
|
||||
|
||||
// RoomTag is a tag given to a specific room.
|
||||
type RoomTag struct {
|
||||
// The name of the tag.
|
||||
Tag string
|
||||
// The order of the tag. Smaller values are ordered higher.
|
||||
Order float64
|
||||
}
|
||||
|
||||
// Room represents a single Matrix room.
|
||||
type Room struct {
|
||||
*gomatrix.Room
|
||||
@ -53,7 +61,9 @@ type Room struct {
|
||||
// a notificationless message like bot notices.
|
||||
HasNewMessages bool
|
||||
|
||||
Tags []string
|
||||
// List of tags given to this room
|
||||
RawTags []RoomTag
|
||||
// Timestamp of previously received actual message.
|
||||
LastReceivedMessage time.Time
|
||||
|
||||
// MXID -> Member cache calculated from membership events.
|
||||
@ -102,6 +112,13 @@ func (room *Room) MarkRead() {
|
||||
room.HasNewMessages = false
|
||||
}
|
||||
|
||||
func (room *Room) Tags() []RoomTag {
|
||||
if len(room.RawTags) == 0 {
|
||||
return []RoomTag{{"", 0.5}}
|
||||
}
|
||||
return room.RawTags
|
||||
}
|
||||
|
||||
// UpdateState updates the room's current state with the given Event. This will clobber events based
|
||||
// on the type/state_key combination.
|
||||
func (room *Room) UpdateState(event *gomatrix.Event) {
|
||||
|
Reference in New Issue
Block a user