aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/fuzzy-search-modal.go1
-rw-r--r--ui/member-list.go2
-rw-r--r--ui/messages/base.go5
-rw-r--r--ui/messages/filemessage.go9
-rw-r--r--ui/messages/html/parser.go13
-rw-r--r--ui/messages/parser.go86
-rw-r--r--ui/room-view.go30
7 files changed, 74 insertions, 72 deletions
diff --git a/ui/fuzzy-search-modal.go b/ui/fuzzy-search-modal.go
index bf9004b..8aeb058 100644
--- a/ui/fuzzy-search-modal.go
+++ b/ui/fuzzy-search-modal.go
@@ -119,7 +119,6 @@ func (fs *FuzzySearchModal) changeHandler(str string) {
func (fs *FuzzySearchModal) OnKeyEvent(event mauview.KeyEvent) bool {
highlights := fs.results.GetHighlights()
- debug.Print("Search key event:", event)
switch event.Key() {
case tcell.KeyEsc:
// Close room finder
diff --git a/ui/member-list.go b/ui/member-list.go
index b47840e..87e7b5d 100644
--- a/ui/member-list.go
+++ b/ui/member-list.go
@@ -65,7 +65,7 @@ func (rml roomMemberList) Swap(i, j int) {
rml[i], rml[j] = rml[j], rml[i]
}
-func (ml *MemberList) Update(data map[id.UserID]*rooms.Member, levels *event.PowerLevels) *MemberList {
+func (ml *MemberList) Update(data map[id.UserID]*rooms.Member, levels *event.PowerLevelsEventContent) *MemberList {
ml.list = make(roomMemberList, len(data))
i := 0
highestLevel := math.MinInt32
diff --git a/ui/messages/base.go b/ui/messages/base.go
index eaeb552..c4e10b0 100644
--- a/ui/messages/base.go
+++ b/ui/messages/base.go
@@ -95,7 +95,8 @@ const DateFormat = "January _2, 2006"
const TimeFormat = "15:04:05"
func newUIMessage(evt *muksevt.Event, displayname string, renderer MessageRenderer) *UIMessage {
- msgtype := evt.Content.MsgType
+ msgContent := evt.Content.AsMessage()
+ msgtype := msgContent.MsgType
if len(msgtype) == 0 {
msgtype = event.MessageType(evt.Type.String())
}
@@ -117,7 +118,7 @@ func newUIMessage(evt *muksevt.Event, displayname string, renderer MessageRender
Type: msgtype,
EventID: evt.ID,
TxnID: evt.Unsigned.TransactionID,
- Relation: *evt.Content.GetRelatesTo(),
+ Relation: *msgContent.GetRelatesTo(),
State: evt.Gomuks.OutgoingState,
IsHighlight: false,
IsService: false,
diff --git a/ui/messages/filemessage.go b/ui/messages/filemessage.go
index baffd0f..5b7b21c 100644
--- a/ui/messages/filemessage.go
+++ b/ui/messages/filemessage.go
@@ -48,11 +48,12 @@ type FileMessage struct {
// NewFileMessage creates a new FileMessage object with the provided values and the default state.
func NewFileMessage(matrix ifc.MatrixContainer, evt *muksevt.Event, displayname string) *UIMessage {
- url, _ := evt.Content.URL.Parse()
- thumbnail, _ := evt.Content.GetInfo().ThumbnailURL.Parse()
+ content := evt.Content.AsMessage()
+ url, _ := content.URL.Parse()
+ thumbnail, _ := content.GetInfo().ThumbnailURL.Parse()
return newUIMessage(evt, displayname, &FileMessage{
- Type: evt.Content.MsgType,
- Body: evt.Content.Body,
+ Type: content.MsgType,
+ Body: content.Body,
URL: url,
Thumbnail: thumbnail,
matrix: matrix,
diff --git a/ui/messages/html/parser.go b/ui/messages/html/parser.go
index 86b501d..7bb4a84 100644
--- a/ui/messages/html/parser.go
+++ b/ui/messages/html/parser.go
@@ -27,7 +27,6 @@ import (
"github.com/lucasb-eyer/go-colorful"
"golang.org/x/net/html"
- "maunium.net/go/gomuks/matrix/muksevt"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
"maunium.net/go/tcell"
@@ -384,10 +383,10 @@ func (parser *htmlParser) Parse(htmlData string) Entity {
const TabLength = 4
// Parse parses a HTML-formatted Matrix event into a UIMessage.
-func Parse(room *rooms.Room, evt *muksevt.Event, senderDisplayname string) Entity {
- htmlData := evt.Content.FormattedBody
- if evt.Content.Format != event.FormatHTML {
- htmlData = strings.Replace(html.EscapeString(evt.Content.Body), "\n", "<br/>", -1)
+func Parse(room *rooms.Room, content *event.MessageEventContent, sender id.UserID, senderDisplayname string) Entity {
+ htmlData := content.FormattedBody
+ if content.Format != event.FormatHTML {
+ htmlData = strings.Replace(html.EscapeString(content.Body), "\n", "<br/>", -1)
}
htmlData = strings.Replace(htmlData, "\t", strings.Repeat(" ", TabLength), -1)
@@ -403,14 +402,14 @@ func Parse(room *rooms.Room, evt *muksevt.Event, senderDisplayname string) Entit
}
}
- if evt.Content.MsgType == event.MsgEmote {
+ if content.MsgType == event.MsgEmote {
root = &ContainerEntity{
BaseEntity: &BaseEntity{
Tag: "emote",
},
Children: []Entity{
NewTextEntity("* "),
- NewTextEntity(senderDisplayname).AdjustStyle(AdjustStyleTextColor(widget.GetHashColor(evt.Sender))),
+ NewTextEntity(senderDisplayname).AdjustStyle(AdjustStyleTextColor(widget.GetHashColor(sender))),
NewTextEntity(" "),
root,
},
diff --git a/ui/messages/parser.go b/ui/messages/parser.go
index d89bcb9..616e7cb 100644
--- a/ui/messages/parser.go
+++ b/ui/messages/parser.go
@@ -20,6 +20,7 @@ import (
"fmt"
"strings"
+ "maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/matrix/muksevt"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
@@ -48,10 +49,10 @@ func ParseEvent(matrix ifc.MatrixContainer, mainView ifc.MainView, room *rooms.R
if msg == nil {
return nil
}
- if len(evt.Content.GetReplyTo()) > 0 {
- if replyToMsg := getCachedEvent(mainView, room.ID, evt.Content.GetReplyTo()); replyToMsg != nil {
+ if content, ok := evt.Content.Parsed.(*event.MessageEventContent); ok && len(content.GetReplyTo()) > 0 {
+ if replyToMsg := getCachedEvent(mainView, room.ID, content.GetReplyTo()); replyToMsg != nil {
msg.ReplyTo = replyToMsg.Clone()
- } else if replyToEvt, _ := matrix.GetEvent(room, evt.Content.GetReplyTo()); replyToEvt != nil {
+ } else if replyToEvt, _ := matrix.GetEvent(room, content.GetReplyTo()); replyToEvt != nil {
if replyToMsg := directParseEvent(matrix, room, replyToEvt); replyToMsg != nil {
msg.ReplyTo = replyToMsg
msg.ReplyTo.Reactions = nil
@@ -74,48 +75,49 @@ func directParseEvent(matrix ifc.MatrixContainer, room *rooms.Room, evt *muksevt
if evt.Unsigned.RedactedBecause != nil || evt.Type == event.EventRedaction {
return NewRedactedMessage(evt, displayname)
}
- switch evt.Type {
- case event.EventSticker:
- evt.Content.MsgType = event.MsgImage
- fallthrough
- case event.EventMessage:
+ switch content := evt.Content.Parsed.(type) {
+ case *event.MessageEventContent:
+ if evt.Type == event.EventSticker {
+ content.MsgType = event.MsgImage
+ }
return ParseMessage(matrix, room, evt, displayname)
- case event.EventEncrypted:
+ case *event.EncryptedEventContent:
return NewExpandedTextMessage(evt, displayname, tstring.NewStyleTString("Encrypted messages are not yet supported", tcell.StyleDefault.Italic(true)))
- case event.StateTopic, event.StateRoomName, event.StateAliases, event.StateCanonicalAlias:
+ case *event.TopicEventContent, *event.RoomNameEventContent, *event.CanonicalAliasEventContent:
return ParseStateEvent(evt, displayname)
- case event.StateMember:
+ case *event.MemberEventContent:
return ParseMembershipEvent(room, evt)
+ default:
+ debug.Printf("Unknown event content type %T in directParseEvent", content)
+ return nil
}
-
- return nil
}
func ParseStateEvent(evt *muksevt.Event, displayname string) *UIMessage {
text := tstring.NewColorTString(displayname, widget.GetHashColor(evt.Sender))
- switch evt.Type {
- case event.StateTopic:
- if len(evt.Content.Topic) == 0 {
+ switch content := evt.Content.Parsed.(type) {
+ case *event.TopicEventContent:
+ if len(content.Topic) == 0 {
text = text.AppendColor(" removed the topic.", tcell.ColorGreen)
} else {
text = text.AppendColor(" changed the topic to ", tcell.ColorGreen).
- AppendStyle(evt.Content.Topic, tcell.StyleDefault.Underline(true)).
+ AppendStyle(content.Topic, tcell.StyleDefault.Underline(true)).
AppendColor(".", tcell.ColorGreen)
}
- case event.StateRoomName:
- if len(evt.Content.Name) == 0 {
+ case *event.RoomNameEventContent:
+ if len(content.Name) == 0 {
text = text.AppendColor(" removed the room name.", tcell.ColorGreen)
} else {
text = text.AppendColor(" changed the room name to ", tcell.ColorGreen).
- AppendStyle(evt.Content.Name, tcell.StyleDefault.Underline(true)).
+ AppendStyle(content.Name, tcell.StyleDefault.Underline(true)).
AppendColor(".", tcell.ColorGreen)
}
- case event.StateCanonicalAlias:
- if len(evt.Content.Alias) == 0 {
+ case *event.CanonicalAliasEventContent:
+ if len(content.Alias) == 0 {
text = text.AppendColor(" removed the main address of the room.", tcell.ColorGreen)
} else {
text = text.AppendColor(" changed the main address of the room to ", tcell.ColorGreen).
- AppendStyle(string(evt.Content.Alias), tcell.StyleDefault.Underline(true)).
+ AppendStyle(string(content.Alias), tcell.StyleDefault.Underline(true)).
AppendColor(".", tcell.ColorGreen)
}
//case event.StateAliases:
@@ -125,19 +127,20 @@ func ParseStateEvent(evt *muksevt.Event, displayname string) *UIMessage {
}
func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *muksevt.Event, displayname string) *UIMessage {
- if len(evt.Content.GetReplyTo()) > 0 {
- evt.Content.RemoveReplyFallback()
+ content := evt.Content.AsMessage()
+ if len(content.GetReplyTo()) > 0 {
+ content.RemoveReplyFallback()
}
if len(evt.Gomuks.Edits) > 0 {
- evt.Content = *evt.Gomuks.Edits[len(evt.Gomuks.Edits)-1].Content.NewContent
+ content = evt.Gomuks.Edits[len(evt.Gomuks.Edits)-1].Content.AsMessage().NewContent
}
- switch evt.Content.MsgType {
+ switch content.MsgType {
case event.MsgText, event.MsgNotice, event.MsgEmote:
- if evt.Content.Format == event.FormatHTML {
- return NewHTMLMessage(evt, displayname, html.Parse(room, evt, displayname))
+ if content.Format == event.FormatHTML {
+ return NewHTMLMessage(evt, displayname, html.Parse(room, content, evt.Sender, displayname))
}
- evt.Content.Body = strings.Replace(evt.Content.Body, "\t", " ", -1)
- return NewTextMessage(evt, displayname, evt.Content.Body)
+ content.Body = strings.Replace(content.Body, "\t", " ", -1)
+ return NewTextMessage(evt, displayname, content.Body)
case event.MsgImage, event.MsgVideo, event.MsgAudio, event.MsgFile:
msg := NewFileMessage(matrix, evt, displayname)
if !matrix.Preferences().DisableDownloads {
@@ -149,8 +152,8 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *muksevt.Eve
return nil
}
-func getMembershipChangeMessage(evt *muksevt.Event, membership, prevMembership event.Membership, senderDisplayname, displayname, prevDisplayname string) (sender string, text tstring.TString) {
- switch membership {
+func getMembershipChangeMessage(evt *muksevt.Event, content *event.MemberEventContent, prevMembership event.Membership, senderDisplayname, displayname, prevDisplayname string) (sender string, text tstring.TString) {
+ switch content.Membership {
case "invite":
sender = "---"
text = tstring.NewColorTString(fmt.Sprintf("%s invited %s.", senderDisplayname, displayname), tcell.ColorGreen)
@@ -171,7 +174,7 @@ func getMembershipChangeMessage(evt *muksevt.Event, membership, prevMembership e
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 {
- text = tstring.NewColorTString(fmt.Sprintf("%s kicked %s: %s", senderDisplayname, displayname, evt.Content.Reason), tcell.ColorRed)
+ text = tstring.NewColorTString(fmt.Sprintf("%s kicked %s: %s", senderDisplayname, displayname, 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))
@@ -187,7 +190,7 @@ func getMembershipChangeMessage(evt *muksevt.Event, membership, prevMembership e
text.Colorize(0, len(displayname), widget.GetHashColor(evt.StateKey))
}
case "ban":
- text = tstring.NewColorTString(fmt.Sprintf("%s banned %s: %s", senderDisplayname, displayname, evt.Content.Reason), tcell.ColorRed)
+ text = tstring.NewColorTString(fmt.Sprintf("%s banned %s: %s", senderDisplayname, displayname, 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))
}
@@ -201,8 +204,8 @@ func getMembershipEventContent(room *rooms.Room, evt *muksevt.Event) (sender str
senderDisplayname = member.Displayname
}
- membership := evt.Content.Membership
- displayname := evt.Content.Displayname
+ content := evt.Content.AsMember()
+ displayname := content.Displayname
if len(displayname) == 0 {
displayname = *evt.StateKey
}
@@ -210,15 +213,16 @@ func getMembershipEventContent(room *rooms.Room, evt *muksevt.Event) (sender str
prevMembership := event.MembershipLeave
prevDisplayname := *evt.StateKey
if evt.Unsigned.PrevContent != nil {
- prevMembership = evt.Unsigned.PrevContent.Membership
- prevDisplayname = evt.Unsigned.PrevContent.Displayname
+ prevContent := evt.Unsigned.PrevContent.AsMember()
+ prevMembership = prevContent.Membership
+ prevDisplayname = prevContent.Displayname
if len(prevDisplayname) == 0 {
prevDisplayname = *evt.StateKey
}
}
- if membership != prevMembership {
- sender, text = getMembershipChangeMessage(evt, membership, prevMembership, senderDisplayname, displayname, prevDisplayname)
+ if content.Membership != prevMembership {
+ sender, text = getMembershipChangeMessage(evt, content, prevMembership, senderDisplayname, displayname, prevDisplayname)
} else if displayname != prevDisplayname {
sender = "---"
color := widget.GetHashColor(evt.StateKey)
diff --git a/ui/room-view.go b/ui/room-view.go
index 8408e25..ba6259b 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -480,8 +480,8 @@ func (view *RoomView) SetEditing(evt *muksevt.Event) {
view.editing = evt
// replying should never be non-nil when SetEditing, but do this just to be safe
view.replying = nil
- text := view.editing.Content.Body
- if view.editing.Content.MsgType == event.MsgEmote {
+ text := view.editing.Content.AsMessage().Body
+ if view.editing.Content.AsMessage().MsgType == event.MsgEmote {
text = "/me " + text
}
view.input.SetText(text)
@@ -497,11 +497,11 @@ func (view *RoomView) filterOwnOnly(evt *muksevt.Event) bool {
}
func (view *RoomView) filterMediaOnly(evt *muksevt.Event) bool {
- return evt.Type == event.EventMessage && (
- evt.Content.MsgType == event.MsgFile ||
- evt.Content.MsgType == event.MsgImage ||
- evt.Content.MsgType == event.MsgAudio ||
- evt.Content.MsgType == event.MsgVideo)
+ content, ok := evt.Content.Parsed.(*event.MessageEventContent)
+ return ok && content.MsgType == event.MsgFile ||
+ content.MsgType == event.MsgImage ||
+ content.MsgType == event.MsgAudio ||
+ content.MsgType == event.MsgVideo
}
func (view *RoomView) findMessage(current *muksevt.Event, forward bool, allow findFilter) *messages.UIMessage {
@@ -660,13 +660,11 @@ func (view *RoomView) SendReaction(eventID id.EventID, reaction string) {
Event: &event.Event{
Type: event.EventReaction,
RoomID: view.Room.ID,
- Content: event.Content{
- RelatesTo: &event.RelatesTo{
- Type: event.RelAnnotation,
- EventID: eventID,
- Key: reaction,
- },
- },
+ Content: event.Content{Parsed: event.ReactionEventContent{RelatesTo: event.RelatesTo{
+ Type: event.RelAnnotation,
+ EventID: eventID,
+ Key: reaction,
+ }}},
},
})
if err != nil {
@@ -745,9 +743,9 @@ func (view *RoomView) Update() {
}
func (view *RoomView) UpdateUserList() {
- pls := &event.PowerLevels{}
+ pls := &event.PowerLevelsEventContent{}
if plEvent := view.Room.GetStateEvent(event.StatePowerLevels, ""); plEvent != nil {
- pls = plEvent.Content.GetPowerLevels()
+ pls = plEvent.Content.AsPowerLevels()
}
view.userList.Update(view.Room.GetMembers(), pls)
view.userListLoaded = true