commit 29dd9b84bd88fd4fefad283919c714a67b040e59
parent e6c580d73a64b13098061b4c7987c263b5b8a77b
Author: MTRNord <mtrnord1@gmail.com>
Date: Sun, 3 Dec 2017 10:00:31 +0100
add basic linkify support
Diffstat:
4 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/main.go b/main.go
@@ -55,6 +55,7 @@ func main() {
go func() {
<-c
cleanup()
+ close(c)
os.Exit(1)
}()
diff --git a/matrix/rooms.go b/matrix/rooms.go
@@ -10,6 +10,7 @@ import (
"github.com/Nordgedanken/Morpheus/matrix/db"
"github.com/dgraph-io/badger"
"github.com/matrix-org/gomatrix"
+ "github.com/rhinoman/go-commonmark"
log "github.com/sirupsen/logrus"
"github.com/therecipe/qt/gui"
)
@@ -50,8 +51,17 @@ func (r *Room) GetRoomTopic() (topic string) {
if r.RoomTopic == "" {
r.crawlRoomTopic()
}
- topic = r.RoomTopic
- return
+
+ mardownMessage := commonmark.Md2Html(r.RoomTopic, 0)
+
+ if mardownMessage == r.RoomTopic {
+ topic = r.RoomTopic
+ return
+ } else {
+ r.RoomTopic = mardownMessage
+ topic = r.RoomTopic
+ return
+ }
}
// GetRoomAvatar generates the Avatar Image for a Room
diff --git a/ui/MainUI.go b/ui/MainUI.go
@@ -18,6 +18,7 @@ import (
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/uitools"
"github.com/therecipe/qt/widgets"
+ "github.com/opennota/linkify"
)
// NewMainUIStruct gives you a MainUI struct with prefilled data
@@ -134,6 +135,33 @@ func (m *MainUI) NewUI() (err error) {
} else {
own = false
}
+ lm := linkify.Links(messageBody)
+ for _, l := range lm {
+ link := messageBody[l.Start:l.End]
+ if l.Start-9 > 0 {
+ log.Infoln("if1: ",messageBody[l.Start-9:l.Start])
+ if !strings.Contains(messageBody[l.Start-9:l.Start], "<a href='") {
+ if l.Start-(1+l.Start+l.End) > 0 {
+ log.Infoln("if2: ",messageBody[l.Start-(1+l.Start+l.End):l.Start])
+ if !strings.Contains(messageBody[l.Start-(1+l.Start+l.End):l.Start], "<a href='"+link+"'>") {
+ messageBody = strings.Replace(messageBody, link, "<a href='"+link+"'>"+link+"</a>", -1)
+ }
+ }else if l.Start-(1+l.Start+l.End) <= 0 {
+ log.Infoln("else2: ",messageBody[0:l.Start])
+ if !strings.Contains(messageBody[0:l.Start], "<a href='"+link+"'>") {
+ messageBody = strings.Replace(messageBody, link, "<a href='" + link + "'>" + link + "</a>", -1)
+ }
+ }
+ }
+ } else if l.Start-9 <= 0 {
+ log.Infoln(messageBody[0:l.Start])
+ if !strings.Contains(messageBody[0:l.Start], "<a href='") {
+ if !strings.Contains(messageBody[0:l.Start], "<a href='"+link+"'>") {
+ messageBody = strings.Replace(messageBody, link, "<a href='" + link + "'>" + link + "</a>", -1)
+ }
+ }
+ }
+ }
NewMessageErr := m.MessageListLayout.NewMessage(messageBody, m.cli, sender, timestamp, m.messageScrollArea, own, m)
if NewMessageErr != nil {
err = NewMessageErr
@@ -198,9 +226,16 @@ func (m *MainUI) NewUI() (err error) {
}
func (m *MainUI) sendMessage(message string) (err error) {
+ messageOriginal := message
+ lm := linkify.Links(message)
+ for _, l := range lm {
+ link := message[l.Start:l.End]
+ message = strings.Replace(message, link, "<a href='" + link + "'>" + link + "</a>", -1)
+ }
+
mardownMessage := commonmark.Md2Html(message, 0)
if mardownMessage == message {
- _, SendErr := m.cli.SendText(m.currentRoom, message)
+ _, SendErr := m.cli.SendMessageEvent(m.currentRoom, "m.room.message", matrix.HTMLMessage{MsgType: "m.text", Body: messageOriginal, FormattedBody: message, Format: "org.matrix.custom.html"})
if SendErr != nil {
err = SendErr
return
diff --git a/ui/roomlist.go b/ui/roomlist.go
@@ -24,6 +24,7 @@ type QRoomVBoxLayoutWithTriggerSlot struct {
widgets.QVBoxLayout
_ func(roomID string) `slot:"TriggerRoom"`
+ _ func(url *core.QUrl) `slot:"ChangeRoom"`
}
// NewRoomList generates a new QRoomVBoxLayoutWithTriggerSlot and adds it to the room scrollArea
@@ -94,7 +95,7 @@ func (roomViewLayout *QRoomVBoxLayoutWithTriggerSlot) NewRoom(room *matrix.Room,
}
go mainUIStruct.loadCache()
- }
+ }
return true
}