aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/commands.go6
-rw-r--r--ui/messages/base.go10
-rw-r--r--ui/messages/expandedtextmessage.go4
-rw-r--r--ui/messages/imagemessage.go4
-rw-r--r--ui/messages/parser/htmlparser.go9
-rw-r--r--ui/messages/parser/parser.go37
-rw-r--r--ui/messages/textmessage.go6
-rw-r--r--ui/room-view.go8
-rw-r--r--ui/view-login.go6
-rw-r--r--ui/view-main.go8
-rw-r--r--ui/widget/border.go4
11 files changed, 60 insertions, 42 deletions
diff --git a/ui/commands.go b/ui/commands.go
index b80fa07..0feda29 100644
--- a/ui/commands.go
+++ b/ui/commands.go
@@ -19,7 +19,7 @@ package ui
import (
"encoding/json"
"fmt"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"strings"
"unicode"
@@ -133,7 +133,7 @@ func cmdSendEvent(cmd *Command) {
return
}
roomID := cmd.Args[0]
- eventType := gomatrix.NewEventType(cmd.Args[1])
+ eventType := mautrix.NewEventType(cmd.Args[1])
rawContent := strings.Join(cmd.Args[2:], "")
debug.Print(roomID, eventType, rawContent)
@@ -162,7 +162,7 @@ func cmdSetState(cmd *Command) {
}
roomID := cmd.Args[0]
- eventType := gomatrix.NewEventType(cmd.Args[1])
+ eventType := mautrix.NewEventType(cmd.Args[1])
stateKey := cmd.Args[2]
if stateKey == "-" {
stateKey = ""
diff --git a/ui/messages/base.go b/ui/messages/base.go
index c9da389..441aca1 100644
--- a/ui/messages/base.go
+++ b/ui/messages/base.go
@@ -18,7 +18,7 @@ package messages
import (
"encoding/gob"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"time"
"maunium.net/go/gomuks/config"
@@ -34,7 +34,7 @@ func init() {
type BaseMessage struct {
MsgID string
- MsgType gomatrix.MessageType
+ MsgType mautrix.MessageType
MsgSenderID string
MsgSender string
MsgSenderColor tcell.Color
@@ -48,7 +48,7 @@ type BaseMessage struct {
prevPrefs config.UserPreferences
}
-func newBaseMessage(id, sender, displayname string, msgtype gomatrix.MessageType, timestamp time.Time) BaseMessage {
+func newBaseMessage(id, sender, displayname string, msgtype mautrix.MessageType, timestamp time.Time) BaseMessage {
return BaseMessage{
MsgSenderID: sender,
MsgSender: displayname,
@@ -195,11 +195,11 @@ func (msg *BaseMessage) SetID(id string) {
msg.MsgID = id
}
-func (msg *BaseMessage) Type() gomatrix.MessageType {
+func (msg *BaseMessage) Type() mautrix.MessageType {
return msg.MsgType
}
-func (msg *BaseMessage) SetType(msgtype gomatrix.MessageType) {
+func (msg *BaseMessage) SetType(msgtype mautrix.MessageType) {
msg.MsgType = msgtype
}
diff --git a/ui/messages/expandedtextmessage.go b/ui/messages/expandedtextmessage.go
index 2e77a24..fbb373d 100644
--- a/ui/messages/expandedtextmessage.go
+++ b/ui/messages/expandedtextmessage.go
@@ -18,7 +18,7 @@ package messages
import (
"encoding/gob"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"time"
"maunium.net/go/gomuks/config"
@@ -35,7 +35,7 @@ type ExpandedTextMessage struct {
}
// NewExpandedTextMessage creates a new ExpandedTextMessage object with the provided values and the default state.
-func NewExpandedTextMessage(id, sender, displayname string, msgtype gomatrix.MessageType, text tstring.TString, timestamp time.Time) UIMessage {
+func NewExpandedTextMessage(id, sender, displayname string, msgtype mautrix.MessageType, text tstring.TString, timestamp time.Time) UIMessage {
return &ExpandedTextMessage{
BaseMessage: newBaseMessage(id, sender, displayname, msgtype, timestamp),
MsgText: text,
diff --git a/ui/messages/imagemessage.go b/ui/messages/imagemessage.go
index a17c842..8ccff67 100644
--- a/ui/messages/imagemessage.go
+++ b/ui/messages/imagemessage.go
@@ -20,7 +20,7 @@ import (
"bytes"
"encoding/gob"
"fmt"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"time"
"image/color"
@@ -48,7 +48,7 @@ type ImageMessage struct {
}
// NewImageMessage creates a new ImageMessage object with the provided values and the default state.
-func NewImageMessage(matrix ifc.MatrixContainer, id, sender, displayname string, msgtype gomatrix.MessageType, body, homeserver, fileID string, data []byte, timestamp time.Time) UIMessage {
+func NewImageMessage(matrix ifc.MatrixContainer, id, sender, displayname string, msgtype mautrix.MessageType, body, homeserver, fileID string, data []byte, timestamp time.Time) UIMessage {
return &ImageMessage{
newBaseMessage(id, sender, displayname, msgtype, timestamp),
body,
diff --git a/ui/messages/parser/htmlparser.go b/ui/messages/parser/htmlparser.go
index bcde14d..b2deeba 100644
--- a/ui/messages/parser/htmlparser.go
+++ b/ui/messages/parser/htmlparser.go
@@ -24,10 +24,10 @@ import (
"github.com/lucasb-eyer/go-colorful"
"golang.org/x/net/html"
- "maunium.net/go/gomatrix"
"maunium.net/go/gomuks/matrix/rooms"
"maunium.net/go/gomuks/ui/messages/tstring"
"maunium.net/go/gomuks/ui/widget"
+ "maunium.net/go/mautrix"
"maunium.net/go/tcell"
"strconv"
)
@@ -69,6 +69,9 @@ func (parser *htmlParser) getAttribute(node *html.Node, attribute string) string
}
func digits(num int) int {
+ if num <= 0 {
+ return 0
+ }
return int(math.Floor(math.Log10(float64(num))) + 1)
}
@@ -270,14 +273,14 @@ func (parser *htmlParser) Parse(htmlData string) tstring.TString {
}
// ParseHTMLMessage parses a HTML-formatted Matrix event into a UIMessage.
-func ParseHTMLMessage(room *rooms.Room, evt *gomatrix.Event, senderDisplayname string) tstring.TString {
+func ParseHTMLMessage(room *rooms.Room, evt *mautrix.Event, senderDisplayname string) tstring.TString {
htmlData := evt.Content.FormattedBody
htmlData = strings.Replace(htmlData, "\t", " ", -1)
parser := htmlParser{room}
str := parser.Parse(htmlData)
- if evt.Content.MsgType == gomatrix.MsgEmote {
+ if evt.Content.MsgType == mautrix.MsgEmote {
str = tstring.Join([]tstring.TString{
tstring.NewTString("* "),
tstring.NewColorTString(senderDisplayname, widget.GetHashColor(evt.Sender)),
diff --git a/ui/messages/parser/parser.go b/ui/messages/parser/parser.go
index 1d7ced3..ef6578f 100644
--- a/ui/messages/parser/parser.go
+++ b/ui/messages/parser/parser.go
@@ -18,24 +18,28 @@ package parser
import (
"fmt"
+ "html"
"strings"
"time"
- "maunium.net/go/gomatrix"
"maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/interface"
"maunium.net/go/gomuks/matrix/rooms"
"maunium.net/go/gomuks/ui/messages"
"maunium.net/go/gomuks/ui/messages/tstring"
"maunium.net/go/gomuks/ui/widget"
+ "maunium.net/go/mautrix"
"maunium.net/go/tcell"
)
-func ParseEvent(matrix ifc.MatrixContainer, room *rooms.Room, evt *gomatrix.Event) messages.UIMessage {
+func ParseEvent(matrix ifc.MatrixContainer, room *rooms.Room, evt *mautrix.Event) messages.UIMessage {
switch evt.Type {
- case gomatrix.EventMessage:
+ case mautrix.EventSticker:
+ evt.Content.MsgType = mautrix.MsgImage
+ fallthrough
+ case mautrix.EventMessage:
return ParseMessage(matrix, room, evt)
- case gomatrix.StateMember:
+ case mautrix.StateMember:
return ParseMembershipEvent(room, evt)
}
return nil
@@ -49,16 +53,27 @@ func unixToTime(unix int64) time.Time {
return timestamp
}
-func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *gomatrix.Event) messages.UIMessage {
+func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *mautrix.Event) messages.UIMessage {
displayname := evt.Sender
member := room.GetMember(evt.Sender)
if member != nil {
displayname = member.Displayname
}
+ if len(evt.Content.GetReplyTo()) > 0 {
+ evt.Content.RemoveReplyFallback()
+ replyToEvt, _ := matrix.Client().GetEvent(room.ID, evt.Content.GetReplyTo())
+ replyToEvt.Content.RemoveReplyFallback()
+ if len(replyToEvt.Content.FormattedBody) == 0 {
+ replyToEvt.Content.FormattedBody = html.EscapeString(replyToEvt.Content.Body)
+ }
+ evt.Content.FormattedBody = fmt.Sprintf(
+ "In reply to <a href='https://matrix.to/#/%[1]s'>%[1]s</a><blockquote>%[2]s</blockquote><br/>%[3]s",
+ replyToEvt.Sender, replyToEvt.Content.FormattedBody, evt.Content.FormattedBody)
+ }
ts := unixToTime(evt.Timestamp)
switch evt.Content.MsgType {
case "m.text", "m.notice", "m.emote":
- if evt.Content.Format == gomatrix.FormatHTML {
+ if evt.Content.Format == mautrix.FormatHTML {
text := ParseHTMLMessage(room, evt, displayname)
return messages.NewExpandedTextMessage(evt.ID, evt.Sender, displayname, evt.Content.MsgType, text, ts)
}
@@ -74,7 +89,7 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *gomatrix.Ev
return nil
}
-func getMembershipChangeMessage(evt *gomatrix.Event, membership, prevMembership gomatrix.Membership, senderDisplayname, displayname, prevDisplayname string) (sender string, text tstring.TString) {
+func getMembershipChangeMessage(evt *mautrix.Event, membership, prevMembership mautrix.Membership, senderDisplayname, displayname, prevDisplayname string) (sender string, text tstring.TString) {
switch membership {
case "invite":
sender = "---"
@@ -88,7 +103,7 @@ func getMembershipChangeMessage(evt *gomatrix.Event, membership, prevMembership
case "leave":
sender = "<--"
if evt.Sender != *evt.StateKey {
- if prevMembership == gomatrix.MembershipBan {
+ if prevMembership == mautrix.MembershipBan {
text = tstring.NewColorTString(fmt.Sprintf("%s unbanned %s", senderDisplayname, displayname), tcell.ColorGreen)
text.Colorize(len(senderDisplayname)+len(" unbanned "), len(displayname), widget.GetHashColor(*evt.StateKey))
} else {
@@ -111,7 +126,7 @@ func getMembershipChangeMessage(evt *gomatrix.Event, membership, prevMembership
return
}
-func getMembershipEventContent(room *rooms.Room, evt *gomatrix.Event) (sender string, text tstring.TString) {
+func getMembershipEventContent(room *rooms.Room, evt *mautrix.Event) (sender string, text tstring.TString) {
member := room.GetMember(evt.Sender)
senderDisplayname := evt.Sender
if member != nil {
@@ -124,7 +139,7 @@ func getMembershipEventContent(room *rooms.Room, evt *gomatrix.Event) (sender st
displayname = *evt.StateKey
}
- prevMembership := gomatrix.MembershipLeave
+ prevMembership := mautrix.MembershipLeave
prevDisplayname := *evt.StateKey
if evt.Unsigned.PrevContent != nil {
prevMembership = evt.Unsigned.PrevContent.Membership
@@ -146,7 +161,7 @@ func getMembershipEventContent(room *rooms.Room, evt *gomatrix.Event) (sender st
return
}
-func ParseMembershipEvent(room *rooms.Room, evt *gomatrix.Event) messages.UIMessage {
+func ParseMembershipEvent(room *rooms.Room, evt *mautrix.Event) messages.UIMessage {
displayname, text := getMembershipEventContent(room, evt)
if len(text) == 0 {
return nil
diff --git a/ui/messages/textmessage.go b/ui/messages/textmessage.go
index d5ce324..8622c32 100644
--- a/ui/messages/textmessage.go
+++ b/ui/messages/textmessage.go
@@ -19,7 +19,7 @@ package messages
import (
"encoding/gob"
"fmt"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"time"
"maunium.net/go/gomuks/config"
@@ -38,7 +38,7 @@ type TextMessage struct {
}
// NewTextMessage creates a new UITextMessage object with the provided values and the default state.
-func NewTextMessage(id, sender, displayname string, msgtype gomatrix.MessageType, text string, timestamp time.Time) UIMessage {
+func NewTextMessage(id, sender, displayname string, msgtype mautrix.MessageType, text string, timestamp time.Time) UIMessage {
return &TextMessage{
BaseMessage: newBaseMessage(id, sender, displayname, msgtype, timestamp),
MsgText: text,
@@ -58,7 +58,7 @@ func (msg *TextMessage) getCache() tstring.TString {
return msg.cache
}
-func (msg *TextMessage) SetType(msgtype gomatrix.MessageType) {
+func (msg *TextMessage) SetType(msgtype mautrix.MessageType) {
msg.BaseMessage.SetType(msgtype)
msg.cache = nil
}
diff --git a/ui/room-view.go b/ui/room-view.go
index 4b2cd48..6eda559 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -18,7 +18,7 @@ package ui
import (
"fmt"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"path/filepath"
"sort"
"strconv"
@@ -347,7 +347,7 @@ func (view *RoomView) UpdateUserList() {
}
}
-func (view *RoomView) newUIMessage(id, sender string, msgtype gomatrix.MessageType, text string, timestamp time.Time) messages.UIMessage {
+func (view *RoomView) newUIMessage(id, sender string, msgtype mautrix.MessageType, text string, timestamp time.Time) messages.UIMessage {
member := view.Room.GetMember(sender)
displayname := sender
if member != nil {
@@ -357,11 +357,11 @@ func (view *RoomView) newUIMessage(id, sender string, msgtype gomatrix.MessageTy
return msg
}
-func (view *RoomView) NewMessage(id, sender string, msgtype gomatrix.MessageType, text string, timestamp time.Time) ifc.Message {
+func (view *RoomView) NewMessage(id, sender string, msgtype mautrix.MessageType, text string, timestamp time.Time) ifc.Message {
return view.newUIMessage(id, sender, msgtype, text, timestamp)
}
-func (view *RoomView) NewTempMessage(msgtype gomatrix.MessageType, text string) ifc.Message {
+func (view *RoomView) NewTempMessage(msgtype mautrix.MessageType, text string) ifc.Message {
now := time.Now()
id := strconv.FormatInt(now.UnixNano(), 10)
sender := ""
diff --git a/ui/view-login.go b/ui/view-login.go
index a900870..3d42506 100644
--- a/ui/view-login.go
+++ b/ui/view-login.go
@@ -17,11 +17,11 @@
package ui
import (
- "maunium.net/go/gomatrix"
"maunium.net/go/gomuks/config"
"maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/interface"
"maunium.net/go/gomuks/ui/widget"
+ "maunium.net/go/mautrix"
"maunium.net/go/tview"
)
@@ -89,8 +89,8 @@ func (view *LoginView) Login() {
debug.Print("Init error:", err)
err = view.matrix.Login(mxid, password)
if err != nil {
- if httpErr, ok := err.(gomatrix.HTTPError); ok {
- if respErr, ok := httpErr.WrappedError.(gomatrix.RespError); ok {
+ if httpErr, ok := err.(mautrix.HTTPError); ok {
+ if respErr, ok := httpErr.WrappedError.(mautrix.RespError); ok {
view.Error(respErr.Err)
} else {
view.Error(httpErr.Message)
diff --git a/ui/view-main.go b/ui/view-main.go
index c5abb19..5faa804 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -26,7 +26,7 @@ import (
"bufio"
"os"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"maunium.net/go/gomuks/config"
"maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/interface"
@@ -152,8 +152,8 @@ func (view *MainView) sendTempMessage(roomView *RoomView, tempMessage ifc.Messag
eventID, err := view.matrix.SendMarkdownMessage(roomView.Room.ID, tempMessage.Type(), text)
if err != nil {
tempMessage.SetState(ifc.MessageStateFailed)
- if httpErr, ok := err.(gomatrix.HTTPError); ok {
- if respErr, ok := httpErr.WrappedError.(gomatrix.RespError); ok {
+ if httpErr, ok := err.(mautrix.HTTPError); ok {
+ if respErr, ok := httpErr.WrappedError.(mautrix.RespError); ok {
// Show shorter version if available
err = respErr
}
@@ -510,6 +510,6 @@ func (view *MainView) LoadHistory(room string) {
view.parent.Render()
}
-func (view *MainView) ParseEvent(roomView ifc.RoomView, evt *gomatrix.Event) ifc.Message {
+func (view *MainView) ParseEvent(roomView ifc.RoomView, evt *mautrix.Event) ifc.Message {
return parser.ParseEvent(view.matrix, roomView.MxRoom(), evt)
}
diff --git a/ui/widget/border.go b/ui/widget/border.go
index b3eb65d..834eedb 100644
--- a/ui/widget/border.go
+++ b/ui/widget/border.go
@@ -40,11 +40,11 @@ func (border *Border) Draw(screen tcell.Screen) {
x, y, width, height := border.GetRect()
if width == 1 {
for borderY := y; borderY < y+height; borderY++ {
- screen.SetContent(x, borderY, tview.GraphicsVertBar, nil, background)
+ screen.SetContent(x, borderY, tview.Borders.Vertical, nil, background)
}
} else if height == 1 {
for borderX := x; borderX < x+width; borderX++ {
- screen.SetContent(borderX, y, tview.GraphicsHoriBar, nil, background)
+ screen.SetContent(borderX, y, tview.Borders.Horizontal, nil, background)
}
}
}