aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/commands.go53
-rw-r--r--ui/fuzzy-search-modal.go3
-rw-r--r--ui/member-list.go7
-rw-r--r--ui/message-view.go22
-rw-r--r--ui/messages/base.go39
-rw-r--r--ui/messages/expandedtextmessage.go4
-rw-r--r--ui/messages/filemessage.go27
-rw-r--r--ui/messages/html/parser.go15
-rw-r--r--ui/messages/htmlmessage.go4
-rw-r--r--ui/messages/parser.go205
-rw-r--r--ui/messages/redactedmessage.go4
-rw-r--r--ui/messages/textmessage.go4
-rw-r--r--ui/room-list.go3
-rw-r--r--ui/room-view.go133
-rw-r--r--ui/view-login.go5
-rw-r--r--ui/view-main.go17
-rw-r--r--ui/widget/color.go15
17 files changed, 302 insertions, 258 deletions
diff --git a/ui/commands.go b/ui/commands.go
index a74a164..ba13fc3 100644
--- a/ui/commands.go
+++ b/ui/commands.go
@@ -35,14 +35,16 @@ import (
"github.com/russross/blackfriday/v2"
"maunium.net/go/mautrix"
+ "maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/format"
+ "maunium.net/go/mautrix/id"
"maunium.net/go/gomuks/debug"
)
func cmdMe(cmd *Command) {
text := strings.Join(cmd.Args, " ")
- go cmd.Room.SendMessage(mautrix.MsgEmote, text)
+ go cmd.Room.SendMessage(event.MsgEmote, text)
}
// GradientTable from https://github.com/lucasb-eyer/go-colorful/blob/master/doc/gradientgen/gradientgen.go
@@ -79,7 +81,7 @@ var rainbow = GradientTable{
}
// TODO this command definitely belongs in a plugin once we have a plugin system.
-func makeRainbow(cmd *Command, msgtype mautrix.MessageType) {
+func makeRainbow(cmd *Command, msgtype event.MessageType) {
text := strings.Join(cmd.Args, " ")
render := NewRainbowRenderer(blackfriday.NewHTMLRenderer(blackfriday.HTMLRendererParameters{
@@ -101,15 +103,15 @@ func makeRainbow(cmd *Command, msgtype mautrix.MessageType) {
}
func cmdRainbow(cmd *Command) {
- makeRainbow(cmd, mautrix.MsgText)
+ makeRainbow(cmd, event.MsgText)
}
func cmdRainbowMe(cmd *Command) {
- makeRainbow(cmd, mautrix.MsgEmote)
+ makeRainbow(cmd, event.MsgEmote)
}
func cmdNotice(cmd *Command) {
- go cmd.Room.SendMessage(mautrix.MsgNotice, strings.Join(cmd.Args, " "))
+ go cmd.Room.SendMessage(event.MsgNotice, strings.Join(cmd.Args, " "))
}
func cmdAccept(cmd *Command) {
@@ -118,7 +120,7 @@ func cmdAccept(cmd *Command) {
cmd.Reply("/accept can only be used in rooms you're invited to")
return
}
- _, server, _ := mautrix.ParseUserID(room.SessionMember.Sender)
+ _, server, _ := room.SessionMember.Sender.Parse()
_, err := cmd.Matrix.JoinRoom(room.ID, server)
if err != nil {
cmd.Reply("Failed to accept invite:", err)
@@ -223,11 +225,11 @@ func cmdTag(cmd *Command) {
}
var err error
if len(cmd.Args) > 2 && cmd.Args[2] == "--reset" {
- tags := mautrix.Tags{
+ tags := event.Tags{
cmd.Args[0]: {Order: json.Number(fmt.Sprintf("%f", order))},
}
for _, tag := range cmd.Room.MxRoom().RawTags {
- tags[tag.Tag] = mautrix.Tag{Order: tag.Order}
+ tags[tag.Tag] = event.Tag{Order: tag.Order}
}
err = cmd.Matrix.Client().SetTags(cmd.Room.MxRoom().ID, tags)
} else {
@@ -253,7 +255,7 @@ func cmdRoomNick(cmd *Command) {
room := cmd.Room.MxRoom()
member := room.GetMember(room.SessionUserID)
member.Displayname = strings.Join(cmd.Args, " ")
- _, err := cmd.Matrix.Client().SendStateEvent(room.ID, mautrix.StateMember, room.SessionUserID, member)
+ _, err := cmd.Matrix.Client().SendStateEvent(room.ID, event.StateMember, string(room.SessionUserID), member)
if err != nil {
cmd.Reply("Failed to set room nick:", err)
}
@@ -376,7 +378,7 @@ func cmdInvite(cmd *Command) {
cmd.Reply("Usage: /invite <user id>")
return
}
- _, err := cmd.Matrix.Client().InviteUser(cmd.Room.MxRoom().ID, &mautrix.ReqInviteUser{UserID: cmd.Args[0]})
+ _, err := cmd.Matrix.Client().InviteUser(cmd.Room.MxRoom().ID, &mautrix.ReqInviteUser{UserID: id.UserID(cmd.Args[0])})
if err != nil {
debug.Print("Error in invite call:", err)
cmd.Reply("Failed to invite user: %v", err)
@@ -392,7 +394,7 @@ func cmdBan(cmd *Command) {
if len(cmd.Args) >= 2 {
reason = strings.Join(cmd.Args[1:], " ")
}
- _, err := cmd.Matrix.Client().BanUser(cmd.Room.MxRoom().ID, &mautrix.ReqBanUser{Reason: reason, UserID: cmd.Args[0]})
+ _, err := cmd.Matrix.Client().BanUser(cmd.Room.MxRoom().ID, &mautrix.ReqBanUser{Reason: reason, UserID: id.UserID(cmd.Args[0])})
if err != nil {
debug.Print("Error in ban call:", err)
cmd.Reply("Failed to ban user: %v", err)
@@ -405,7 +407,7 @@ func cmdUnban(cmd *Command) {
cmd.Reply("Usage: /unban <user>")
return
}
- _, err := cmd.Matrix.Client().UnbanUser(cmd.Room.MxRoom().ID, &mautrix.ReqUnbanUser{UserID: cmd.Args[0]})
+ _, err := cmd.Matrix.Client().UnbanUser(cmd.Room.MxRoom().ID, &mautrix.ReqUnbanUser{UserID: id.UserID(cmd.Args[0])})
if err != nil {
debug.Print("Error in unban call:", err)
cmd.Reply("Failed to unban user: %v", err)
@@ -421,7 +423,7 @@ func cmdKick(cmd *Command) {
if len(cmd.Args) >= 2 {
reason = strings.Join(cmd.Args[1:], " ")
}
- _, err := cmd.Matrix.Client().KickUser(cmd.Room.MxRoom().ID, &mautrix.ReqKickUser{Reason: reason, UserID: cmd.Args[0]})
+ _, err := cmd.Matrix.Client().KickUser(cmd.Room.MxRoom().ID, &mautrix.ReqKickUser{Reason: reason, UserID: id.UserID(cmd.Args[0])})
if err != nil {
debug.Print("Error in kick call:", err)
debug.Print("Failed to kick user:", err)
@@ -445,9 +447,18 @@ func cmdPrivateMessage(cmd *Command) {
if len(cmd.Args) == 0 {
cmd.Reply("Usage: /pm <user id> [more user ids...]")
}
+ invites := make([]id.UserID, len(cmd.Args))
+ for i, userID := range cmd.Args {
+ invites[i] = id.UserID(userID)
+ _, _, err := invites[i].Parse()
+ if err != nil {
+ cmd.Reply("%s isn't a valid user ID", userID)
+ return
+ }
+ }
req := &mautrix.ReqCreateRoom{
Preset: "trusted_private_chat",
- Invite: cmd.Args,
+ Invite: invites,
}
room, err := cmd.Matrix.CreateRoom(req)
if err != nil {
@@ -462,7 +473,7 @@ func cmdJoin(cmd *Command) {
cmd.Reply("Usage: /join <room>")
return
}
- identifer := cmd.Args[0]
+ identifer := id.RoomID(cmd.Args[0])
server := ""
if len(cmd.Args) > 1 {
server = cmd.Args[1]
@@ -479,7 +490,7 @@ func cmdMSendEvent(cmd *Command) {
cmd.Reply("Usage: /msend <event type> <content>")
return
}
- cmd.Args = append([]string{cmd.Room.MxRoom().ID}, cmd.Args...)
+ cmd.Args = append([]string{string(cmd.Room.MxRoom().ID)}, cmd.Args...)
cmdSendEvent(cmd)
}
@@ -488,8 +499,8 @@ func cmdSendEvent(cmd *Command) {
cmd.Reply("Usage: /send <room id> <event type> <content>")
return
}
- roomID := cmd.Args[0]
- eventType := mautrix.NewEventType(cmd.Args[1])
+ roomID := id.RoomID(cmd.Args[0])
+ eventType := event.NewEventType(cmd.Args[1])
rawContent := strings.Join(cmd.Args[2:], " ")
var content interface{}
@@ -515,7 +526,7 @@ func cmdMSetState(cmd *Command) {
cmd.Reply("Usage: /msetstate <event type> <state key> <content>")
return
}
- cmd.Args = append([]string{cmd.Room.MxRoom().ID}, cmd.Args...)
+ cmd.Args = append([]string{string(cmd.Room.MxRoom().ID)}, cmd.Args...)
cmdSetState(cmd)
}
@@ -525,8 +536,8 @@ func cmdSetState(cmd *Command) {
return
}
- roomID := cmd.Args[0]
- eventType := mautrix.NewEventType(cmd.Args[1])
+ roomID := id.RoomID(cmd.Args[0])
+ eventType := event.NewEventType(cmd.Args[1])
stateKey := cmd.Args[2]
if stateKey == "-" {
stateKey = ""
diff --git a/ui/fuzzy-search-modal.go b/ui/fuzzy-search-modal.go
index 9f91877..bf9004b 100644
--- a/ui/fuzzy-search-modal.go
+++ b/ui/fuzzy-search-modal.go
@@ -23,6 +23,7 @@ import (
"github.com/lithammer/fuzzysearch/fuzzy"
+ "maunium.net/go/mautrix/id"
"maunium.net/go/mauview"
"maunium.net/go/tcell"
@@ -87,7 +88,7 @@ func (fs *FuzzySearchModal) Blur() {
fs.container.Blur()
}
-func (fs *FuzzySearchModal) InitList(rooms map[string]*RoomView) {
+func (fs *FuzzySearchModal) InitList(rooms map[id.RoomID]*RoomView) {
for _, room := range rooms {
if room.Room.IsReplaced() {
//if _, ok := rooms[room.Room.ReplacedBy()]; ok
diff --git a/ui/member-list.go b/ui/member-list.go
index e836e18..b47840e 100644
--- a/ui/member-list.go
+++ b/ui/member-list.go
@@ -23,7 +23,8 @@ import (
"github.com/mattn/go-runewidth"
- "maunium.net/go/mautrix"
+ "maunium.net/go/mautrix/event"
+ "maunium.net/go/mautrix/id"
"maunium.net/go/mauview"
"maunium.net/go/tcell"
@@ -43,7 +44,7 @@ type memberListItem struct {
rooms.Member
PowerLevel int
Sigil rune
- UserID string
+ UserID id.UserID
Color tcell.Color
}
@@ -64,7 +65,7 @@ func (rml roomMemberList) Swap(i, j int) {
rml[i], rml[j] = rml[j], rml[i]
}
-func (ml *MemberList) Update(data map[string]*rooms.Member, levels *mautrix.PowerLevels) *MemberList {
+func (ml *MemberList) Update(data map[id.UserID]*rooms.Member, levels *event.PowerLevels) *MemberList {
ml.list = make(roomMemberList, len(data))
i := 0
highestLevel := math.MinInt32
diff --git a/ui/message-view.go b/ui/message-view.go
index 4f406e1..764143f 100644
--- a/ui/message-view.go
+++ b/ui/message-view.go
@@ -25,10 +25,12 @@ import (
"github.com/mattn/go-runewidth"
sync "github.com/sasha-s/go-deadlock"
- "maunium.net/go/mautrix"
"maunium.net/go/mauview"
"maunium.net/go/tcell"
+ "maunium.net/go/mautrix/event"
+ "maunium.net/go/mautrix/id"
+
"maunium.net/go/gomuks/config"
"maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/interface"
@@ -59,7 +61,7 @@ type MessageView struct {
prevPrefs config.UserPreferences
messageIDLock sync.RWMutex
- messageIDs map[string]*messages.UIMessage
+ messageIDs map[id.EventID]*messages.UIMessage
messagesLock sync.RWMutex
messages []*messages.UIMessage
msgBufferLock sync.RWMutex
@@ -79,7 +81,7 @@ func NewMessageView(parent *RoomView) *MessageView {
ScrollOffset: 0,
messages: make([]*messages.UIMessage, 0),
- messageIDs: make(map[string]*messages.UIMessage),
+ messageIDs: make(map[id.EventID]*messages.UIMessage),
msgBuffer: make([]*messages.UIMessage, 0),
_width: 80,
@@ -95,7 +97,7 @@ func (view *MessageView) Unload() {
view.messagesLock.Lock()
view.msgBufferLock.Lock()
view.messageIDLock.Lock()
- view.messageIDs = make(map[string]*messages.UIMessage)
+ view.messageIDs = make(map[id.EventID]*messages.UIMessage)
view.msgBuffer = make([]*messages.UIMessage, 0)
view.messages = make([]*messages.UIMessage, 0)
view.initialHistoryLoaded = false
@@ -140,9 +142,9 @@ func (view *MessageView) AddMessage(ifcMessage ifc.Message, direction MessageDir
if oldMsg = view.getMessageByID(message.EventID); oldMsg != nil {
view.replaceMessage(oldMsg, message)
direction = IgnoreMessage
- } else if oldMsg = view.getMessageByID(message.TxnID); oldMsg != nil {
+ } else if oldMsg = view.getMessageByID(id.EventID(message.TxnID)); oldMsg != nil {
view.replaceMessage(oldMsg, message)
- view.deleteMessageID(message.TxnID)
+ view.deleteMessageID(id.EventID(message.TxnID))
direction = IgnoreMessage
}
@@ -208,7 +210,7 @@ func (view *MessageView) replaceMessage(original *messages.UIMessage, new *messa
view.messagesLock.Unlock()
}
-func (view *MessageView) getMessageByID(id string) *messages.UIMessage {
+func (view *MessageView) getMessageByID(id id.EventID) *messages.UIMessage {
if id == "" {
return nil
}
@@ -221,7 +223,7 @@ func (view *MessageView) getMessageByID(id string) *messages.UIMessage {
return msg
}
-func (view *MessageView) deleteMessageID(id string) {
+func (view *MessageView) deleteMessageID(id id.EventID) {
if id == "" {
return
}
@@ -365,7 +367,7 @@ func (view *MessageView) handleUsernameClick(message *messages.UIMessage, prevMe
// return false
//}
- if message.SenderName == "---" || message.SenderName == "-->" || message.SenderName == "<--" || message.Type == mautrix.MsgEmote {
+ if message.SenderName == "---" || message.SenderName == "-->" || message.SenderName == "<--" || message.Type == event.MsgEmote {
return false
}
@@ -564,7 +566,7 @@ func (view *MessageView) CapturePlaintext(height int) string {
var sender string
if len(message.Sender()) > 0 {
sender = fmt.Sprintf(" <%s>", message.Sender())
- } else if message.Type == mautrix.MsgEmote {
+ } else if message.Type == event.MsgEmote {
sender = fmt.Sprintf(" * %s", message.SenderName)
}
fmt.Fprintf(&buf, "%s%s %s\n", message.FormatTime(), sender, message.PlainText())
diff --git a/ui/messages/base.go b/ui/messages/base.go
index 745bfcd..eaeb552 100644
--- a/ui/messages/base.go
+++ b/ui/messages/base.go
@@ -22,8 +22,9 @@ import (
"time"
"maunium.net/go/gomuks/config"
- "maunium.net/go/gomuks/matrix/event"
- "maunium.net/go/mautrix"
+ "maunium.net/go/gomuks/matrix/muksevt"
+ "maunium.net/go/mautrix/event"
+ "maunium.net/go/mautrix/id"
"maunium.net/go/mauview"
"maunium.net/go/tcell"
@@ -64,26 +65,26 @@ func (rs ReactionSlice) Swap(i, j int) {
}
type UIMessage struct {
- EventID string
+ EventID id.EventID
TxnID string
- Relation mautrix.RelatesTo
- Type mautrix.MessageType
- SenderID string
+ Relation event.RelatesTo
+ Type event.MessageType
+ SenderID id.UserID
SenderName string
DefaultSenderColor tcell.Color
Timestamp time.Time
- State event.OutgoingState
+ State muksevt.OutgoingState
IsHighlight bool
IsService bool
IsSelected bool
Edited bool
- Event *event.Event
+ Event *muksevt.Event
ReplyTo *UIMessage
Reactions ReactionSlice
Renderer MessageRenderer
}
-func (msg *UIMessage) GetEvent() *event.Event {
+func (msg *UIMessage) GetEvent() *muksevt.Event {
if msg == nil {
return nil
}
@@ -93,10 +94,10 @@ func (msg *UIMessage) GetEvent() *event.Event {
const DateFormat = "January _2, 2006"
const TimeFormat = "15:04:05"
-func newUIMessage(evt *event.Event, displayname string, renderer MessageRenderer) *UIMessage {
+func newUIMessage(evt *muksevt.Event, displayname string, renderer MessageRenderer) *UIMessage {
msgtype := evt.Content.MsgType
if len(msgtype) == 0 {
- msgtype = mautrix.MessageType(evt.Type.String())
+ msgtype = event.MessageType(evt.Type.String())
}
reactions := make(ReactionSlice, 0, len(evt.Unsigned.Relations.Annotations.Map))
@@ -161,9 +162,9 @@ func unixToTime(unix int64) time.Time {
// In any other case, the sender is the display name of the user who sent the message.
func (msg *UIMessage) Sender() string {
switch msg.State {
- case event.StateLocalEcho:
+ case muksevt.StateLocalEcho:
return "Sending..."
- case event.StateSendFail:
+ case muksevt.StateSendFail:
return "Error"
}
switch msg.Type {
@@ -185,11 +186,11 @@ func (msg *UIMessage) NotificationContent() string {
func (msg *UIMessage) getStateSpecificColor() tcell.Color {
switch msg.State {
- case event.StateLocalEcho:
+ case muksevt.StateLocalEcho:
return tcell.ColorGray
- case event.StateSendFail:
+ case muksevt.StateSendFail:
return tcell.ColorRed
- case event.StateDefault:
+ case muksevt.StateDefault:
fallthrough
default:
return tcell.ColorDefault
@@ -286,14 +287,14 @@ func (msg *UIMessage) SameDate(message *UIMessage) bool {
return day1 == day2 && month1 == month2 && year1 == year2
}
-func (msg *UIMessage) ID() string {
+func (msg *UIMessage) ID() id.EventID {
if len(msg.EventID) == 0 {
- return msg.TxnID
+ return id.EventID(msg.TxnID)
}
return msg.EventID
}
-func (msg *UIMessage) SetID(id string) {
+func (msg *UIMessage) SetID(id id.EventID) {
msg.EventID = id
}
diff --git a/ui/messages/expandedtextmessage.go b/ui/messages/expandedtextmessage.go
index bd5aba9..5c9b5bd 100644
--- a/ui/messages/expandedtextmessage.go
+++ b/ui/messages/expandedtextmessage.go
@@ -20,7 +20,7 @@ import (
"fmt"
"time"
- "maunium.net/go/gomuks/matrix/event"
+ "maunium.net/go/gomuks/matrix/muksevt"
"maunium.net/go/mauview"
"maunium.net/go/tcell"
@@ -34,7 +34,7 @@ type ExpandedTextMessage struct {
}
// NewExpandedTextMessage creates a new ExpandedTextMessage object with the provided values and the default state.
-func NewExpandedTextMessage(evt *event.Event, displayname string, text tstring.TString) *UIMessage {
+func NewExpandedTextMessage(evt *muksevt.Event, displayname string, text tstring.TString) *UIMessage {
return newUIMessage(evt, displayname, &ExpandedTextMessage{
Text: text,
})
diff --git a/ui/messages/filemessage.go b/ui/messages/filemessage.go
index daf6c00..baffd0f 100644
--- a/ui/messages/filemessage.go
+++ b/ui/messages/filemessage.go
@@ -22,8 +22,9 @@ import (
"image"
"image/color"
- "maunium.net/go/gomuks/matrix/event"
- "maunium.net/go/mautrix"
+ "maunium.net/go/gomuks/matrix/muksevt"
+ "maunium.net/go/mautrix/event"
+ "maunium.net/go/mautrix/id"
"maunium.net/go/mauview"
"maunium.net/go/tcell"
@@ -35,10 +36,10 @@ import (
)
type FileMessage struct {
- Type mautrix.MessageType
+ Type event.MessageType
Body string
- URL mautrix.ContentURI
- Thumbnail mautrix.ContentURI
+ URL id.ContentURI
+ Thumbnail id.ContentURI
imageData []byte
buffer []tstring.TString
@@ -46,9 +47,9 @@ type FileMessage struct {
}
// NewFileMessage creates a new FileMessage object with the provided values and the default state.
-func NewFileMessage(matrix ifc.MatrixContainer, evt *event.Event, displayname string) *UIMessage {
- url, _ := mautrix.ParseContentURI(evt.Content.URL)
- thumbnail, _ := mautrix.ParseContentURI(evt.Content.GetInfo().ThumbnailURL)
+func NewFileMessage(matrix ifc.MatrixContainer, evt *muksevt.Event, displayname string) *UIMessage {
+ url, _ := evt.Content.URL.Parse()
+ thumbnail, _ := evt.Content.GetInfo().ThumbnailURL.Parse()
return newUIMessage(evt, displayname, &FileMessage{
Type: evt.Content.MsgType,
Body: evt.Content.Body,
@@ -72,13 +73,13 @@ func (msg *FileMessage) Clone() MessageRenderer {
func (msg *FileMessage) NotificationContent() string {
switch msg.Type {
- case mautrix.MsgImage:
+ case event.MsgImage:
return "Sent an image"
- case mautrix.MsgAudio:
+ case event.MsgAudio:
return "Sent an audio file"
- case mautrix.MsgVideo:
+ case event.MsgVideo:
return "Sent a video"
- case mautrix.MsgFile:
+ case event.MsgFile:
fallthrough
default:
return "Sent a file"
@@ -96,7 +97,7 @@ func (msg *FileMessage) String() string {
func (msg *FileMessage) DownloadPreview() {
url := msg.Thumbnail
if url.IsEmpty() {
- if msg.Type == mautrix.MsgImage && !msg.URL.IsEmpty() {
+ if msg.Type == event.MsgImage && !msg.URL.IsEmpty() {
msg.Thumbnail = msg.URL
url = msg.Thumbnail
} else {
diff --git a/ui/messages/html/parser.go b/ui/messages/html/parser.go
index 99f9c29..86b501d 100644
--- a/ui/messages/html/parser.go
+++ b/ui/messages/html/parser.go
@@ -27,8 +27,9 @@ import (
"github.com/lucasb-eyer/go-colorful"
"golang.org/x/net/html"
- "maunium.net/go/gomuks/matrix/event"
- "maunium.net/go/mautrix"
+ "maunium.net/go/gomuks/matrix/muksevt"
+ "maunium.net/go/mautrix/event"
+ "maunium.net/go/mautrix/id"
"maunium.net/go/tcell"
"maunium.net/go/gomuks/matrix/rooms"
@@ -185,12 +186,12 @@ func (parser *htmlParser) linkToEntity(node *html.Node) Entity {
pillTarget := match[1]
text := NewTextEntity(pillTarget)
if pillTarget[0] == '@' {
- if member := parser.room.GetMember(pillTarget); member != nil {
+ if member := parser.room.GetMember(id.UserID(pillTarget)); member != nil {
text.Text = member.Displayname
text.Style = text.Style.Foreground(widget.GetHashColor(pillTarget))
}
entity.Children = []Entity{text}
- /*} else if slash := strings.IndexRune(pillTarget, '/'); slash != -1 {
+ /*} else if slash := strings.IndexRune(pillTarget, '/'); slash != -1 {
room := pillTarget[:slash]
event := pillTarget[slash+1:]*/
} else if pillTarget[0] == '#' {
@@ -383,9 +384,9 @@ 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 *event.Event, senderDisplayname string) Entity {
+func Parse(room *rooms.Room, evt *muksevt.Event, senderDisplayname string) Entity {
htmlData := evt.Content.FormattedBody
- if evt.Content.Format != mautrix.FormatHTML {
+ if evt.Content.Format != event.FormatHTML {
htmlData = strings.Replace(html.EscapeString(evt.Content.Body), "\n", "<br/>", -1)
}
htmlData = strings.Replace(htmlData, "\t", strings.Repeat(" ", TabLength), -1)
@@ -402,7 +403,7 @@ func Parse(room *rooms.Room, evt *event.Event, senderDisplayname string) Entity
}
}
- if evt.Content.MsgType == mautrix.MsgEmote {
+ if evt.Content.MsgType == event.MsgEmote {
root = &ContainerEntity{
BaseEntity: &BaseEntity{
Tag: "emote",
diff --git a/ui/messages/htmlmessage.go b/ui/messages/htmlmessage.go
index af3ce41..cc206fd 100644
--- a/ui/messages/htmlmessage.go
+++ b/ui/messages/htmlmessage.go
@@ -17,7 +17,7 @@
package messages
import (
- "maunium.net/go/gomuks/matrix/event"
+ "maunium.net/go/gomuks/matrix/muksevt"
"maunium.net/go/mauview"
"maunium.net/go/tcell"
@@ -32,7 +32,7 @@ type HTMLMessage struct {
focused bool
}
-func NewHTMLMessage(evt *event.Event, displayname string, root html.Entity) *UIMessage {
+func NewHTMLMessage(evt *muksevt.Event, displayname string, root html.Entity) *UIMessage {
return newUIMessage(evt, displayname, &HTMLMessage{
Root: root,
})
diff --git a/ui/messages/parser.go b/ui/messages/parser.go
index d0bc6e0..d89bcb9 100644
--- a/ui/messages/parser.go
+++ b/ui/messages/parser.go
@@ -20,8 +20,9 @@ import (
"fmt"
"strings"
- "maunium.net/go/gomuks/matrix/event"
- "maunium.net/go/mautrix"
+ "maunium.net/go/gomuks/matrix/muksevt"
+ "maunium.net/go/mautrix/event"
+ "maunium.net/go/mautrix/id"
"maunium.net/go/tcell"
"maunium.net/go/gomuks/interface"
@@ -31,7 +32,7 @@ import (
"maunium.net/go/gomuks/ui/widget"
)
-func getCachedEvent(mainView ifc.MainView, roomID, eventID string) *UIMessage {
+func getCachedEvent(mainView ifc.MainView, roomID id.RoomID, eventID id.EventID) *UIMessage {
if roomView := mainView.GetRoom(roomID); roomView != nil {
if replyToIfcMsg := roomView.GetEvent(eventID); replyToIfcMsg != nil {
if replyToMsg, ok := replyToIfcMsg.(*UIMessage); ok && replyToMsg != nil {
@@ -42,7 +43,7 @@ func getCachedEvent(mainView ifc.MainView, roomID, eventID string) *UIMessage {
return nil
}
-func ParseEvent(matrix ifc.MatrixContainer, mainView ifc.MainView, room *rooms.Room, evt *event.Event) *UIMessage {
+func ParseEvent(matrix ifc.MatrixContainer, mainView ifc.MainView, room *rooms.Room, evt *muksevt.Event) *UIMessage {
msg := directParseEvent(matrix, room, evt)
if msg == nil {
return nil
@@ -64,36 +65,36 @@ func ParseEvent(matrix ifc.MatrixContainer, mainView ifc.MainView, room *rooms.R
return msg
}
-func directParseEvent(matrix ifc.MatrixContainer, room *rooms.Room, evt *event.Event) *UIMessage {
- displayname := evt.Sender
+func directParseEvent(matrix ifc.MatrixContainer, room *rooms.Room, evt *muksevt.Event) *UIMessage {
+ displayname := string(evt.Sender)
member := room.GetMember(evt.Sender)
if member != nil {
displayname = member.Displayname
}
- if evt.Unsigned.RedactedBecause != nil || evt.Type == mautrix.EventRedaction {
+ if evt.Unsigned.RedactedBecause != nil || evt.Type == event.EventRedaction {
return NewRedactedMessage(evt, displayname)
}
switch evt.Type {
- case mautrix.EventSticker:
- evt.Content.MsgType = mautrix.MsgImage
+ case event.EventSticker:
+ evt.Content.MsgType = event.MsgImage
fallthrough
- case mautrix.EventMessage:
+ case event.EventMessage:
return ParseMessage(matrix, room, evt, displayname)
- case mautrix.EventEncrypted:
+ case event.EventEncrypted:
return NewExpandedTextMessage(evt, displayname, tstring.NewStyleTString("Encrypted messages are not yet supported", tcell.StyleDefault.Italic(true)))
- case mautrix.StateTopic, mautrix.StateRoomName, mautrix.StateAliases, mautrix.StateCanonicalAlias:
+ case event.StateTopic, event.StateRoomName, event.StateAliases, event.StateCanonicalAlias:
return ParseStateEvent(evt, displayname)
- case mautrix.StateMember:
+ case event.StateMember:
return ParseMembershipEvent(room, evt)
}
return nil
}
-func ParseStateEvent(evt *event.Event, displayname string) *UIMessage {
+func ParseStateEvent(evt *muksevt.Event, displayname string) *UIMessage {
text := tstring.NewColorTString(displayname, widget.GetHashColor(evt.Sender))
switch evt.Type {
- case mautrix.StateTopic:
+ case event.StateTopic:
if len(evt.Content.Topic) == 0 {
text = text.AppendColor(" removed the topic.", tcell.ColorGreen)
} else {
@@ -101,7 +102,7 @@ func ParseStateEvent(evt *event.Event, displayname string) *UIMessage {
AppendStyle(evt.Content.Topic, tcell.StyleDefault.Underline(true)).
AppendColor(".", tcell.ColorGreen)
}
- case mautrix.StateRoomName:
+ case event.StateRoomName:
if len(evt.Content.Name) == 0 {
text = text.AppendColor(" removed the room name.", tcell.ColorGreen)
} else {
@@ -109,21 +110,21 @@ func ParseStateEvent(evt *event.Event, displayname string) *UIMessage {
AppendStyle(evt.Content.Name, tcell.StyleDefault.Underline(true)).
AppendColor(".", tcell.ColorGreen)
}
- case mautrix.StateCanonicalAlias:
+ case event.StateCanonicalAlias:
if len(evt.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(evt.Content.Alias, tcell.StyleDefault.Underline(true)).
+ AppendStyle(string(evt.Content.Alias), tcell.StyleDefault.Underline(true)).
AppendColor(".", tcell.ColorGreen)
}
- case mautrix.StateAliases:
- text = ParseAliasEvent(evt, displayname)
+ //case event.StateAliases:
+ // text = ParseAliasEvent(evt, displayname)
}
return NewExpandedTextMessage(evt, displayname, text)
}
-func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *event.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()
}
@@ -131,13 +132,13 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *event.Event
evt.Content = *evt.Gomuks.Edits[len(evt.Gomuks.Edits)-1].Content.NewContent
}
switch evt.Content.MsgType {
- case mautrix.MsgText, mautrix.MsgNotice, mautrix.MsgEmote:
- if evt.Content.Format == mautrix.FormatHTML {
+ case event.MsgText, event.MsgNotice, event.MsgEmote:
+ if evt.Content.Format == event.FormatHTML {
return NewHTMLMessage(evt, displayname, html.Parse(room, evt, displayname))
}
evt.Content.Body = strings.Replace(evt.Content.Body, "\t", " ", -1)
return NewTextMessage(evt, displayname, evt.Content.Body)
- case mautrix.MsgImage, mautrix.MsgVideo, mautrix.MsgAudio, mautrix.MsgFile:
+ case event.MsgImage, event.MsgVideo, event.MsgAudio, event.MsgFile:
msg := NewFileMessage(matrix, evt, displayname)
if !matrix.Preferences().DisableDownloads {
renderer := msg.Renderer.(*FileMessage)
@@ -148,54 +149,54 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *event.Event
return nil
}
-func getMembershipChangeMessage(evt *event.Event, membership, prevMembership mautrix.Membership, senderDisplayname, displayname, prevDisplayname string) (sender string, text tstring.TString) {
+func getMembershipChangeMessage(evt *muksevt.Event, membership, prevMembership event.Membership, senderDisplayname, displayname, prevDisplayname string) (sender string, text tstring.TString) {
switch membership {
case "invite":
sender = "---"
text = tstring.NewColorTString(fmt.Sprintf("%s invited %s.", senderDisplayname, displayname), tcell.ColorGreen)
text.Colorize(0, len(senderDisplayname), widget.GetHashColor(evt.Sender))
- text.Colorize(len(senderDisplayname)+len(" invited "), len(displayname), widget.GetHashColor(*evt.StateKey))
+ text.Colorize(len(senderDisplayname)+len(" invited "), len(displayname), widget.GetHashColor(evt.StateKey))
case "join":
sender = "-->"
- if prevMembership == mautrix.MembershipInvite {
+ if prevMembership == event.MembershipInvite {
text = tstring.NewColorTString(fmt.Sprintf("%s accepted the invite.", displayname), tcell.ColorGreen)
} else {
text = tstring.NewColorTString(fmt.Sprintf("%s joined the room.", displayname), tcell.ColorGreen)
}
- text.Colorize(0, len(displayname), widget.GetHashColor(*evt.StateKey))
+ text.Colorize(0, len(displayname), widget.GetHashColor(evt.StateKey))
case "leave":
sender = "<--"
- if evt.Sender != *evt.StateKey {
- if prevMembership == mautrix.MembershipBan {
+ if evt.Sender != id.UserID(*evt.StateKey) {
+ if prevMembership == event.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))
+ 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.Colorize(len(senderDisplayname)+len(" kicked "), len(displayname), widget.GetHashColor(*evt.StateKey))
+ text.Colorize(len(senderDisplayname)+len(" kicked "), len(displayname), widget.GetHashColor(evt.StateKey))
}
text.Colorize(0, len(senderDisplayname), widget.GetHashColor(evt.Sender))
} else {
if displayname == *evt.StateKey {
displayname = prevDisplayname
}
- if prevMembership == mautrix.MembershipInvite {
+ if prevMembership == event.MembershipInvite {
text = tstring.NewColorTString(fmt.Sprintf("%s rejected the invite.", displayname), tcell.ColorRed)
} else {
text = tstring.NewColorTString(fmt.Sprintf("%s left the room.", displayname), tcell.ColorRed)
}
- text.Colorize(0, len(displayname), widget.GetHashColor(*evt.StateKey))
+ 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.Colorize(len(senderDisplayname)+len(" banned "), len(displayname), widget.GetHashColor(*evt.StateKey))
+ text.Colorize(len(senderDisplayname)+len(" banned "), len(displayname), widget.GetHashColor(evt.StateKey))
text.Colorize(0, len(senderDisplayname), widget.GetHashColor(evt.Sender))
}
return
}
-func getMembershipEventContent(room *rooms.Room, evt *event.Event) (sender string, text tstring.TString) {
+func getMembershipEventContent(room *rooms.Room, evt *muksevt.Event) (sender string, text tstring.TString) {
member := room.GetMember(evt.Sender)
- senderDisplayname := evt.Sender
+ senderDisplayname := string(evt.Sender)
if member != nil {
senderDisplayname = member.Displayname
}
@@ -206,7 +207,7 @@ func getMembershipEventContent(room *rooms.Room, evt *event.Event) (sender strin
displayname = *evt.StateKey
}
- prevMembership := mautrix.MembershipLeave
+ prevMembership := event.MembershipLeave
prevDisplayname := *evt.StateKey
if evt.Unsigned.PrevContent != nil {
prevMembership = evt.Unsigned.PrevContent.Membership
@@ -220,7 +221,7 @@ func getMembershipEventContent(room *rooms.Room, evt *event.Event) (sender strin
sender, text = getMembershipChangeMessage(evt, membership, prevMembership, senderDisplayname, displayname, prevDisplayname)
} else if displayname != prevDisplayname {
sender = "---"
- color := widget.GetHashColor(*evt.StateKey)
+ color := widget.GetHashColor(evt.StateKey)
text = tstring.NewBlankTString().
AppendColor(prevDisplayname, color).
AppendColor(" changed their display name to ", tcell.ColorGreen).
@@ -230,7 +231,7 @@ func getMembershipEventContent(room *rooms.Room, evt *event.Event) (sender strin
return
}
-func ParseMembershipEvent(room *rooms.Room, evt *event.Event) *UIMessage {
+func ParseMembershipEvent(room *rooms.Room, evt *muksevt.Event) *UIMessage {
displayname, text := getMembershipEventContent(room, evt)
if len(text) == 0 {
return nil
@@ -239,65 +240,65 @@ func ParseMembershipEvent(room *rooms.Room, evt *event.Event) *UIMessage {
return NewExpandedTextMessage(evt, displayname, text)
}
-func ParseAliasEvent(evt *event.Event, displayname string) tstring.TString {
- var prevAliases []string
- if evt.Unsigned.PrevContent != nil {
- prevAliases = evt.Unsigned.PrevContent.Aliases
- }
- aliases := evt.Content.Aliases
- var added, removed []tstring.TString
-Outer1:
- for _, oldAlias := range prevAliases {
- for _, newAlias := range aliases {
- if oldAlias == newAlias {
- continue Outer1
- }
- }
- removed = append(removed, tstring.NewStyleTString(oldAlias, tcell.StyleDefault.Foreground(widget.GetHashColor(oldAlias)).Underline(true)))
- }
-Outer2:
- for _, newAlias := range aliases {
- for _, oldAlias := range prevAliases {
- if oldAlias == newAlias {
- continue Outer2
- }
- }
- added = append(added, tstring.NewStyleTString(newAlias, tcell.StyleDefault.Foreground(widget.GetHashColor(newAlias)).Underline(true)))
- }
- var addedStr, removedStr tstring.TString
- if len(added) == 1 {
- addedStr = added[0]
- } else if len(added) > 1 {
- addedStr = tstring.
- Join(added[:len(added)-1], ", ").
- Append(" and ").
- AppendTString(added[len(added)-1])
- }
- if len(removed) == 1 {
- removedStr = removed[0]
- } else if len(removed) > 1 {
- removedStr = tstring.
- Join(removed[:len(removed)-1], ", ").
- Append(" and ").
- AppendTString(removed[len(removed)-1])
- }
- text := tstring.NewBlankTString()
- if len(addedStr) > 0 && len(removedStr) > 0 {
- text = text.AppendColor(fmt.Sprintf("%s added ", displayname), tcell.ColorGreen).
- AppendTString(addedStr).
- AppendColor(" and removed ", tcell.ColorGreen).
- AppendTString(removedStr).
- AppendColor(" as addresses for this room.", tcell.ColorGreen)
- } else if len(addedStr) > 0 {
- text = text.AppendColor(fmt.Sprintf("%s added ", displayname), tcell.ColorGreen).
- AppendTString(addedStr).
- AppendColor(" as addresses for this room.", tcell.ColorGreen)
- } else if len(removedStr) > 0 {
- text = text.AppendColor(fmt.Sprintf("%s removed ", displayname), tcell.ColorGreen).
- AppendTString(removedStr).
- AppendColor(" as addresses for this room.", tcell.ColorGreen)
- } else {
- return nil
- }
- return text
-}
+//func ParseAliasEvent(evt *muksevt.Event, displayname string) tstring.TString {
+// var prevAliases []string
+// if evt.Unsigned.PrevContent != nil {
+// prevAliases = evt.Unsigned.PrevContent.Aliases
+// }
+// aliases := evt.Content.Aliases
+// var added, removed []tstring.TString
+//Outer1:
+// for _, oldAlias := range prevAliases {
+// for _, newAlias := range aliases {
+// if oldAlias == newAlias {
+// continue Outer1
+// }
+// }
+// removed = append(removed, tstring.NewStyleTString(oldAlias, tcell.StyleDefault.Foreground(widget.GetHashColor(oldAlias)).Underline(true)))
+// }
+//Outer2:
+// for _, newAlias := range aliases {
+// for _, oldAlias := range prevAliases {
+// if oldAlias == newAlias {
+// continue Outer2
+// }
+// }
+// added = append(added, tstring.NewStyleTString(newAlias, tcell.StyleDefault.Foreground(widget.GetHashColor(newAlias)).Underline(true)))
+// }
+// var addedStr, removedStr tstring.TString
+// if len(added) == 1 {
+// addedStr = added[0]
+// } else if len(added) > 1 {
+// addedStr = tstring.
+// Join(added[:len(added)-1], ", ").
+// Append(" and ").
+// AppendTString(added[len(added)-1])
+// }
+// if len(removed) == 1 {
+// removedStr = removed[0]
+// } else if len(removed) > 1 {
+// removedStr = tstring.
+// Join(removed[:len(removed)-1], ", ").
+// Append(" and ").
+// AppendTString(removed[len(removed)-1])
+// }
+// text := tstring.NewBlankTString()
+// if len(addedStr) > 0 && len(removedStr) > 0 {
+// text = text.AppendColor(fmt.Sprintf("%s added ", displayname), tcell.ColorGreen).
+// AppendTString(addedStr).
+// AppendColor(" and removed ", tcell.ColorGreen).
+// AppendTString(removedStr).
+// AppendColor(" as addresses for this room.", tcell.ColorGreen)
+// } else if len(addedStr) > 0 {
+// text = text.AppendColor(fmt.Sprintf("%s added ", displayname), tcell.ColorGreen).
+// AppendTString(addedStr).
+// AppendColor(" as addresses for this room.", tcell.ColorGreen)
+// } else if len(removedStr) > 0 {
+// text = text.AppendColor(fmt.Sprintf("%s removed ", displayname), tcell.ColorGreen).
+// AppendTString(removedStr).
+// AppendColor(" as addresses for this room.", tcell.ColorGreen)
+// } else {
+// return nil
+// }
+// return text
+//}
diff --git a/ui/messages/redactedmessage.go b/ui/messages/redactedmessage.go
index 34d880b..ac79008 100644
--- a/ui/messages/redactedmessage.go
+++ b/ui/messages/redactedmessage.go
@@ -17,7 +17,7 @@
package messages
import (
- "maunium.net/go/gomuks/matrix/event"
+ "maunium.net/go/gomuks/matrix/muksevt"
"maunium.net/go/mauview"
"maunium.net/go/tcell"
@@ -26,7 +26,7 @@ import (
type RedactedMessage struct{}
-func NewRedactedMessage(evt *event.Event, displayname string) *UIMessage {
+func NewRedactedMessage(evt *muksevt.Event, displayname string) *UIMessage {
return newUIMessage(evt, displayname, &RedactedMessage{})
}
diff --git a/ui/messages/textmessage.go b/ui/messages/textmessage.go
index 2e59c8f..cf3b590 100644
--- a/ui/messages/textmessage.go
+++ b/ui/messages/textmessage.go
@@ -20,7 +20,7 @@ import (
"fmt"
"time"
- "maunium.net/go/gomuks/matrix/event"
+ "maunium.net/go/gomuks/matrix/muksevt"
"maunium.net/go/mauview"
"maunium.net/go/gomuks/config"
@@ -35,7 +35,7 @@ type TextMessage struct {
}
// NewTextMessage creates a new UITextMessage object with the provided values and the default state.
-func NewTextMessage(evt *event.Event, displayname string, text string) *UIMessage {
+func NewTextMessage(evt *muksevt.Event, displayname string, text string) *UIMessage {
return newUIMessage(evt, displayname, &TextMessage{
Text: text,
})
diff --git a/ui/room-list.go b/ui/room-list.go
index df986fe..3169bba 100644
--- a/ui/room-list.go
+++ b/ui/room-list.go
@@ -24,6 +24,7 @@ import (
sync "github.com/sasha-s/go-deadlock"
+ "maunium.net/go/mautrix/id"
"maunium.net/go/mauview"
"maunium.net/go/tcell"
@@ -105,7 +106,7 @@ func NewRoomList(parent *MainView) *RoomList {
return list
}
-func (list *RoomList) Contains(roomID string) bool {
+func (list *RoomList) Contains(roomID id.RoomID) bool {
list.RLock()
defer list.RUnlock()
for _, trl := range list.items {
diff --git a/ui/room-view.go b/ui/room-view.go
index 3a1d3cb..8408e25 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -26,18 +26,19 @@ import (
"github.com/kyokomi/emoji"
"github.com/mattn/go-runewidth"
- "maunium.net/go/gomuks/debug"
- "maunium.net/go/gomuks/lib/open"
- "maunium.net/go/gomuks/matrix/event"
-
"maunium.net/go/mauview"
+ "maunium.net/go/tcell"
"maunium.net/go/mautrix"
- "maunium.net/go/tcell"
+ "maunium.net/go/mautrix/event"
+ "maunium.net/go/mautrix/id"
"maunium.net/go/gomuks/config"
+ "maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/interface"
+ "maunium.net/go/gomuks/lib/open"
"maunium.net/go/gomuks/lib/util"
+ "maunium.net/go/gomuks/matrix/muksevt"
"maunium.net/go/gomuks/matrix/rooms"
"maunium.net/go/gomuks/ui/messages"
"maunium.net/go/gomuks/ui/widget"
@@ -72,9 +73,9 @@ type RoomView struct {
selectReason SelectReason
selectContent string
- replying *event.Event
+ replying *muksevt.Event
- editing *event.Event
+ editing *muksevt.Event
editMoveText string
completions struct {
@@ -186,7 +187,7 @@ func (view *RoomView) OnSelect(message *messages.UIMessage) {
case SelectReply:
view.replying = message.Event
if len(view.selectContent) > 0 {
- go view.SendMessage(mautrix.MsgText, view.selectContent)
+ go view.SendMessage(event.MsgText, view.selectContent)
}
case SelectReact:
go view.SendReaction(message.EventID, view.selectContent)
@@ -217,7 +218,7 @@ func (view *RoomView) GetStatus() string {
buf.WriteString("Editing message - ")
} else if view.replying != nil {
buf.WriteString("Replying to ")
- buf.WriteString(view.replying.Sender)
+ buf.WriteString(string(view.replying.Sender))
buf.WriteString(" - ")
} else if view.selecting {
buf.WriteString("Selecting message to ")
@@ -235,12 +236,19 @@ func (view *RoomView) GetStatus() string {
}
if len(view.typing) == 1 {
- buf.WriteString("Typing: " + view.typing[0])
+ buf.WriteString("Typing: " + string(view.typing[0]))
buf.WriteString(" - ")
} else if len(view.typing) > 1 {
- _, _ = fmt.Fprintf(&buf,
- "Typing: %s and %s - ",
- strings.Join(view.typing[:len(view.typing)-1], ", "), view.typing[len(view.typing)-1])
+ buf.WriteString("Typing: ")
+ for i, userID := range view.typing {
+ if i == len(view.typing)-1 {
+ buf.WriteString(" and ")
+ } else if i > 0 {
+ buf.WriteString(", ")
+ }
+ buf.WriteString(string(userID))
+ }
+ buf.WriteString(" - ")
}
return strings.TrimSuffix(buf.String(), " - ")
@@ -384,15 +392,18 @@ func (view *RoomView) SetCompletions(completions []string) {
func (view *RoomView) loadTyping() {
for index, user := range view.typing {
- member := view.Room.GetMember(user)
+ member := view.Room.GetMember(id.UserID(user))
if member != nil {
view.typing[index] = member.Displayname
}
}
}
-func (view *RoomView) SetTyping(users []string) {
- view.typing = users
+func (view *RoomView) SetTyping(users []id.UserID) {
+ view.typing = make([]string, len(users))
+ for i, user := range users {
+ view.typing[i] = string(user)
+ }
if view.Room.Loaded() {
view.loadTyping()
}
@@ -406,13 +417,13 @@ type completion struct {
func (view *RoomView) autocompleteUser(existingText string) (completions []completion) {
textWithoutPrefix := strings.TrimPrefix(existingText, "@")
for userID, user := range view.Room.GetMembers() {
- if user.Displayname == textWithoutPrefix || userID == existingText {
+ if user.Displayname == textWithoutPrefix || string(userID) == existingText {
// Exact match, return that.
- return []completion{{user.Displayname, userID}}
+ return []completion{{user.Displayname, string(userID)}}
}
- if strings.HasPrefix(user.Displayname, textWithoutPrefix) || strings.HasPrefix(userID, existingText) {
- completions = append(completions, completion{user.Displayname, userID})
+ if strings.HasPrefix(user.Displayname, textWithoutPrefix) || strings.HasPrefix(string(userID), existingText) {
+ completions = append(completions, completion{user.Displayname, string(userID)})
}
}
return
@@ -420,13 +431,13 @@ func (view *RoomView) autocompleteUser(existingText string) (completions []compl
func (view *RoomView) autocompleteRoom(existingText string) (completions []completion) {
for _, room := range view.parent.rooms {
- alias := room.Room.GetCanonicalAlias()
+ alias := string(room.Room.GetCanonicalAlias())
if alias == existingText {
// Exact match, return that.
- return []completion{{alias, room.Room.ID}}
+ return []completion{{alias, string(room.Room.ID)}}
}
if strings.HasPrefix(alias, existingText) {
- completions = append(completions, completion{alias, room.Room.ID})
+ completions = append(completions, completion{alias, string(room.Room.ID)})
continue
}
}
@@ -457,7 +468,7 @@ func (view *RoomView) autocompleteEmoji(word string) (completions []string) {
return
}
-func (view *RoomView) SetEditing(evt *event.Event) {
+func (view *RoomView) SetEditing(evt *muksevt.Event) {
if evt == nil {
view.editing = nil
view.SetInputText(view.editMoveText)
@@ -470,7 +481,7 @@ func (view *RoomView) SetEditing(evt *event.Event) {
// 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 == mautrix.MsgEmote {
+ if view.editing.Content.MsgType == event.MsgEmote {
text = "/me " + text
}
view.input.SetText(text)
@@ -479,21 +490,21 @@ func (view *RoomView) SetEditing(evt *event.Event) {
view.input.SetCursorOffset(-1)
}
-type findFilter func(evt *event.Event) bool
+type findFilter func(evt *muksevt.Event) bool
-func (view *RoomView) filterOwnOnly(evt *event.Event) bool {
- return evt.Sender == view.parent.matrix.Client().UserID && evt.Type == mautrix.EventMessage
+func (view *RoomView) filterOwnOnly(evt *muksevt.Event) bool {
+ return evt.Sender == view.parent.matrix.Client().UserID && evt.Type == event.EventMessage
}
-func (view *RoomView) filterMediaOnly(evt *event.Event) bool {
- return evt.Type == mautrix.EventMessage && (
- evt.Content.MsgType == mautrix.MsgFile ||
- evt.Content.MsgType == mautrix.MsgImage ||
- evt.Content.MsgType == mautrix.MsgAudio ||
- evt.Content.MsgType == mautrix.MsgVideo)
+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)
}
-func (view *RoomView) findMessage(current *event.Event, forward bool, allow findFilter) *messages.UIMessage {
+func (view *RoomView) findMessage(current *muksevt.Event, forward bool, allow findFilter) *messages.UIMessage {
currentFound := current == nil
msgs := view.MessageView().messages
for i := 0; i < len(msgs); i++ {
@@ -502,7 +513,7 @@ func (view *RoomView) findMessage(current *event.Event, forward bool, allow find
index = len(msgs) - i - 1
}
evt := msgs[index]
- if evt.EventID == "" || evt.EventID == evt.TxnID || evt.IsService {
+ if evt.EventID == "" || string(evt.EventID) == evt.TxnID || evt.IsService {
continue
} else if currentFound {
if allow == nil || allow(evt.Event) {
@@ -607,13 +618,13 @@ func (view *RoomView) InputSubmit(text string) {
} else if cmd := view.parent.cmdProcessor.ParseCommand(view, text); cmd != nil {
go view.parent.cmdProcessor.HandleCommand(cmd)
} else {
- go view.SendMessage(mautrix.MsgText, text)
+ go view.SendMessage(event.MsgText, text)
}
view.editMoveText = ""
view.SetInputText("")
}
-func (view *RoomView) Download(url mautrix.ContentURI, filename string, openFile bool) {
+func (view *RoomView) Download(url id.ContentURI, filename string, openFile bool) {
path, err := view.parent.matrix.DownloadToDisk(url, filename)
if err != nil {
view.AddServiceMessage(fmt.Sprintf("Failed to download media: %v", err))
@@ -627,7 +638,7 @@ func (view *RoomView) Download(url mautrix.ContentURI, filename string, openFile
}
}
-func (view *RoomView) Redact(eventID, reason string) {
+func (view *RoomView) Redact(eventID id.EventID, reason string) {
defer debug.Recover()
err := view.parent.matrix.Redact(view.Room.ID, eventID, reason)
if err != nil {
@@ -642,16 +653,16 @@ func (view *RoomView) Redact(eventID, reason string) {
}
}
-func (view *RoomView) SendReaction(eventID string, reaction string) {
+func (view *RoomView) SendReaction(eventID id.EventID, reaction string) {
defer debug.Recover()
debug.Print("Reacting to", eventID, "in", view.Room.ID, "with", reaction)
- eventID, err := view.parent.matrix.SendEvent(&event.Event{
- Event: &mautrix.Event{
- Type: mautrix.EventReaction,
+ eventID, err := view.parent.matrix.SendEvent(&muksevt.Event{
+ Event: &event.Event{
+ Type: event.EventReaction,
RoomID: view.Room.ID,
- Content: mautrix.Content{
- RelatesTo: &mautrix.RelatesTo{
- Type: mautrix.RelAnnotation,
+ Content: event.Content{
+ RelatesTo: &event.RelatesTo{
+ Type: event.RelAnnotation,
EventID: eventID,
Key: reaction,
},
@@ -670,11 +681,11 @@ func (view *RoomView) SendReaction(eventID string, reaction string) {
}
}
-func (view *RoomView) SendMessage(msgtype mautrix.MessageType, text string) {
+func (view *RoomView) SendMessage(msgtype event.MessageType, text string) {
view.SendMessageHTML(msgtype, text, "")
}
-func (view *RoomView) SendMessageHTML(msgtype mautrix.MessageType, text, html string) {
+func (view *RoomView) SendMessageHTML(msgtype event.MessageType, text, html string) {
defer debug.Recover()
debug.Print("Sending message", msgtype, text, "to", view.Room.ID)
if !view.config.Preferences.DisableEmojis {
@@ -683,12 +694,12 @@ func (view *RoomView) SendMessageHTML(msgtype mautrix.MessageType, text, html st
var rel *ifc.Relation
if view.editing != nil {
rel = &ifc.Relation{
- Type: mautrix.RelReplace,
+ Type: event.RelReplace,
Event: view.editing,
}
} else if view.replying != nil {
rel = &ifc.Relation{
- Type: mautrix.RelReference,
+ Type: event.RelReference,
Event: view.replying,
}
}
@@ -699,7 +710,7 @@ func (view *RoomView) SendMessageHTML(msgtype mautrix.MessageType, text, html st
view.status.SetText(view.GetStatus())
eventID, err := view.parent.matrix.SendEvent(evt)
if err != nil {
- msg.State = event.StateSendFail
+ msg.State = muksevt.StateSendFail
// Show shorter version if available
if httpErr, ok := err.(mautrix.HTTPError); ok {
err = httpErr
@@ -712,7 +723,7 @@ func (view *RoomView) SendMessageHTML(msgtype mautrix.MessageType, text, html st
} else {
debug.Print("Event ID received:", eventID)
msg.EventID = eventID
- msg.State = event.StateDefault
+ msg.State = muksevt.StateDefault
view.MessageView().setMessageID(msg)
view.parent.parent.Render()
}
@@ -734,8 +745,8 @@ func (view *RoomView) Update() {
}
func (view *RoomView) UpdateUserList() {
- pls := &mautrix.PowerLevels{}
- if plEvent := view.Room.GetStateEvent(mautrix.StatePowerLevels, ""); plEvent != nil {
+ pls := &event.PowerLevels{}
+ if plEvent := view.Room.GetStateEvent(event.StatePowerLevels, ""); plEvent != nil {
pls = plEvent.Content.GetPowerLevels()
}
view.userList.Update(view.Room.GetMembers(), pls)
@@ -746,17 +757,17 @@ func (view *RoomView) AddServiceMessage(text string) {
view.content.AddMessage(messages.NewServiceMessage(text), AppendMessage)
}
-func (view *RoomView) parseEvent(evt *event.Event) *messages.UIMessage {
+func (view *RoomView) parseEvent(evt *muksevt.Event) *messages.UIMessage {
return messages.ParseEvent(view.parent.matrix, view.parent, view.Room, evt)
}
-func (view *RoomView) AddHistoryEvent(evt *event.Event) {
+func (view *RoomView) AddHistoryEvent(evt *muksevt.Event) {
if msg := view.parseEvent(evt); msg != nil {
view.content.AddMessage(msg, PrependMessage)
}
}
-func (view *RoomView) AddEvent(evt *event.Event) ifc.Message {
+func (view *RoomView) AddEvent(evt *muksevt.Event) ifc.Message {
if msg := view.parseEvent(evt); msg != nil {
view.content.AddMessage(msg, AppendMessage)
return msg
@@ -764,17 +775,17 @@ func (view *RoomView) AddEvent(evt *event.Event) ifc.Message {
return nil
}
-func (view *RoomView) AddRedaction(redactedEvt *event.Event) {
+func (view *RoomView) AddRedaction(redactedEvt *muksevt.Event) {
view.AddEvent(redactedEvt)
}
-func (view *RoomView) AddEdit(evt *event.Event) {
+func (view *RoomView) AddEdit(evt *muksevt.Event) {
if msg := view.parseEvent(evt); msg != nil {
view.content.AddMessage(msg, IgnoreMessage)
}
}
-func (view *RoomView) AddReaction(evt *event.Event, key string) {
+func (view *RoomView) AddReaction(evt *muksevt.Event, key string) {
msgView := view.MessageView()
msg := msgView.getMessageByID(evt.ID)
if msg == nil {
@@ -790,7 +801,7 @@ func (view *RoomView) AddReaction(evt *event.Event, key string) {
}
}
-func (view *RoomView) GetEvent(eventID string) ifc.Message {
+func (view *RoomView) GetEvent(eventID id.EventID) ifc.Message {
message, ok := view.content.messageIDs[eventID]
if !ok {
return nil
diff --git a/ui/view-login.go b/ui/view-login.go
index 9eb8226..d1cd4ee 100644
--- a/ui/view-login.go
+++ b/ui/view-login.go
@@ -19,6 +19,7 @@ package ui
import (
"math"
+ "maunium.net/go/mautrix/id"
"maunium.net/go/tcell"
"maunium.net/go/mautrix"
@@ -75,7 +76,7 @@ func (ui *GomuksUI) NewLoginView() mauview.Component {
hs := ui.gmx.Config().HS
view.homeserver.SetPlaceholder("https://example.com").SetText(hs)
- view.username.SetPlaceholder("@user:example.com").SetText(ui.gmx.Config().UserID)
+ view.username.SetPlaceholder("@user:example.com").SetText(string(ui.gmx.Config().UserID))
view.password.SetPlaceholder("correct horse battery staple").SetMaskCharacter('*')
view.quitButton.SetOnClick(func() { ui.gmx.Stop(true) }).SetBackgroundColor(tcell.ColorDarkCyan)
@@ -103,7 +104,7 @@ func (ui *GomuksUI) NewLoginView() mauview.Component {
}
func (view *LoginView) resolveWellKnown() {
- _, homeserver, err := mautrix.ParseUserID(view.username.GetText())
+ _, homeserver, err := id.UserID(view.username.GetText()).Parse()
if err != nil {
return
}
diff --git a/ui/view-main.go b/ui/view-main.go
index 870c98b..581e186 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -27,6 +27,7 @@ import (
sync "github.com/sasha-s/go-deadlock"
"maunium.net/go/gomuks/ui/messages"
+ "maunium.net/go/mautrix/id"
"maunium.net/go/mauview"
"maunium.net/go/tcell"
@@ -34,9 +35,9 @@ import (
"maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/interface"
"maunium.net/go/gomuks/lib/notification"
- "maunium.net/go/gomuks/matrix/pushrules"
"maunium.net/go/gomuks/matrix/rooms"
"maunium.net/go/gomuks/ui/widget"
+ "maunium.net/go/mautrix/pushrules"
)
type MainView struct {
@@ -45,7 +46,7 @@ type MainView struct {
roomList *RoomList
roomView *mauview.Box
currentRoom *RoomView
- rooms map[string]*RoomView
+ rooms map[id.RoomID]*RoomView
roomsLock sync.RWMutex
cmdProcessor *CommandProcessor
focused mauview.Focusable
@@ -64,7 +65,7 @@ func (ui *GomuksUI) NewMainView() mauview.Component {
mainView := &MainView{
flex: mauview.NewFlex().SetDirection(mauview.FlexColumn),
roomView: mauview.NewBox(nil).SetBorder(false),
- rooms: make(map[string]*RoomView),
+ rooms: make(map[id.RoomID]*RoomView),
matrix: ui.gmx.Matrix(),
gmx: ui.gmx,
@@ -295,7 +296,7 @@ func (view *MainView) addRoomPage(room *rooms.Room) *RoomView {
return nil
}
-func (view *MainView) GetRoom(roomID string) ifc.RoomView {
+func (view *MainView) GetRoom(roomID id.RoomID) ifc.RoomView {
room, ok := view.getRoomView(roomID, true)
if !ok {
return view.addRoom(view.matrix.GetOrCreateRoom(roomID))
@@ -303,7 +304,7 @@ func (view *MainView) GetRoom(roomID string) ifc.RoomView {
return room
}
-func (view *MainView) getRoomView(roomID string, lock bool) (room *RoomView, ok bool) {
+func (view *MainView) getRoomView(roomID id.RoomID, lock bool) (room *RoomView, ok bool) {
if lock {
view.roomsLock.RLock()
room, ok = view.rooms[roomID]
@@ -357,7 +358,7 @@ func (view *MainView) addRoom(room *rooms.Room) *RoomView {
func (view *MainView) SetRooms(rooms *rooms.RoomCache) {
view.roomList.Clear()
view.roomsLock.Lock()
- view.rooms = make(map[string]*RoomView)
+ view.rooms = make(map[id.RoomID]*RoomView)
for _, room := range rooms.Map {
if room.HasLeft {
continue
@@ -383,7 +384,7 @@ func (view *MainView) UpdateTags(room *rooms.Room) {
view.parent.Render()
}
-func (view *MainView) SetTyping(roomID string, users []string) {
+func (view *MainView) SetTyping(roomID id.RoomID, users []id.UserID) {
roomView, ok := view.getRoomView(roomID, true)
if ok {
roomView.SetTyping(users)
@@ -438,7 +439,7 @@ func (view *MainView) NotifyMessage(room *rooms.Room, message ifc.Message, shoul
message.SetIsHighlight(should.Highlight)
}
-func (view *MainView) LoadHistory(roomID string) {
+func (view *MainView) LoadHistory(roomID id.RoomID) {
defer debug.Recover()
roomView, ok := view.getRoomView(roomID, true)
if !ok {
diff --git a/ui/widget/color.go b/ui/widget/color.go
index edb966c..5a8d001 100644
--- a/ui/widget/color.go
+++ b/ui/widget/color.go
@@ -21,6 +21,8 @@ import (
"hash/fnv"
"maunium.net/go/tcell"
+
+ "maunium.net/go/mautrix/id"
)
var colorNames = []string{
@@ -201,8 +203,17 @@ func GetHashColorName(s string) string {
// GetHashColor gets the tcell Color value for the given string.
//
// GetHashColor calls GetHashColorName() and gets the Color value from the tcell.ColorNames map.
-func GetHashColor(s string) tcell.Color {
- return tcell.ColorNames[GetHashColorName(s)]
+func GetHashColor(val interface{}) tcell.Color {
+ switch str := val.(type) {
+ case string:
+ return tcell.ColorNames[GetHashColorName(str)]
+ case *string:
+ return tcell.ColorNames[GetHashColorName(*str)]
+ case id.UserID:
+ return tcell.ColorNames[GetHashColorName(string(str))]
+ default:
+ return tcell.ColorNames["red"]
+ }
}
// AddColor adds tview color tags to the given string.