aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/commands.go5
-rw-r--r--ui/messages/base.go9
-rw-r--r--ui/messages/expandedtextmessage.go3
-rw-r--r--ui/messages/imagemessage.go3
-rw-r--r--ui/messages/parser/htmlparser.go9
-rw-r--r--ui/messages/parser/parser.go48
-rw-r--r--ui/messages/textmessage.go5
-rw-r--r--ui/room-view.go31
-rw-r--r--ui/view-main.go2
9 files changed, 57 insertions, 58 deletions
diff --git a/ui/commands.go b/ui/commands.go
index 2827666..b80fa07 100644
--- a/ui/commands.go
+++ b/ui/commands.go
@@ -19,6 +19,7 @@ package ui
import (
"encoding/json"
"fmt"
+ "maunium.net/go/gomatrix"
"strings"
"unicode"
@@ -132,7 +133,7 @@ func cmdSendEvent(cmd *Command) {
return
}
roomID := cmd.Args[0]
- eventType := cmd.Args[1]
+ eventType := gomatrix.NewEventType(cmd.Args[1])
rawContent := strings.Join(cmd.Args[2:], "")
debug.Print(roomID, eventType, rawContent)
@@ -161,7 +162,7 @@ func cmdSetState(cmd *Command) {
}
roomID := cmd.Args[0]
- eventType := cmd.Args[1]
+ eventType := gomatrix.NewEventType(cmd.Args[1])
stateKey := cmd.Args[2]
if stateKey == "-" {
stateKey = ""
diff --git a/ui/messages/base.go b/ui/messages/base.go
index 6049ae3..c9da389 100644
--- a/ui/messages/base.go
+++ b/ui/messages/base.go
@@ -18,6 +18,7 @@ package messages
import (
"encoding/gob"
+ "maunium.net/go/gomatrix"
"time"
"maunium.net/go/gomuks/config"
@@ -33,7 +34,7 @@ func init() {
type BaseMessage struct {
MsgID string
- MsgType string
+ MsgType gomatrix.MessageType
MsgSenderID string
MsgSender string
MsgSenderColor tcell.Color
@@ -47,7 +48,7 @@ type BaseMessage struct {
prevPrefs config.UserPreferences
}
-func newBaseMessage(id, sender, displayname, msgtype string, timestamp time.Time) BaseMessage {
+func newBaseMessage(id, sender, displayname string, msgtype gomatrix.MessageType, timestamp time.Time) BaseMessage {
return BaseMessage{
MsgSenderID: sender,
MsgSender: displayname,
@@ -194,11 +195,11 @@ func (msg *BaseMessage) SetID(id string) {
msg.MsgID = id
}
-func (msg *BaseMessage) Type() string {
+func (msg *BaseMessage) Type() gomatrix.MessageType {
return msg.MsgType
}
-func (msg *BaseMessage) SetType(msgtype string) {
+func (msg *BaseMessage) SetType(msgtype gomatrix.MessageType) {
msg.MsgType = msgtype
}
diff --git a/ui/messages/expandedtextmessage.go b/ui/messages/expandedtextmessage.go
index c69f3dc..2e77a24 100644
--- a/ui/messages/expandedtextmessage.go
+++ b/ui/messages/expandedtextmessage.go
@@ -18,6 +18,7 @@ package messages
import (
"encoding/gob"
+ "maunium.net/go/gomatrix"
"time"
"maunium.net/go/gomuks/config"
@@ -34,7 +35,7 @@ type ExpandedTextMessage struct {
}
// NewExpandedTextMessage creates a new ExpandedTextMessage object with the provided values and the default state.
-func NewExpandedTextMessage(id, sender, displayname, msgtype string, text tstring.TString, timestamp time.Time) UIMessage {
+func NewExpandedTextMessage(id, sender, displayname string, msgtype gomatrix.MessageType, text tstring.TString, timestamp time.Time) UIMessage {
return &ExpandedTextMessage{
BaseMessage: newBaseMessage(id, sender, displayname, msgtype, timestamp),
MsgText: text,
diff --git a/ui/messages/imagemessage.go b/ui/messages/imagemessage.go
index dcbe1c5..a17c842 100644
--- a/ui/messages/imagemessage.go
+++ b/ui/messages/imagemessage.go
@@ -20,6 +20,7 @@ import (
"bytes"
"encoding/gob"
"fmt"
+ "maunium.net/go/gomatrix"
"time"
"image/color"
@@ -47,7 +48,7 @@ type ImageMessage struct {
}
// NewImageMessage creates a new ImageMessage object with the provided values and the default state.
-func NewImageMessage(matrix ifc.MatrixContainer, id, sender, displayname, msgtype, body, homeserver, fileID string, data []byte, timestamp time.Time) UIMessage {
+func NewImageMessage(matrix ifc.MatrixContainer, id, sender, displayname string, msgtype gomatrix.MessageType, body, homeserver, fileID string, data []byte, timestamp time.Time) UIMessage {
return &ImageMessage{
newBaseMessage(id, sender, displayname, msgtype, timestamp),
body,
diff --git a/ui/messages/parser/htmlparser.go b/ui/messages/parser/htmlparser.go
index c8b000e..bcde14d 100644
--- a/ui/messages/parser/htmlparser.go
+++ b/ui/messages/parser/htmlparser.go
@@ -22,6 +22,7 @@ import (
"regexp"
"strings"
+ "github.com/lucasb-eyer/go-colorful"
"golang.org/x/net/html"
"maunium.net/go/gomatrix"
"maunium.net/go/gomuks/matrix/rooms"
@@ -29,7 +30,6 @@ import (
"maunium.net/go/gomuks/ui/widget"
"maunium.net/go/tcell"
"strconv"
- "github.com/lucasb-eyer/go-colorful"
)
var matrixToURL = regexp.MustCompile("^(?:https?://)?(?:www\\.)?matrix\\.to/#/([#@!].*)")
@@ -173,7 +173,7 @@ func (parser *htmlParser) linkToTString(node *html.Node, stripLinebreak bool) ts
pillTarget := match[1]
if pillTarget[0] == '@' {
if member := parser.room.GetMember(pillTarget); member != nil {
- return tstring.NewColorTString(member.DisplayName, widget.GetHashColor(member.UserID))
+ return tstring.NewColorTString(member.Displayname, widget.GetHashColor(pillTarget))
}
}
return tstring.NewTString(pillTarget)
@@ -271,14 +271,13 @@ func (parser *htmlParser) Parse(htmlData string) tstring.TString {
// ParseHTMLMessage parses a HTML-formatted Matrix event into a UIMessage.
func ParseHTMLMessage(room *rooms.Room, evt *gomatrix.Event, senderDisplayname string) tstring.TString {
- htmlData, _ := evt.Content["formatted_body"].(string)
+ htmlData := evt.Content.FormattedBody
htmlData = strings.Replace(htmlData, "\t", " ", -1)
parser := htmlParser{room}
str := parser.Parse(htmlData)
- msgtype, _ := evt.Content["msgtype"].(string)
- if msgtype == "m.emote" {
+ if evt.Content.MsgType == gomatrix.MsgEmote {
str = tstring.Join([]tstring.TString{
tstring.NewTString("* "),
tstring.NewColorTString(senderDisplayname, widget.GetHashColor(evt.Sender)),
diff --git a/ui/messages/parser/parser.go b/ui/messages/parser/parser.go
index c84a7f4..1d7ced3 100644
--- a/ui/messages/parser/parser.go
+++ b/ui/messages/parser/parser.go
@@ -33,9 +33,9 @@ import (
func ParseEvent(matrix ifc.MatrixContainer, room *rooms.Room, evt *gomatrix.Event) messages.UIMessage {
switch evt.Type {
- case "m.room.message":
+ case gomatrix.EventMessage:
return ParseMessage(matrix, room, evt)
- case "m.room.member":
+ case gomatrix.StateMember:
return ParseMembershipEvent(room, evt)
}
return nil
@@ -53,32 +53,28 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *gomatrix.Ev
displayname := evt.Sender
member := room.GetMember(evt.Sender)
if member != nil {
- displayname = member.DisplayName
+ displayname = member.Displayname
}
- msgtype, _ := evt.Content["msgtype"].(string)
- text, _ := evt.Content["body"].(string)
ts := unixToTime(evt.Timestamp)
- switch msgtype {
+ switch evt.Content.MsgType {
case "m.text", "m.notice", "m.emote":
- format, hasFormat := evt.Content["format"].(string)
- if hasFormat && format == "org.matrix.custom.html" {
+ if evt.Content.Format == gomatrix.FormatHTML {
text := ParseHTMLMessage(room, evt, displayname)
- return messages.NewExpandedTextMessage(evt.ID, evt.Sender, displayname, msgtype, text, ts)
+ return messages.NewExpandedTextMessage(evt.ID, evt.Sender, displayname, evt.Content.MsgType, text, ts)
}
- text = strings.Replace(text, "\t", " ", -1)
- return messages.NewTextMessage(evt.ID, evt.Sender, displayname, msgtype, text, ts)
+ evt.Content.Body = strings.Replace(evt.Content.Body, "\t", " ", -1)
+ return messages.NewTextMessage(evt.ID, evt.Sender, displayname, evt.Content.MsgType, evt.Content.Body, ts)
case "m.image":
- url, _ := evt.Content["url"].(string)
- data, hs, id, err := matrix.Download(url)
+ data, hs, id, err := matrix.Download(evt.Content.URL)
if err != nil {
- debug.Printf("Failed to download %s: %v", url, err)
+ debug.Printf("Failed to download %s: %v", evt.Content.URL, err)
}
- return messages.NewImageMessage(matrix, evt.ID, evt.Sender, displayname, msgtype, text, hs, id, data, ts)
+ return messages.NewImageMessage(matrix, evt.ID, evt.Sender, displayname, evt.Content.MsgType, evt.Content.Body, hs, id, data, ts)
}
return nil
}
-func getMembershipChangeMessage(evt *gomatrix.Event, membership, prevMembership, senderDisplayname, displayname, prevDisplayname string) (sender string, text tstring.TString) {
+func getMembershipChangeMessage(evt *gomatrix.Event, membership, prevMembership gomatrix.Membership, senderDisplayname, displayname, prevDisplayname string) (sender string, text tstring.TString) {
switch membership {
case "invite":
sender = "---"
@@ -92,12 +88,11 @@ func getMembershipChangeMessage(evt *gomatrix.Event, membership, prevMembership,
case "leave":
sender = "<--"
if evt.Sender != *evt.StateKey {
- if prevMembership == "ban" {
+ if prevMembership == gomatrix.MembershipBan {
text = tstring.NewColorTString(fmt.Sprintf("%s unbanned %s", senderDisplayname, displayname), tcell.ColorGreen)
text.Colorize(len(senderDisplayname)+len(" unbanned "), len(displayname), widget.GetHashColor(*evt.StateKey))
} else {
- reason, _ := evt.Content["reason"].(string)
- text = tstring.NewColorTString(fmt.Sprintf("%s kicked %s: %s", senderDisplayname, displayname, reason), tcell.ColorRed)
+ text = tstring.NewColorTString(fmt.Sprintf("%s kicked %s: %s", senderDisplayname, displayname, evt.Content.Reason), tcell.ColorRed)
text.Colorize(len(senderDisplayname)+len(" kicked "), len(displayname), widget.GetHashColor(*evt.StateKey))
}
text.Colorize(0, len(senderDisplayname), widget.GetHashColor(evt.Sender))
@@ -109,8 +104,7 @@ func getMembershipChangeMessage(evt *gomatrix.Event, membership, prevMembership,
text.Colorize(0, len(displayname), widget.GetHashColor(*evt.StateKey))
}
case "ban":
- reason, _ := evt.Content["reason"].(string)
- text = tstring.NewColorTString(fmt.Sprintf("%s banned %s: %s", senderDisplayname, displayname, reason), tcell.ColorRed)
+ text = tstring.NewColorTString(fmt.Sprintf("%s banned %s: %s", senderDisplayname, displayname, evt.Content.Reason), tcell.ColorRed)
text.Colorize(len(senderDisplayname)+len(" banned "), len(displayname), widget.GetHashColor(*evt.StateKey))
text.Colorize(0, len(senderDisplayname), widget.GetHashColor(evt.Sender))
}
@@ -121,20 +115,20 @@ func getMembershipEventContent(room *rooms.Room, evt *gomatrix.Event) (sender st
member := room.GetMember(evt.Sender)
senderDisplayname := evt.Sender
if member != nil {
- senderDisplayname = member.DisplayName
+ senderDisplayname = member.Displayname
}
- membership, _ := evt.Content["membership"].(string)
- displayname, _ := evt.Content["displayname"].(string)
+ membership := evt.Content.Membership
+ displayname := evt.Content.Displayname
if len(displayname) == 0 {
displayname = *evt.StateKey
}
- prevMembership := "leave"
+ prevMembership := gomatrix.MembershipLeave
prevDisplayname := *evt.StateKey
if evt.Unsigned.PrevContent != nil {
- prevMembership, _ = evt.Unsigned.PrevContent["membership"].(string)
- prevDisplayname, _ = evt.Unsigned.PrevContent["displayname"].(string)
+ prevMembership = evt.Unsigned.PrevContent.Membership
+ prevDisplayname = evt.Unsigned.PrevContent.Displayname
if len(prevDisplayname) == 0 {
prevDisplayname = *evt.StateKey
}
diff --git a/ui/messages/textmessage.go b/ui/messages/textmessage.go
index d268688..d5ce324 100644
--- a/ui/messages/textmessage.go
+++ b/ui/messages/textmessage.go
@@ -19,6 +19,7 @@ package messages
import (
"encoding/gob"
"fmt"
+ "maunium.net/go/gomatrix"
"time"
"maunium.net/go/gomuks/config"
@@ -37,7 +38,7 @@ type TextMessage struct {
}
// NewTextMessage creates a new UITextMessage object with the provided values and the default state.
-func NewTextMessage(id, sender, displayname, msgtype, text string, timestamp time.Time) UIMessage {
+func NewTextMessage(id, sender, displayname string, msgtype gomatrix.MessageType, text string, timestamp time.Time) UIMessage {
return &TextMessage{
BaseMessage: newBaseMessage(id, sender, displayname, msgtype, timestamp),
MsgText: text,
@@ -57,7 +58,7 @@ func (msg *TextMessage) getCache() tstring.TString {
return msg.cache
}
-func (msg *TextMessage) SetType(msgtype string) {
+func (msg *TextMessage) SetType(msgtype gomatrix.MessageType) {
msg.BaseMessage.SetType(msgtype)
msg.cache = nil
}
diff --git a/ui/room-view.go b/ui/room-view.go
index bb8f5ec..4b2cd48 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -18,6 +18,7 @@ package ui
import (
"fmt"
+ "maunium.net/go/gomatrix"
"path/filepath"
"sort"
"strconv"
@@ -242,7 +243,7 @@ func (view *RoomView) SetTyping(users []string) {
for index, user := range users {
member := view.Room.GetMember(user)
if member != nil {
- users[index] = member.DisplayName
+ users[index] = member.Displayname
}
}
view.typing = users
@@ -255,14 +256,14 @@ type completion struct {
func (view *RoomView) autocompleteUser(existingText string) (completions []completion) {
textWithoutPrefix := strings.TrimPrefix(existingText, "@")
- for _, user := range view.Room.GetMembers() {
- if user.DisplayName == textWithoutPrefix || user.UserID == existingText {
+ for userID, user := range view.Room.GetMembers() {
+ if user.Displayname == textWithoutPrefix || userID == existingText {
// Exact match, return that.
- return []completion{{user.DisplayName, user.UserID}}
+ return []completion{{user.Displayname, userID}}
}
- if strings.HasPrefix(user.DisplayName, textWithoutPrefix) || strings.HasPrefix(user.UserID, existingText) {
- completions = append(completions, completion{user.DisplayName, user.UserID})
+ if strings.HasPrefix(user.Displayname, textWithoutPrefix) || strings.HasPrefix(userID, existingText) {
+ completions = append(completions, completion{user.Displayname, userID})
}
}
return
@@ -330,12 +331,12 @@ func (view *RoomView) MxRoom() *rooms.Room {
func (view *RoomView) UpdateUserList() {
var joined strings.Builder
var invited strings.Builder
- for _, user := range view.Room.GetMembers() {
+ for userID, user := range view.Room.GetMembers() {
if user.Membership == "join" {
- joined.WriteString(widget.AddColor(user.DisplayName, widget.GetHashColorName(user.UserID)))
+ joined.WriteString(widget.AddColor(user.Displayname, widget.GetHashColorName(userID)))
joined.WriteRune('\n')
} else if user.Membership == "invite" {
- invited.WriteString(widget.AddColor(user.DisplayName, widget.GetHashColorName(user.UserID)))
+ invited.WriteString(widget.AddColor(user.Displayname, widget.GetHashColorName(userID)))
invited.WriteRune('\n')
}
}
@@ -346,26 +347,26 @@ func (view *RoomView) UpdateUserList() {
}
}
-func (view *RoomView) newUIMessage(id, sender, msgtype, text string, timestamp time.Time) messages.UIMessage {
+func (view *RoomView) newUIMessage(id, sender string, msgtype gomatrix.MessageType, text string, timestamp time.Time) messages.UIMessage {
member := view.Room.GetMember(sender)
displayname := sender
if member != nil {
- displayname = member.DisplayName
+ displayname = member.Displayname
}
msg := messages.NewTextMessage(id, sender, displayname, msgtype, text, timestamp)
return msg
}
-func (view *RoomView) NewMessage(id, sender, msgtype, text string, timestamp time.Time) ifc.Message {
+func (view *RoomView) NewMessage(id, sender string, msgtype gomatrix.MessageType, text string, timestamp time.Time) ifc.Message {
return view.newUIMessage(id, sender, msgtype, text, timestamp)
}
-func (view *RoomView) NewTempMessage(msgtype, text string) ifc.Message {
+func (view *RoomView) NewTempMessage(msgtype gomatrix.MessageType, text string) ifc.Message {
now := time.Now()
id := strconv.FormatInt(now.UnixNano(), 10)
sender := ""
- if ownerMember := view.Room.GetSessionOwner(); ownerMember != nil {
- sender = ownerMember.DisplayName
+ if ownerMember := view.Room.GetMember(view.Room.GetSessionOwner()); ownerMember != nil {
+ sender = ownerMember.Displayname
}
message := view.newUIMessage(id, sender, msgtype, text, now)
message.SetState(ifc.MessageStateSending)
diff --git a/ui/view-main.go b/ui/view-main.go
index f38043a..c5abb19 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -497,7 +497,7 @@ func (view *MainView) LoadHistory(room string) {
}
roomView.Room.PrevBatch = prevBatch
for _, evt := range history {
- message := view.ParseEvent(roomView, &evt)
+ message := view.ParseEvent(roomView, evt)
if message != nil {
roomView.AddMessage(message, ifc.PrependMessage)
}