From 815190be147e575f12211c468f8121e5c60e6337 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 16 Apr 2020 19:27:35 +0300 Subject: Update stuff and move pushrules to mautrix-go --- ui/messages/base.go | 39 +++---- ui/messages/expandedtextmessage.go | 4 +- ui/messages/filemessage.go | 27 ++--- ui/messages/html/parser.go | 15 +-- ui/messages/htmlmessage.go | 4 +- ui/messages/parser.go | 205 +++++++++++++++++++------------------ ui/messages/redactedmessage.go | 4 +- ui/messages/textmessage.go | 4 +- 8 files changed, 153 insertions(+), 149 deletions(-) (limited to 'ui/messages') 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", "
", -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, }) -- cgit v1.2.3