Commit 563b397f authored by Black Hat's avatar Black Hat

Remove debug information and add missing files.

parent 7fb9d633
package matrix
import (
"github.com/matrix-org/gomatrix"
"log"
"strings"
)
type Room struct {
ID string
Alias string
Name string
Topic string
Avatar string
cli *gomatrix.Client
}
func (r *Room) Init(cli *gomatrix.Client) {
r.SetCli(cli)
r.FetchAlias()
r.FetchName()
r.FetchTopic()
r.FetchAvatar()
}
func (r *Room) SetCli(cli *gomatrix.Client) {
r.cli = cli
}
func (r *Room) FetchAlias() {
type RespRoomAlias struct {
Alias string `json:"alias"`
}
resp := new(RespRoomAlias)
err := r.cli.StateEvent(r.ID, "m.room.canonical_alias", "", resp)
if err == nil && resp.Alias != "" {
r.Alias = resp.Alias
return
}
}
func (r *Room) FetchName() {
type RespRoomName struct {
Name string `json:"name"`
}
resp := new(RespRoomName)
err := r.cli.StateEvent(r.ID, "m.room.name", "", resp)
if err == nil && resp.Name != "" {
r.Name = resp.Name
return
}
respM, _ := r.cli.JoinedMembers(r.ID)
memberSlice := respM.Joined
if len(memberSlice) == 2 {
for eachID, eachMember := range memberSlice {
if eachID == r.cli.UserID {
continue
}
if eachMember.DisplayName != nil {
r.Name = *eachMember.DisplayName
return
}
break
}
}
}
func (r *Room) FetchTopic() {
type RespRoomTopic struct {
Topic string `json:"topic"`
}
resp := new(RespRoomTopic)
err := r.cli.StateEvent(r.ID, "m.room.topic", "", resp)
if err != nil {
log.Println("Error when fetching topic of room", r.ID, ":", err.Error())
return
}
r.Topic = resp.Topic
}
func (r *Room) FetchAvatar() {
type RespRoomAvatar struct {
Avatar string `json:"url"`
}
resp := new(RespRoomAvatar)
err := r.cli.StateEvent(r.ID, "m.room.avatar", "", resp)
if err == nil && resp.Avatar != "" {
r.Avatar = resp.Avatar
return
}
respM, _ := r.cli.JoinedMembers(r.ID)
memberSlice := respM.Joined
if len(memberSlice) == 2 {
for eachID, eachMember := range memberSlice {
if eachID == r.cli.UserID {
continue
}
if eachMember.AvatarURL != nil {
r.Avatar = *eachMember.AvatarURL
return
}
break
}
}
r.Avatar = strings.ToUpper(r.Name)
}
package ui
import (
"github.com/matrix-org/gomatrix"
"github.com/therecipe/qt/core"
"time"
)
type Message struct {
core.QObject
eventID string
event *gomatrix.Event
authorID string
text string
timestamp *time.Time
}
package ui
//import "github.com/therecipe/qt/core"
//
//type MessageEventModel struct {
// core.QAbstractListModel
//
// _ *Controller `property:"controller"`
//
// _ func() `constructor:"init"`
//
// _ *Room `property:"currentRoom"`
//
// _ map[int]*core.QByteArray `property:"roles"`
// _ []*Message `property:"message"`
//
// _ func(*[]*Message) `signal:"doResetModel"`
//
// _ func(int) *Message `slot:"messageAt"`
// _ func(*Message) `slot:"addMessage"`
// _ func(row int) `slot:"removeMessage"`
//}
//
//func (m *MessageEventModel) init() {
// m.SetRoles(map[int]*core.QByteArray{
// ID: core.NewQByteArray2("id", len("id")),
// Name: core.NewQByteArray2("name", len("name")),
// Alias: core.NewQByteArray2("alias", len("alias")),
// Topic: core.NewQByteArray2("topic", len("topic")),
// Avatar: core.NewQByteArray2("avatar", len("avatar")),
// })
//}
//
......@@ -66,12 +66,10 @@ func (m *RoomListModel) fetchModel() {
defer close(roomChan)
for _, roomID := range resp.JoinedRooms {
go func(id string) {
log.Println("ID:", id)
defer m.Controller().recovery()
room := matrix.Room{ID: id}
room.Init(m.Controller().matrixCli)
log.Println(room)
roomChan <- &room
}(roomID)
}
......@@ -82,7 +80,6 @@ func (m *RoomListModel) fetchModel() {
}
m.Controller().SetBusy(false)
log.Println("BEFORE:", rooms)
m.DoResetModel(rooms)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment