diff --git a/Gopkg.lock b/Gopkg.lock
index 25c518f..5e46ec5 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -2,79 +2,104 @@
[[projects]]
+ digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec"
name = "github.com/davecgh/go-spew"
packages = ["spew"]
+ pruneopts = "UT"
revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73"
version = "v1.1.1"
[[projects]]
+ digest = "1:2694597a20d303502ad1b7f1cc688977c7dc34da732ccf4d27e98b552cceed5b"
name = "github.com/disintegration/imaging"
packages = ["."]
+ pruneopts = "UT"
revision = "0bd5694c78c9c3d9a3cd06a706a8f3c59296a9ac"
version = "v1.5.0"
[[projects]]
branch = "master"
+ digest = "1:40d0056c1b1f503c366ba441df92a82b5a2654d6f3747b1689a611eb5c9ce0a2"
name = "github.com/gdamore/encoding"
packages = ["."]
+ pruneopts = "UT"
revision = "b23993cbb6353f0e6aa98d0ee318a34728f628b9"
[[projects]]
+ digest = "1:f4bd9b6cfcbaafa94259861747781022d8f06ff3c88aafe49a815ac02609bc96"
name = "github.com/kyokomi/emoji"
packages = ["."]
+ pruneopts = "UT"
revision = "2e9a9507333f3ee28f3fab88c2c3aba34455d734"
version = "v1.5.1"
[[projects]]
+ digest = "1:c65a16ac77d0b1aefc7009cabb6ac5ad05def02025f5be85f450c03f52cc6f86"
name = "github.com/lucasb-eyer/go-colorful"
packages = ["."]
+ pruneopts = "UT"
revision = "345fbb3dbcdb252d9985ee899a84963c0fa24c82"
version = "v1.0"
[[projects]]
+ digest = "1:cdb899c199f907ac9fb50495ec71212c95cb5b0e0a8ee0800da0238036091033"
name = "github.com/mattn/go-runewidth"
packages = ["."]
+ pruneopts = "UT"
revision = "ce7b0b5c7b45a81508558cd1dba6bb1e4ddb51bb"
version = "v0.0.3"
[[projects]]
branch = "master"
+ digest = "1:0e1e5f960c58fdc677212fcc70e55042a0084d367623e51afbdb568963832f5d"
name = "github.com/nu7hatch/gouuid"
packages = ["."]
+ pruneopts = "UT"
revision = "179d4d0c4d8d407a32af483c2354df1d2c91e6c3"
[[projects]]
+ digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe"
name = "github.com/pmezard/go-difflib"
packages = ["difflib"]
+ pruneopts = "UT"
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
version = "v1.0.0"
[[projects]]
+ branch = "master"
+ digest = "1:3fd3d634f6815f19ac4b2c5e16d28ec9aa4584d0bba25d1ee6c424d813cca22a"
name = "github.com/renstrom/fuzzysearch"
packages = ["fuzzy"]
+ pruneopts = "UT"
revision = "b18e754edff4833912ef4dce9eaca885bd3f0de1"
- version = "v1.0.1"
[[projects]]
branch = "master"
+ digest = "1:def689e73e9252f6f7fe66834a76751a41b767e03daab299e607e7226c58a855"
name = "github.com/shurcooL/sanitized_anchor_name"
packages = ["."]
+ pruneopts = "UT"
revision = "86672fcb3f950f35f2e675df2240550f2a50762f"
[[projects]]
+ digest = "1:18752d0b95816a1b777505a97f71c7467a8445b8ffb55631a7bf779f6ba4fa83"
name = "github.com/stretchr/testify"
packages = ["assert"]
+ pruneopts = "UT"
revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686"
version = "v1.2.2"
[[projects]]
branch = "master"
+ digest = "1:22738a5261588086d75acb3c792f7c931d30fd32e351117e9e046331135f5297"
name = "github.com/zyedidia/clipboard"
packages = ["."]
+ pruneopts = "UT"
revision = "bd31d747117d04b4e25b61f73e1ea4faeea3c56a"
[[projects]]
branch = "master"
+ digest = "1:441333ba1f7f3074035297647244e3d1ce3665e4e7c5054b3a8b138463f8ff58"
name = "golang.org/x/image"
packages = [
"bmp",
@@ -83,79 +108,108 @@
"tiff/lzw",
"vp8",
"vp8l",
- "webp"
+ "webp",
]
- revision = "c73c2afc3b812cdd6385de5a50616511c4a3d458"
+ pruneopts = "UT"
+ revision = "249dc8530c0efc2766606a940c1c50b434b2f1cd"
[[projects]]
branch = "master"
+ digest = "1:1a1ecfa7b54ca3f7a0115ab5c578d7d6a5d8b605839c549e80260468c42f8be7"
name = "golang.org/x/net"
packages = [
"html",
- "html/atom"
+ "html/atom",
]
- revision = "8a410e7b638dca158bf9e766925842f6651ff828"
+ pruneopts = "UT"
+ revision = "88d92db4c548972d942ac2a3531a8a9a34c82ca6"
[[projects]]
+ digest = "1:37672ad5821719e2df8509c2edd4ba5ae192463237c73c3a2d24ef8b2bc9e36f"
name = "golang.org/x/text"
packages = [
"encoding",
"encoding/internal/identifier",
"internal/gen",
"transform",
- "unicode/cldr"
+ "unicode/cldr",
]
+ pruneopts = "UT"
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
version = "v0.3.0"
[[projects]]
+ digest = "1:2ee0f15eb0fb04f918db7c2dcf39745f40d69f798ef171610a730e8a56aaa4fd"
name = "gopkg.in/russross/blackfriday.v2"
packages = ["."]
- revision = "cadec560ec52d93835bf2f15bd794700d3a2473b"
- version = "v2.0.0"
+ pruneopts = "UT"
+ revision = "d3b5b032dc8e8927d31a5071b56e14c89f045135"
+ version = "v2.0.1"
[[projects]]
branch = "v1"
+ digest = "1:b71ccd8615521db4ea2f9381f55780a1312654f5d8431d2e58eca51c74110de2"
name = "gopkg.in/toast.v1"
packages = ["."]
+ pruneopts = "UT"
revision = "0a84660828b24d25b35525c9a1f1f51267f8da91"
[[projects]]
+ digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202"
name = "gopkg.in/yaml.v2"
packages = ["."]
+ pruneopts = "UT"
revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183"
version = "v2.2.1"
[[projects]]
branch = "master"
- name = "maunium.net/go/gomatrix"
+ digest = "1:d23e0bbfa4e45fe847e61fdfd442b24adf9bd3d0b050a846f9ef0f3af4f43c86"
+ name = "maunium.net/go/mautrix"
packages = ["."]
- revision = "d651abc3ecb4bbd85a6b17b710632e73ddbbc6aa"
-
-[[projects]]
- name = "maunium.net/go/maulogger"
- packages = ["."]
- revision = "64f0aa33b6c51313e15575257db71dec44fe7988"
- version = "v1.0"
+ pruneopts = "UT"
+ revision = "e8080dcf484d1db9021d2019fee132ffc9e37e3c"
[[projects]]
branch = "master"
+ digest = "1:28d6d6123ce29c9b0b5d393af0085f1454a9d93d70b4c9893efe6cff025702b9"
name = "maunium.net/go/tcell"
packages = [
".",
- "terminfo"
+ "terminfo",
]
- revision = "f32e44a866ab0475655e11ede91337d7b562956d"
+ pruneopts = "UT"
+ revision = "a62189e4543d731b94ae0d3b659d1853975ea657"
[[projects]]
branch = "master"
+ digest = "1:b4c2e264221b6afa98aec4e0a097f3775cb014eebac8a6f49d33c53b237b77af"
name = "maunium.net/go/tview"
packages = ["."]
- revision = "8b261597bbdb95dcaef03854aaa0cc192f56b1ff"
+ pruneopts = "UT"
+ revision = "dae31f32cda75339f5ec2a64411ef3ec1862ef5e"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
- inputs-digest = "6c0a263ebffa1c073f4b67a895832017afeab906b0d88b31da38ae22bc75e1aa"
+ input-imports = [
+ "github.com/disintegration/imaging",
+ "github.com/kyokomi/emoji",
+ "github.com/lucasb-eyer/go-colorful",
+ "github.com/mattn/go-runewidth",
+ "github.com/renstrom/fuzzysearch/fuzzy",
+ "github.com/stretchr/testify/assert",
+ "github.com/zyedidia/clipboard",
+ "golang.org/x/image/bmp",
+ "golang.org/x/image/tiff",
+ "golang.org/x/image/webp",
+ "golang.org/x/net/html",
+ "gopkg.in/russross/blackfriday.v2",
+ "gopkg.in/toast.v1",
+ "gopkg.in/yaml.v2",
+ "maunium.net/go/mautrix",
+ "maunium.net/go/tcell",
+ "maunium.net/go/tview",
+ ]
solver-name = "gps-cdcl"
solver-version = 1
diff --git a/Gopkg.toml b/Gopkg.toml
index 5927463..2fa3148 100644
--- a/Gopkg.toml
+++ b/Gopkg.toml
@@ -63,7 +63,7 @@
[[constraint]]
branch = "master"
- name = "maunium.net/go/gomatrix"
+ name = "maunium.net/go/mautrix"
[[constraint]]
branch = "master"
diff --git a/README.md b/README.md
index 79509d3..e39c33b 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@
![Chat Preview](chat-preview.png)
-A terminal Matrix client written in Go using [gomatrix](https://github.com/matrix-org/gomatrix) and [tview](https://github.com/rivo/tview).
+A terminal Matrix client written in Go using [mautrix](https://github.com/matrix-org/mautrix) and [tview](https://github.com/rivo/tview).
Basic usage is possible, but expect bugs and missing features.
diff --git a/config/config.go b/config/config.go
index e4fb743..8f45d76 100644
--- a/config/config.go
+++ b/config/config.go
@@ -25,7 +25,7 @@ import (
"strings"
"gopkg.in/yaml.v2"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/matrix/pushrules"
"maunium.net/go/gomuks/matrix/rooms"
@@ -289,12 +289,12 @@ func (config *Config) PutRoom(room *rooms.Room) {
room.Save(config.getRoomCachePath(room))
}
-func (config *Config) SaveRoom(room *gomatrix.Room) {
+func (config *Config) SaveRoom(room *mautrix.Room) {
gmxRoom := config.GetRoom(room.ID)
gmxRoom.Room = room
gmxRoom.Save(config.getRoomCachePath(gmxRoom))
}
-func (config *Config) LoadRoom(roomID string) *gomatrix.Room {
+func (config *Config) LoadRoom(roomID string) *mautrix.Room {
return config.GetRoom(roomID).Room
}
diff --git a/interface/matrix.go b/interface/matrix.go
index 0538df9..01f224e 100644
--- a/interface/matrix.go
+++ b/interface/matrix.go
@@ -17,12 +17,12 @@
package ifc
import (
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"maunium.net/go/gomuks/matrix/rooms"
)
type MatrixContainer interface {
- Client() *gomatrix.Client
+ Client() *mautrix.Client
InitClient() error
Initialized() bool
@@ -33,14 +33,14 @@ type MatrixContainer interface {
Logout()
SendPreferencesToMatrix()
- SendMessage(roomID string, msgtype gomatrix.MessageType, message string) (string, error)
- SendMarkdownMessage(roomID string, msgtype gomatrix.MessageType, message string) (string, error)
+ SendMessage(roomID string, msgtype mautrix.MessageType, message string) (string, error)
+ SendMarkdownMessage(roomID string, msgtype mautrix.MessageType, message string) (string, error)
SendTyping(roomID string, typing bool)
MarkRead(roomID, eventID string)
JoinRoom(roomID, server string) (*rooms.Room, error)
LeaveRoom(roomID string) error
- GetHistory(roomID, prevBatch string, limit int) ([]*gomatrix.Event, string, error)
+ GetHistory(roomID, prevBatch string, limit int) ([]*mautrix.Event, string, error)
GetRoom(roomID string) *rooms.Room
Download(mxcURL string) ([]byte, string, string, error)
diff --git a/interface/ui.go b/interface/ui.go
index 929dc65..39473f5 100644
--- a/interface/ui.go
+++ b/interface/ui.go
@@ -19,7 +19,7 @@ package ifc
import (
"time"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"maunium.net/go/gomuks/matrix/pushrules"
"maunium.net/go/gomuks/matrix/rooms"
"maunium.net/go/tcell"
@@ -50,7 +50,7 @@ type MainView interface {
UpdateTags(room *rooms.Room)
SetTyping(roomID string, users []string)
- ParseEvent(roomView RoomView, evt *gomatrix.Event) Message
+ ParseEvent(roomView RoomView, evt *mautrix.Event) Message
NotifyMessage(room *rooms.Room, message Message, should pushrules.PushActionArrayShould)
InitialSyncDone()
@@ -73,8 +73,8 @@ type RoomView interface {
SetTyping(users []string)
UpdateUserList()
- NewMessage(id, sender string, msgtype gomatrix.MessageType, text string, timestamp time.Time) Message
- NewTempMessage(msgtype gomatrix.MessageType, text string) Message
+ NewMessage(id, sender string, msgtype mautrix.MessageType, text string, timestamp time.Time) Message
+ NewTempMessage(msgtype mautrix.MessageType, text string) Message
AddMessage(message Message, direction MessageDirection)
AddServiceMessage(message string)
}
@@ -111,8 +111,8 @@ type Message interface {
SetID(id string)
ID() string
- SetType(msgtype gomatrix.MessageType)
- Type() gomatrix.MessageType
+ SetType(msgtype mautrix.MessageType)
+ Type() mautrix.MessageType
NotificationContent() string
diff --git a/matrix/doc.go b/matrix/doc.go
index 2cd54e2..f789895 100644
--- a/matrix/doc.go
+++ b/matrix/doc.go
@@ -1,2 +1,2 @@
-// Package matrix contains wrappers for gomatrix for use by the UI of gomuks.
+// Package matrix contains wrappers for mautrix for use by the UI of gomuks.
package matrix
diff --git a/matrix/matrix.go b/matrix/matrix.go
index 060becd..cf9e463 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -34,20 +34,20 @@ import (
"encoding/json"
"gopkg.in/russross/blackfriday.v2"
- "maunium.net/go/gomatrix"
"maunium.net/go/gomuks/config"
"maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/interface"
"maunium.net/go/gomuks/lib/bfhtml"
"maunium.net/go/gomuks/matrix/pushrules"
"maunium.net/go/gomuks/matrix/rooms"
+ "maunium.net/go/mautrix"
)
-// Container is a wrapper for a gomatrix Client and some other stuff.
+// Container is a wrapper for a mautrix Client and some other stuff.
//
// It is used for all Matrix calls from the UI and Matrix event handlers.
type Container struct {
- client *gomatrix.Client
+ client *mautrix.Client
syncer *GomuksSyncer
gmx ifc.Gomuks
ui ifc.GomuksUI
@@ -69,12 +69,18 @@ func NewContainer(gmx ifc.Gomuks) *Container {
return c
}
-// Client returns the underlying gomatrix Client.
-func (c *Container) Client() *gomatrix.Client {
+// Client returns the underlying mautrix Client.
+func (c *Container) Client() *mautrix.Client {
return c.client
}
-// InitClient initializes the gomatrix client and connects to the homeserver specified in the config.
+type mxLogger struct{}
+
+func (log mxLogger) Debugfln(message string, args ...interface{}) {
+ debug.Printf("[Matrix] "+message, args...)
+}
+
+// InitClient initializes the mautrix client and connects to the homeserver specified in the config.
func (c *Container) InitClient() error {
if len(c.config.HS) == 0 {
return fmt.Errorf("no homeserver in config")
@@ -92,10 +98,11 @@ func (c *Container) InitClient() error {
}
var err error
- c.client, err = gomatrix.NewClient(c.config.HS, mxid, accessToken)
+ c.client, err = mautrix.NewClient(c.config.HS, mxid, accessToken)
if err != nil {
return err
}
+ c.client.Logger = mxLogger{}
allowInsecure := len(os.Getenv("GOMUKS_ALLOW_INSECURE_CONNECTIONS")) > 0
if allowInsecure {
@@ -112,14 +119,14 @@ func (c *Container) InitClient() error {
return nil
}
-// Initialized returns whether or not the gomatrix client is initialized (see InitClient())
+// Initialized returns whether or not the mautrix client is initialized (see InitClient())
func (c *Container) Initialized() bool {
return c.client != nil
}
// Login sends a password login request with the given username and password.
func (c *Container) Login(user, password string) error {
- resp, err := c.client.Login(&gomatrix.ReqLogin{
+ resp, err := c.client.Login(&mautrix.ReqLogin{
Type: "m.login.password",
User: user,
Password: password,
@@ -175,7 +182,7 @@ func (c *Container) PushRules() *pushrules.PushRuleset {
return c.config.PushRules
}
-var AccountDataGomuksPreferences = gomatrix.NewEventType("net.maunium.gomuks.preferences")
+var AccountDataGomuksPreferences = mautrix.NewEventType("net.maunium.gomuks.preferences")
// OnLogin initializes the syncer and updates the room list.
func (c *Container) OnLogin() {
@@ -185,15 +192,16 @@ func (c *Container) OnLogin() {
debug.Print("Initializing syncer")
c.syncer = NewGomuksSyncer(c.config)
- c.syncer.OnEventType(gomatrix.EventMessage, c.HandleMessage)
- c.syncer.OnEventType(gomatrix.StateMember, c.HandleMembership)
- c.syncer.OnEventType(gomatrix.EphemeralEventReceipt, c.HandleReadReceipt)
- c.syncer.OnEventType(gomatrix.EphemeralEventTyping, c.HandleTyping)
- c.syncer.OnEventType(gomatrix.AccountDataDirectChats, c.HandleDirectChatInfo)
- c.syncer.OnEventType(gomatrix.AccountDataPushRules, c.HandlePushRules)
- c.syncer.OnEventType(gomatrix.AccountDataRoomTags, c.HandleTag)
+ c.syncer.OnEventType(mautrix.EventMessage, c.HandleMessage)
+ c.syncer.OnEventType(mautrix.StateMember, c.HandleMembership)
+ c.syncer.OnEventType(mautrix.EphemeralEventReceipt, c.HandleReadReceipt)
+ c.syncer.OnEventType(mautrix.EphemeralEventTyping, c.HandleTyping)
+ c.syncer.OnEventType(mautrix.AccountDataDirectChats, c.HandleDirectChatInfo)
+ c.syncer.OnEventType(mautrix.AccountDataPushRules, c.HandlePushRules)
+ c.syncer.OnEventType(mautrix.AccountDataRoomTags, c.HandleTag)
c.syncer.OnEventType(AccountDataGomuksPreferences, c.HandlePreferences)
c.syncer.InitDoneCallback = func() {
+ debug.Print("Initial sync done")
c.config.AuthCache.InitialSyncDone = true
c.config.SaveAuthCache()
c.ui.MainView().InitialSyncDone()
@@ -227,7 +235,7 @@ func (c *Container) Start() {
return
default:
if err := c.client.Sync(); err != nil {
- if httpErr, ok := err.(gomatrix.HTTPError); ok && httpErr.Code == http.StatusUnauthorized {
+ if httpErr, ok := err.(mautrix.HTTPError); ok && httpErr.Code == http.StatusUnauthorized {
debug.Print("Sync() errored with ", err, " -> logging out")
c.Logout()
} else {
@@ -240,7 +248,7 @@ func (c *Container) Start() {
}
}
-func (c *Container) HandlePreferences(source EventSource, evt *gomatrix.Event) {
+func (c *Container) HandlePreferences(source EventSource, evt *mautrix.Event) {
orig := c.config.Preferences
rt, _ := json.Marshal(&evt.Content)
json.Unmarshal(rt, &c.config.Preferences)
@@ -259,7 +267,7 @@ func (c *Container) SendPreferencesToMatrix() {
}
// HandleMessage is the event handler for the m.room.message timeline event.
-func (c *Container) HandleMessage(source EventSource, evt *gomatrix.Event) {
+func (c *Container) HandleMessage(source EventSource, evt *mautrix.Event) {
if source&EventSourceLeave != 0 {
return
}
@@ -286,7 +294,7 @@ func (c *Container) HandleMessage(source EventSource, evt *gomatrix.Event) {
}
// HandleMembership is the event handler for the m.room.member state event.
-func (c *Container) HandleMembership(source EventSource, evt *gomatrix.Event) {
+func (c *Container) HandleMembership(source EventSource, evt *mautrix.Event) {
isLeave := source&EventSourceLeave != 0
isTimeline := source&EventSourceTimeline != 0
isNonTimelineLeave := isLeave && !isTimeline
@@ -302,9 +310,9 @@ func (c *Container) HandleMembership(source EventSource, evt *gomatrix.Event) {
c.HandleMessage(source, evt)
}
-func (c *Container) processOwnMembershipChange(evt *gomatrix.Event) {
+func (c *Container) processOwnMembershipChange(evt *mautrix.Event) {
membership := evt.Content.Membership
- prevMembership := gomatrix.MembershipLeave
+ prevMembership := mautrix.MembershipLeave
if evt.Unsigned.PrevContent != nil {
prevMembership = evt.Unsigned.PrevContent.Membership
}
@@ -326,7 +334,7 @@ func (c *Container) processOwnMembershipChange(evt *gomatrix.Event) {
}
}
-func (c *Container) parseReadReceipt(evt *gomatrix.Event) (largestTimestampEvent string) {
+func (c *Container) parseReadReceipt(evt *mautrix.Event) (largestTimestampEvent string) {
var largestTimestamp int64
for eventID, rawContent := range evt.Content.Raw {
content, ok := rawContent.(map[string]interface{})
@@ -353,7 +361,7 @@ func (c *Container) parseReadReceipt(evt *gomatrix.Event) (largestTimestampEvent
return
}
-func (c *Container) HandleReadReceipt(source EventSource, evt *gomatrix.Event) {
+func (c *Container) HandleReadReceipt(source EventSource, evt *mautrix.Event) {
if source&EventSourceLeave != 0 {
return
}
@@ -368,7 +376,7 @@ func (c *Container) HandleReadReceipt(source EventSource, evt *gomatrix.Event) {
c.ui.Render()
}
-func (c *Container) parseDirectChatInfo(evt *gomatrix.Event) map[*rooms.Room]bool {
+func (c *Container) parseDirectChatInfo(evt *mautrix.Event) map[*rooms.Room]bool {
directChats := make(map[*rooms.Room]bool)
for _, rawRoomIDList := range evt.Content.Raw {
roomIDList, ok := rawRoomIDList.([]interface{})
@@ -391,7 +399,7 @@ func (c *Container) parseDirectChatInfo(evt *gomatrix.Event) map[*rooms.Room]boo
return directChats
}
-func (c *Container) HandleDirectChatInfo(source EventSource, evt *gomatrix.Event) {
+func (c *Container) HandleDirectChatInfo(source EventSource, evt *mautrix.Event) {
directChats := c.parseDirectChatInfo(evt)
for _, room := range c.config.Rooms {
shouldBeDirect := directChats[room]
@@ -403,7 +411,7 @@ func (c *Container) HandleDirectChatInfo(source EventSource, evt *gomatrix.Event
}
// HandlePushRules is the event handler for the m.push_rules account data event.
-func (c *Container) HandlePushRules(source EventSource, evt *gomatrix.Event) {
+func (c *Container) HandlePushRules(source EventSource, evt *mautrix.Event) {
debug.Print("Received updated push rules")
var err error
c.config.PushRules, err = pushrules.EventToPushRules(evt)
@@ -415,7 +423,7 @@ func (c *Container) HandlePushRules(source EventSource, evt *gomatrix.Event) {
}
// HandleTag is the event handler for the m.tag account data event.
-func (c *Container) HandleTag(source EventSource, evt *gomatrix.Event) {
+func (c *Container) HandleTag(source EventSource, evt *mautrix.Event) {
room := c.config.GetRoom(evt.RoomID)
newTags := make([]rooms.RoomTag, len(evt.Content.RoomTags))
@@ -423,7 +431,7 @@ func (c *Container) HandleTag(source EventSource, evt *gomatrix.Event) {
for tag, info := range evt.Content.RoomTags {
order := "0.5"
if len(info.Order) > 0 {
- order = info.Order
+ order = info.Order.String()
}
newTags[index] = rooms.RoomTag{
Tag: tag,
@@ -438,7 +446,7 @@ func (c *Container) HandleTag(source EventSource, evt *gomatrix.Event) {
}
// HandleTyping is the event handler for the m.typing event.
-func (c *Container) HandleTyping(source EventSource, evt *gomatrix.Event) {
+func (c *Container) HandleTyping(source EventSource, evt *mautrix.Event) {
c.ui.MainView().SetTyping(evt.RoomID, evt.Content.TypingUserIDs)
}
@@ -448,11 +456,11 @@ func (c *Container) MarkRead(roomID, eventID string) {
}
// SendMessage sends a message with the given text to the given room.
-func (c *Container) SendMessage(roomID string, msgtype gomatrix.MessageType, text string) (string, error) {
+func (c *Container) SendMessage(roomID string, msgtype mautrix.MessageType, text string) (string, error) {
defer debug.Recover()
c.SendTyping(roomID, false)
- resp, err := c.client.SendMessageEvent(roomID, gomatrix.EventMessage,
- gomatrix.Content{MsgType: msgtype, Body: text})
+ resp, err := c.client.SendMessageEvent(roomID, mautrix.EventMessage,
+ mautrix.Content{MsgType: msgtype, Body: text})
if err != nil {
return "", err
}
@@ -491,7 +499,7 @@ var roomRegex = regexp.MustCompile("\\[.+?]\\(https://matrix.to/#/(#.+?:[^/]+?)\
//
// If the given text contains markdown formatting symbols, it will be rendered into HTML before sending.
// Otherwise, it will be sent as plain text.
-func (c *Container) SendMarkdownMessage(roomID string, msgtype gomatrix.MessageType, text string) (string, error) {
+func (c *Container) SendMarkdownMessage(roomID string, msgtype mautrix.MessageType, text string) (string, error) {
defer debug.Recover()
html := c.renderMarkdown(text)
@@ -504,11 +512,11 @@ func (c *Container) SendMarkdownMessage(roomID string, msgtype gomatrix.MessageT
text = roomRegex.ReplaceAllString(text, "$1")
c.SendTyping(roomID, false)
- resp, err := c.client.SendMessageEvent(roomID, gomatrix.EventMessage,
- gomatrix.Content{
+ resp, err := c.client.SendMessageEvent(roomID, mautrix.EventMessage,
+ mautrix.Content{
MsgType: msgtype,
Body: text,
- Format: gomatrix.FormatHTML,
+ Format: mautrix.FormatHTML,
FormattedBody: html,
})
if err != nil {
@@ -560,7 +568,7 @@ func (c *Container) LeaveRoom(roomID string) error {
}
// GetHistory fetches room history.
-func (c *Container) GetHistory(roomID, prevBatch string, limit int) ([]*gomatrix.Event, string, error) {
+func (c *Container) GetHistory(roomID, prevBatch string, limit int) ([]*mautrix.Event, string, error) {
resp, err := c.client.Messages(roomID, prevBatch, "", 'b', limit)
if err != nil {
return nil, "", err
diff --git a/matrix/matrix_test.go b/matrix/matrix_test.go
index b6511ec..0d8bc3c 100644
--- a/matrix/matrix_test.go
+++ b/matrix/matrix_test.go
@@ -21,7 +21,7 @@ import (
"fmt"
"github.com/stretchr/testify/assert"
"io/ioutil"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"maunium.net/go/gomuks/config"
"net/http"
"os"
@@ -80,7 +80,7 @@ func TestContainer_SendMarkdownMessage_WithMarkdown(t *testing.T) {
}
func TestContainer_SendTyping(t *testing.T) {
- var calls []gomatrix.ReqTyping
+ var calls []mautrix.ReqTyping
c := Container{client: mockClient(func(req *http.Request) (*http.Response, error) {
if req.Method != http.MethodPut || req.URL.Path != "/_matrix/client/r0/rooms/!foo:example.com/typing/@user:example.com" {
return nil, fmt.Errorf("unexpected query: %s %s", req.Method, req.URL.Path)
@@ -91,7 +91,7 @@ func TestContainer_SendTyping(t *testing.T) {
return nil, err
}
- call := gomatrix.ReqTyping{}
+ call := mautrix.ReqTyping{}
err = json.Unmarshal(rawBody, &call)
if err != nil {
return nil, err
@@ -187,8 +187,8 @@ func TestContainer_GetHistory(t *testing.T) {
assert.Equal(t, "456", prevBatch)
}
-func mockClient(fn func(*http.Request) (*http.Response, error)) *gomatrix.Client {
- client, _ := gomatrix.NewClient("https://example.com", "@user:example.com", "foobar")
+func mockClient(fn func(*http.Request) (*http.Response, error)) *mautrix.Client {
+ client, _ := mautrix.NewClient("https://example.com", "@user:example.com", "foobar")
client.Client = &http.Client{Transport: MockRoundTripper{RT: fn}}
return client
}
diff --git a/matrix/pushrules/condition.go b/matrix/pushrules/condition.go
index 22d59aa..bacab56 100644
--- a/matrix/pushrules/condition.go
+++ b/matrix/pushrules/condition.go
@@ -21,14 +21,14 @@ import (
"strconv"
"strings"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"maunium.net/go/gomuks/lib/glob"
)
// Room is an interface with the functions that are needed for processing room-specific push conditions
type Room interface {
- GetMember(mxid string) *gomatrix.Member
- GetMembers() map[string]*gomatrix.Member
+ GetMember(mxid string) *mautrix.Member
+ GetMembers() map[string]*mautrix.Member
GetSessionOwner() string
}
@@ -59,7 +59,7 @@ type PushCondition struct {
var MemberCountFilterRegex = regexp.MustCompile("^(==|[<>]=?)?([0-9]+)$")
// Match checks if this condition is fulfilled for the given event in the given room.
-func (cond *PushCondition) Match(room Room, event *gomatrix.Event) bool {
+func (cond *PushCondition) Match(room Room, event *mautrix.Event) bool {
switch cond.Kind {
case KindEventMatch:
return cond.matchValue(room, event)
@@ -72,7 +72,7 @@ func (cond *PushCondition) Match(room Room, event *gomatrix.Event) bool {
}
}
-func (cond *PushCondition) matchValue(room Room, event *gomatrix.Event) bool {
+func (cond *PushCondition) matchValue(room Room, event *mautrix.Event) bool {
index := strings.IndexRune(cond.Key, '.')
key := cond.Key
subkey := ""
@@ -106,7 +106,7 @@ func (cond *PushCondition) matchValue(room Room, event *gomatrix.Event) bool {
}
}
-func (cond *PushCondition) matchDisplayName(room Room, event *gomatrix.Event) bool {
+func (cond *PushCondition) matchDisplayName(room Room, event *mautrix.Event) bool {
ownerID := room.GetSessionOwner()
if ownerID == event.Sender {
return false
@@ -115,7 +115,7 @@ func (cond *PushCondition) matchDisplayName(room Room, event *gomatrix.Event) bo
return strings.Contains(event.Content.Body, member.Displayname)
}
-func (cond *PushCondition) matchMemberCount(room Room, event *gomatrix.Event) bool {
+func (cond *PushCondition) matchMemberCount(room Room, event *mautrix.Event) bool {
group := MemberCountFilterRegex.FindStringSubmatch(cond.MemberCountCondition)
if len(group) != 3 {
return false
diff --git a/matrix/pushrules/condition_test.go b/matrix/pushrules/condition_test.go
index 7fd06ee..750f2c7 100644
--- a/matrix/pushrules/condition_test.go
+++ b/matrix/pushrules/condition_test.go
@@ -21,7 +21,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"maunium.net/go/gomuks/matrix/pushrules"
"maunium.net/go/gomuks/matrix/rooms"
)
@@ -30,7 +30,7 @@ var (
blankTestRoom *rooms.Room
displaynameTestRoom pushrules.Room
- countConditionTestEvent *gomatrix.Event
+ countConditionTestEvent *mautrix.Event
displaynamePushCondition *pushrules.PushCondition
)
@@ -38,7 +38,7 @@ var (
func init() {
blankTestRoom = rooms.NewRoom("!fakeroom:maunium.net", "@tulir:maunium.net")
- countConditionTestEvent = &gomatrix.Event{
+ countConditionTestEvent = &mautrix.Event{
Sender: "@tulir:maunium.net",
Type: "m.room.message",
Timestamp: 1523791120,
@@ -56,8 +56,8 @@ func init() {
}
}
-func newFakeEvent(evtType string, content map[string]interface{}) *gomatrix.Event {
- return &gomatrix.Event{
+func newFakeEvent(evtType string, content map[string]interface{}) *mautrix.Event {
+ return &mautrix.Event{
Sender: "@tulir:maunium.net",
Type: evtType,
Timestamp: 1523791120,
diff --git a/matrix/pushrules/pushrules.go b/matrix/pushrules/pushrules.go
index b383c66..643f2f2 100644
--- a/matrix/pushrules/pushrules.go
+++ b/matrix/pushrules/pushrules.go
@@ -4,16 +4,16 @@ import (
"encoding/json"
"net/url"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
)
// GetPushRules returns the push notification rules for the global scope.
-func GetPushRules(client *gomatrix.Client) (*PushRuleset, error) {
+func GetPushRules(client *mautrix.Client) (*PushRuleset, error) {
return GetScopedPushRules(client, "global")
}
// GetScopedPushRules returns the push notification rules for the given scope.
-func GetScopedPushRules(client *gomatrix.Client, scope string) (resp *PushRuleset, err error) {
+func GetScopedPushRules(client *mautrix.Client, scope string) (resp *PushRuleset, err error) {
u, _ := url.Parse(client.BuildURL("pushrules", scope))
// client.BuildURL returns the URL without a trailing slash, but the pushrules endpoint requires the slash.
u.Path += "/"
@@ -26,7 +26,7 @@ type contentWithRuleset struct {
}
// EventToPushRules converts a m.push_rules event to a PushRuleset by passing the data through JSON.
-func EventToPushRules(event *gomatrix.Event) (*PushRuleset, error) {
+func EventToPushRules(event *mautrix.Event) (*PushRuleset, error) {
content := &contentWithRuleset{}
err := json.Unmarshal(event.Content.VeryRaw, content)
if err != nil {
diff --git a/matrix/pushrules/pushrules_test.go b/matrix/pushrules/pushrules_test.go
index 09698ac..73fa787 100644
--- a/matrix/pushrules/pushrules_test.go
+++ b/matrix/pushrules/pushrules_test.go
@@ -21,7 +21,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"maunium.net/go/gomuks/matrix/pushrules"
)
@@ -33,7 +33,7 @@ func init() {
}
func TestEventToPushRules(t *testing.T) {
- event := &gomatrix.Event{
+ event := &mautrix.Event{
Type: "m.push_rules",
Timestamp: 1523380910,
Content: mapExamplePushRules,
diff --git a/matrix/pushrules/rule.go b/matrix/pushrules/rule.go
index 71f71e5..62318ac 100644
--- a/matrix/pushrules/rule.go
+++ b/matrix/pushrules/rule.go
@@ -18,7 +18,7 @@ package pushrules
import (
"encoding/gob"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"maunium.net/go/gomuks/lib/glob"
)
@@ -28,7 +28,7 @@ func init() {
}
type PushRuleCollection interface {
- GetActions(room Room, event *gomatrix.Event) PushActionArray
+ GetActions(room Room, event *mautrix.Event) PushActionArray
}
type PushRuleArray []*PushRule
@@ -40,7 +40,7 @@ func (rules PushRuleArray) SetType(typ PushRuleType) PushRuleArray {
return rules
}
-func (rules PushRuleArray) GetActions(room Room, event *gomatrix.Event) PushActionArray {
+func (rules PushRuleArray) GetActions(room Room, event *mautrix.Event) PushActionArray {
for _, rule := range rules {
if !rule.Match(room, event) {
continue
@@ -67,7 +67,7 @@ func (rules PushRuleArray) SetTypeAndMap(typ PushRuleType) PushRuleMap {
return data
}
-func (ruleMap PushRuleMap) GetActions(room Room, event *gomatrix.Event) PushActionArray {
+func (ruleMap PushRuleMap) GetActions(room Room, event *mautrix.Event) PushActionArray {
var rule *PushRule
var found bool
switch ruleMap.Type {
@@ -122,7 +122,7 @@ type PushRule struct {
Pattern string `json:"pattern,omitempty"`
}
-func (rule *PushRule) Match(room Room, event *gomatrix.Event) bool {
+func (rule *PushRule) Match(room Room, event *mautrix.Event) bool {
if !rule.Enabled {
return false
}
@@ -140,7 +140,7 @@ func (rule *PushRule) Match(room Room, event *gomatrix.Event) bool {
}
}
-func (rule *PushRule) matchConditions(room Room, event *gomatrix.Event) bool {
+func (rule *PushRule) matchConditions(room Room, event *mautrix.Event) bool {
for _, cond := range rule.Conditions {
if !cond.Match(room, event) {
return false
@@ -149,7 +149,7 @@ func (rule *PushRule) matchConditions(room Room, event *gomatrix.Event) bool {
return true
}
-func (rule *PushRule) matchPattern(room Room, event *gomatrix.Event) bool {
+func (rule *PushRule) matchPattern(room Room, event *mautrix.Event) bool {
pattern, err := glob.Compile(rule.Pattern)
if err != nil {
return false
diff --git a/matrix/pushrules/ruleset.go b/matrix/pushrules/ruleset.go
index 940025f..366702e 100644
--- a/matrix/pushrules/ruleset.go
+++ b/matrix/pushrules/ruleset.go
@@ -19,7 +19,7 @@ package pushrules
import (
"encoding/json"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
)
type PushRuleset struct {
@@ -80,7 +80,7 @@ var DefaultPushActions = make(PushActionArray, 0)
// GetActions matches the given event against all of the push rule
// collections in this push ruleset in the order of priority as
// specified in spec section 11.12.1.4.
-func (rs *PushRuleset) GetActions(room Room, event *gomatrix.Event) (match PushActionArray) {
+func (rs *PushRuleset) GetActions(room Room, event *mautrix.Event) (match PushActionArray) {
// Add push rule collections to array in priority order
arrays := []PushRuleCollection{rs.Override, rs.Content, rs.Room, rs.Sender, rs.Underride}
// Loop until one of the push rule collections matches the room/event combo.
diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go
index bd233f8..72251c4 100644
--- a/matrix/rooms/room.go
+++ b/matrix/rooms/room.go
@@ -23,7 +23,7 @@ import (
"time"
"encoding/gob"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"maunium.net/go/gomuks/debug"
"os"
)
@@ -58,7 +58,7 @@ type UnreadMessage struct {
// Room represents a single Matrix room.
type Room struct {
- *gomatrix.Room
+ *mautrix.Room
// Whether or not the user has left the room.
HasLeft bool
@@ -82,10 +82,10 @@ type Room struct {
LastReceivedMessage time.Time
// MXID -> Member cache calculated from membership events.
- memberCache map[string]*gomatrix.Member
+ memberCache map[string]*mautrix.Member
// The first non-SessionUserID member in the room. Calculated at
// the same time as memberCache.
- firstMemberCache *gomatrix.Member
+ firstMemberCache *mautrix.Member
// The name of the room. Calculated from the state event name,
// canonical_alias or alias or the member cache.
nameCache string
@@ -216,31 +216,31 @@ func (room *Room) Tags() []RoomTag {
// UpdateState updates the room's current state with the given Event. This will clobber events based
// on the type/state_key combination.
-func (room *Room) UpdateState(event *gomatrix.Event) {
+func (room *Room) UpdateState(event *mautrix.Event) {
_, exists := room.State[event.Type]
if !exists {
- room.State[event.Type] = make(map[string]*gomatrix.Event)
+ room.State[event.Type] = make(map[string]*mautrix.Event)
}
switch event.Type {
- case gomatrix.StateRoomName:
+ case mautrix.StateRoomName:
room.nameCache = ""
- case gomatrix.StateCanonicalAlias:
+ case mautrix.StateCanonicalAlias:
if room.nameCacheSource >= CanonicalAliasRoomName {
room.nameCache = ""
}
room.canonicalAliasCache = ""
- case gomatrix.StateAliases:
+ case mautrix.StateAliases:
if room.nameCacheSource >= AliasRoomName {
room.nameCache = ""
}
room.aliasesCache = nil
- case gomatrix.StateMember:
+ case mautrix.StateMember:
room.memberCache = nil
room.firstMemberCache = nil
if room.nameCacheSource >= MemberRoomName {
room.nameCache = ""
}
- case gomatrix.StateTopic:
+ case mautrix.StateTopic:
room.topicCache = ""
}
@@ -248,7 +248,7 @@ func (room *Room) UpdateState(event *gomatrix.Event) {
if event.StateKey != nil {
stateKey = *event.StateKey
}
- if event.Type != gomatrix.StateMember {
+ if event.Type != mautrix.StateMember {
debug.Printf("Updating state %s#%s for %s", event.Type, stateKey, room.ID)
}
@@ -260,14 +260,14 @@ func (room *Room) UpdateState(event *gomatrix.Event) {
}
// GetStateEvent returns the state event for the given type/state_key combo, or nil.
-func (room *Room) GetStateEvent(eventType gomatrix.EventType, stateKey string) *gomatrix.Event {
+func (room *Room) GetStateEvent(eventType mautrix.EventType, stateKey string) *mautrix.Event {
stateEventMap, _ := room.State[eventType]
event, _ := stateEventMap[stateKey]
return event
}
// GetStateEvents returns the state events for the given type.
-func (room *Room) GetStateEvents(eventType gomatrix.EventType) map[string]*gomatrix.Event {
+func (room *Room) GetStateEvents(eventType mautrix.EventType) map[string]*mautrix.Event {
stateEventMap, _ := room.State[eventType]
return stateEventMap
}
@@ -275,7 +275,7 @@ func (room *Room) GetStateEvents(eventType gomatrix.EventType) map[string]*gomat
// GetTopic returns the topic of the room.
func (room *Room) GetTopic() string {
if len(room.topicCache) == 0 {
- topicEvt := room.GetStateEvent(gomatrix.StateTopic, "")
+ topicEvt := room.GetStateEvent(mautrix.StateTopic, "")
if topicEvt != nil {
room.topicCache = topicEvt.Content.Topic
}
@@ -285,7 +285,7 @@ func (room *Room) GetTopic() string {
func (room *Room) GetCanonicalAlias() string {
if len(room.canonicalAliasCache) == 0 {
- canonicalAliasEvt := room.GetStateEvent(gomatrix.StateCanonicalAlias, "")
+ canonicalAliasEvt := room.GetStateEvent(mautrix.StateCanonicalAlias, "")
if canonicalAliasEvt != nil {
room.canonicalAliasCache = canonicalAliasEvt.Content.Alias
} else {
@@ -301,7 +301,7 @@ func (room *Room) GetCanonicalAlias() string {
// GetAliases returns the list of aliases that point to this room.
func (room *Room) GetAliases() []string {
if room.aliasesCache == nil {
- aliasEvents := room.GetStateEvents(gomatrix.StateAliases)
+ aliasEvents := room.GetStateEvents(mautrix.StateAliases)
room.aliasesCache = []string{}
for _, event := range aliasEvents {
room.aliasesCache = append(room.aliasesCache, event.Content.Aliases...)
@@ -312,7 +312,7 @@ func (room *Room) GetAliases() []string {
// updateNameFromNameEvent updates the room display name to be the name set in the name event.
func (room *Room) updateNameFromNameEvent() {
- nameEvt := room.GetStateEvent(gomatrix.StateRoomName, "")
+ nameEvt := room.GetStateEvent(mautrix.StateRoomName, "")
if nameEvt != nil {
room.nameCache = nameEvt.Content.Name
}
@@ -384,9 +384,9 @@ func (room *Room) GetTitle() string {
}
// createMemberCache caches all member events into a easily processable MXID -> *Member map.
-func (room *Room) createMemberCache() map[string]*gomatrix.Member {
- cache := make(map[string]*gomatrix.Member)
- events := room.GetStateEvents(gomatrix.StateMember)
+func (room *Room) createMemberCache() map[string]*mautrix.Member {
+ cache := make(map[string]*mautrix.Member)
+ events := room.GetStateEvents(mautrix.StateMember)
room.firstMemberCache = nil
if events != nil {
for userID, event := range events {
@@ -407,7 +407,7 @@ func (room *Room) createMemberCache() map[string]*gomatrix.Member {
//
// The members are returned from the cache.
// If the cache is empty, it is updated first.
-func (room *Room) GetMembers() map[string]*gomatrix.Member {
+func (room *Room) GetMembers() map[string]*mautrix.Member {
if len(room.memberCache) == 0 || room.firstMemberCache == nil {
room.createMemberCache()
}
@@ -416,7 +416,7 @@ func (room *Room) GetMembers() map[string]*gomatrix.Member {
// GetMember returns the member with the given MXID.
// If the member doesn't exist, nil is returned.
-func (room *Room) GetMember(userID string) *gomatrix.Member {
+func (room *Room) GetMember(userID string) *mautrix.Member {
if len(room.memberCache) == 0 {
room.createMemberCache()
}
@@ -432,7 +432,7 @@ func (room *Room) GetSessionOwner() string {
// NewRoom creates a new Room with the given ID
func NewRoom(roomID, owner string) *Room {
return &Room{
- Room: gomatrix.NewRoom(roomID),
+ Room: mautrix.NewRoom(roomID),
fetchHistoryLock: &sync.Mutex{},
SessionUserID: owner,
}
diff --git a/matrix/rooms/room_test.go b/matrix/rooms/room_test.go
index 1fabdcc..db7f586 100644
--- a/matrix/rooms/room_test.go
+++ b/matrix/rooms/room_test.go
@@ -21,7 +21,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"maunium.net/go/gomuks/matrix/rooms"
)
@@ -39,7 +39,7 @@ func TestNewRoom_DefaultValues(t *testing.T) {
func TestRoom_GetCanonicalAlias(t *testing.T) {
room := rooms.NewRoom("!test:maunium.net", "@tulir:maunium.net")
- room.UpdateState(&gomatrix.Event{
+ room.UpdateState(&mautrix.Event{
Type: "m.room.canonical_alias",
Content: map[string]interface{}{
"alias": "#foo:maunium.net",
@@ -50,7 +50,7 @@ func TestRoom_GetCanonicalAlias(t *testing.T) {
func TestRoom_GetTopic(t *testing.T) {
room := rooms.NewRoom("!test:maunium.net", "@tulir:maunium.net")
- room.UpdateState(&gomatrix.Event{
+ room.UpdateState(&mautrix.Event{
Type: "m.room.topic",
Content: map[string]interface{}{
"topic": "test topic",
@@ -87,7 +87,7 @@ func TestRoom_GetAliases(t *testing.T) {
}
func addName(room *rooms.Room) {
- room.UpdateState(&gomatrix.Event{
+ room.UpdateState(&mautrix.Event{
Type: "m.room.name",
Content: map[string]interface{}{
"name": "Test room",
@@ -96,7 +96,7 @@ func addName(room *rooms.Room) {
}
func addCanonicalAlias(room *rooms.Room) {
- room.UpdateState(&gomatrix.Event{
+ room.UpdateState(&mautrix.Event{
Type: "m.room.canonical_alias",
Content: map[string]interface{}{
"alias": "#foo:maunium.net",
@@ -106,7 +106,7 @@ func addCanonicalAlias(room *rooms.Room) {
func addAliases(room *rooms.Room) {
server1 := "maunium.net"
- room.UpdateState(&gomatrix.Event{
+ room.UpdateState(&mautrix.Event{
Type: "m.room.aliases",
StateKey: &server1,
Content: map[string]interface{}{
@@ -115,7 +115,7 @@ func addAliases(room *rooms.Room) {
})
server2 := "matrix.org"
- room.UpdateState(&gomatrix.Event{
+ room.UpdateState(&mautrix.Event{
Type: "m.room.aliases",
StateKey: &server2,
Content: map[string]interface{}{
@@ -126,7 +126,7 @@ func addAliases(room *rooms.Room) {
func addMembers(room *rooms.Room, count int) {
user1 := "@tulir:maunium.net"
- room.UpdateState(&gomatrix.Event{
+ room.UpdateState(&mautrix.Event{
Type: "m.room.member",
StateKey: &user1,
Content: map[string]interface{}{
@@ -146,7 +146,7 @@ func addMembers(room *rooms.Room, count int) {
if i%5 == 0 {
content["membership"] = "invite"
}
- room.UpdateState(&gomatrix.Event{
+ room.UpdateState(&mautrix.Event{
Type: "m.room.member",
StateKey: &userN,
Content: content,
diff --git a/matrix/sync.go b/matrix/sync.go
index 6d5def7..06c7f47 100644
--- a/matrix/sync.go
+++ b/matrix/sync.go
@@ -14,15 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
-// Based on https://github.com/matrix-org/gomatrix/blob/master/sync.go
+// Based on https://github.com/matrix-org/mautrix/blob/master/sync.go
package matrix
import (
"encoding/json"
+ "maunium.net/go/gomuks/debug"
"time"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"maunium.net/go/gomuks/matrix/rooms"
)
@@ -44,14 +45,14 @@ const (
EventSourceEphemeral
)
-type EventHandler func(source EventSource, event *gomatrix.Event)
+type EventHandler func(source EventSource, event *mautrix.Event)
// GomuksSyncer is the default syncing implementation. You can either write your own syncer, or selectively
// replace parts of this default syncer (e.g. the ProcessResponse method). The default syncer uses the observer
// pattern to notify callers about incoming events. See GomuksSyncer.OnEventType for more information.
type GomuksSyncer struct {
Session SyncerSession
- listeners map[gomatrix.EventType][]EventHandler // event type to listeners array
+ listeners map[mautrix.EventType][]EventHandler // event type to listeners array
FirstSyncDone bool
InitDoneCallback func()
}
@@ -60,13 +61,14 @@ type GomuksSyncer struct {
func NewGomuksSyncer(session SyncerSession) *GomuksSyncer {
return &GomuksSyncer{
Session: session,
- listeners: make(map[gomatrix.EventType][]EventHandler),
+ listeners: make(map[mautrix.EventType][]EventHandler),
FirstSyncDone: false,
}
}
// ProcessResponse processes a Matrix sync response.
-func (s *GomuksSyncer) ProcessResponse(res *gomatrix.RespSync, since string) (err error) {
+func (s *GomuksSyncer) ProcessResponse(res *mautrix.RespSync, since string) (err error) {
+ debug.Print("Received sync response")
s.processSyncEvents(nil, res.Presence.Events, EventSourcePresence, false)
s.processSyncEvents(nil, res.AccountData.Events, EventSourceAccountData, false)
@@ -106,7 +108,7 @@ func (s *GomuksSyncer) ProcessResponse(res *gomatrix.RespSync, since string) (er
return
}
-func (s *GomuksSyncer) processSyncEvents(room *rooms.Room, events []*gomatrix.Event, source EventSource, checkStateKey bool) {
+func (s *GomuksSyncer) processSyncEvents(room *rooms.Room, events []*mautrix.Event, source EventSource, checkStateKey bool) {
for _, event := range events {
if !checkStateKey || event.StateKey != nil {
s.processSyncEvent(room, event, source)
@@ -114,11 +116,11 @@ func (s *GomuksSyncer) processSyncEvents(room *rooms.Room, events []*gomatrix.Ev
}
}
-func (s *GomuksSyncer) processSyncEvent(room *rooms.Room, event *gomatrix.Event, source EventSource) {
+func (s *GomuksSyncer) processSyncEvent(room *rooms.Room, event *mautrix.Event, source EventSource) {
if room != nil {
event.RoomID = room.ID
}
- if event.Type.Class == gomatrix.StateEventType {
+ if event.Type.Class == mautrix.StateEventType {
room.UpdateState(event)
}
s.notifyListeners(source, event)
@@ -126,7 +128,7 @@ func (s *GomuksSyncer) processSyncEvent(room *rooms.Room, event *gomatrix.Event,
// OnEventType allows callers to be notified when there are new events for the given event type.
// There are no duplicate checks.
-func (s *GomuksSyncer) OnEventType(eventType gomatrix.EventType, callback EventHandler) {
+func (s *GomuksSyncer) OnEventType(eventType mautrix.EventType, callback EventHandler) {
_, exists := s.listeners[eventType]
if !exists {
s.listeners[eventType] = []EventHandler{}
@@ -134,7 +136,7 @@ func (s *GomuksSyncer) OnEventType(eventType gomatrix.EventType, callback EventH
s.listeners[eventType] = append(s.listeners[eventType], callback)
}
-func (s *GomuksSyncer) notifyListeners(source EventSource, event *gomatrix.Event) {
+func (s *GomuksSyncer) notifyListeners(source EventSource, event *mautrix.Event) {
listeners, exists := s.listeners[event.Type]
if !exists {
return
@@ -145,16 +147,17 @@ func (s *GomuksSyncer) notifyListeners(source EventSource, event *gomatrix.Event
}
// OnFailedSync always returns a 10 second wait period between failed /syncs, never a fatal error.
-func (s *GomuksSyncer) OnFailedSync(res *gomatrix.RespSync, err error) (time.Duration, error) {
+func (s *GomuksSyncer) OnFailedSync(res *mautrix.RespSync, err error) (time.Duration, error) {
+ debug.Printf("Sync failed: %v", err)
return 10 * time.Second, nil
}
// GetFilterJSON returns a filter with a timeline limit of 50.
func (s *GomuksSyncer) GetFilterJSON(userID string) json.RawMessage {
- filter := &gomatrix.Filter{
- Room: gomatrix.RoomFilter{
+ filter := &mautrix.Filter{
+ Room: mautrix.RoomFilter{
IncludeLeave: false,
- State: gomatrix.FilterPart{
+ State: mautrix.FilterPart{
Types: []string{
"m.room.member",
"m.room.name",
@@ -163,21 +166,21 @@ func (s *GomuksSyncer) GetFilterJSON(userID string) json.RawMessage {
"m.room.aliases",
},
},
- Timeline: gomatrix.FilterPart{
+ Timeline: mautrix.FilterPart{
Types: []string{"m.room.message", "m.room.member"},
Limit: 50,
},
- Ephemeral: gomatrix.FilterPart{
+ Ephemeral: mautrix.FilterPart{
Types: []string{"m.typing", "m.receipt"},
},
- AccountData: gomatrix.FilterPart{
+ AccountData: mautrix.FilterPart{
Types: []string{"m.tag"},
},
},
- AccountData: gomatrix.FilterPart{
+ AccountData: mautrix.FilterPart{
Types: []string{"m.push_rules", "m.direct", "net.maunium.gomuks.preferences"},
},
- Presence: gomatrix.FilterPart{
+ Presence: mautrix.FilterPart{
Types: []string{},
},
}
diff --git a/matrix/sync_test.go b/matrix/sync_test.go
index 49bbcb0..79cb11b 100644
--- a/matrix/sync_test.go
+++ b/matrix/sync_test.go
@@ -20,7 +20,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
- "maunium.net/go/gomatrix"
+ "maunium.net/go/mautrix"
"maunium.net/go/gomuks/matrix"
"maunium.net/go/gomuks/matrix/rooms"
)
@@ -42,13 +42,13 @@ func TestGomuksSyncer_ProcessResponse(t *testing.T) {
userID: "@tulir:maunium.net",
rooms: map[string]*rooms.Room{
"!foo:maunium.net": {
- Room: gomatrix.NewRoom("!foo:maunium.net"),
+ Room: mautrix.NewRoom("!foo:maunium.net"),
},
"!bar:maunium.net": {
- Room: gomatrix.NewRoom("!bar:maunium.net"),
+ Room: mautrix.NewRoom("!bar:maunium.net"),
},
"!test:maunium.net": {
- Room: gomatrix.NewRoom("!test:maunium.net"),
+ Room: mautrix.NewRoom("!test:maunium.net"),
},
},
}
@@ -58,7 +58,7 @@ func TestGomuksSyncer_ProcessResponse(t *testing.T) {
syncer.OnEventType("m.room.message", ml.receive)
syncer.GetFilterJSON("@tulir:maunium.net")
- joinEvt := &gomatrix.Event{
+ joinEvt := &mautrix.Event{
ID: "!join:maunium.net",
Type: "m.room.member",
Sender: "@tulir:maunium.net",
@@ -67,7 +67,7 @@ func TestGomuksSyncer_ProcessResponse(t *testing.T) {
"membership": "join",
},
}
- messageEvt := &gomatrix.Event{
+ messageEvt := &mautrix.Event{
ID: "!msg:maunium.net",
Type: "m.room.message",
Content: map[string]interface{}{
@@ -75,11 +75,11 @@ func TestGomuksSyncer_ProcessResponse(t *testing.T) {
"msgtype": "m.text",
},
}
- unhandledEvt := &gomatrix.Event{
+ unhandledEvt := &mautrix.Event{
ID: "!unhandled:maunium.net",
Type: "m.room.unhandled_event",
}
- inviteEvt := &gomatrix.Event{
+ inviteEvt := &mautrix.Event{
ID: "!invite:matrix.org",
Type: "m.room.member",
Sender: "@you:matrix.org",
@@ -88,7 +88,7 @@ func TestGomuksSyncer_ProcessResponse(t *testing.T) {
"membership": "invite",
},
}
- leaveEvt := &gomatrix.Event{
+ leaveEvt := &mautrix.Event{
ID: "!leave:matrix.org",
Type: "m.room.member",
Sender: "@you:matrix.org",
@@ -100,27 +100,27 @@ func TestGomuksSyncer_ProcessResponse(t *testing.T) {
resp := newRespSync()
resp.Rooms.Join["!foo:maunium.net"] = join{
- State: events{Events: []*gomatrix.Event{joinEvt}},
- Timeline: timeline{Events: []*gomatrix.Event{messageEvt, unhandledEvt}},
+ State: events{Events: []*mautrix.Event{joinEvt}},
+ Timeline: timeline{Events: []*mautrix.Event{messageEvt, unhandledEvt}},
}
resp.Rooms.Invite["!bar:maunium.net"] = struct {
State struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
} `json:"invite_state"`
}{
- State: events{Events: []*gomatrix.Event{inviteEvt}},
+ State: events{Events: []*mautrix.Event{inviteEvt}},
}
resp.Rooms.Leave["!test:maunium.net"] = struct {
State struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
} `json:"state"`
Timeline struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
Limited bool `json:"limited"`
PrevBatch string `json:"prev_batch"`
} `json:"timeline"`
}{
- State: events{Events: []*gomatrix.Event{leaveEvt}},
+ State: events{Events: []*mautrix.Event{leaveEvt}},
}
syncer.ProcessResponse(resp, "since")
@@ -145,28 +145,28 @@ func (mss *mockSyncerSession) GetUserID() string {
}
type events struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
}
type timeline struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
Limited bool `json:"limited"`
PrevBatch string `json:"prev_batch"`
}
type join struct {
State struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
} `json:"state"`
Timeline struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
Limited bool `json:"limited"`
PrevBatch string `json:"prev_batch"`
} `json:"timeline"`
Ephemeral struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
} `json:"ephemeral"`
AccountData struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
} `json:"account_data"`
}
@@ -175,42 +175,42 @@ func ptr(text string) *string {
}
type mockListener struct {
- received []*gomatrix.Event
+ received []*mautrix.Event
}
-func (ml *mockListener) receive(source matrix.EventSource, evt *gomatrix.Event) {
+func (ml *mockListener) receive(source matrix.EventSource, evt *mautrix.Event) {
ml.received = append(ml.received, evt)
}
-func newRespSync() *gomatrix.RespSync {
- resp := &gomatrix.RespSync{NextBatch: "123"}
+func newRespSync() *mautrix.RespSync {
+ resp := &mautrix.RespSync{NextBatch: "123"}
resp.Rooms.Join = make(map[string]struct {
State struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
} `json:"state"`
Timeline struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
Limited bool `json:"limited"`
PrevBatch string `json:"prev_batch"`
} `json:"timeline"`
Ephemeral struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
} `json:"ephemeral"`
AccountData struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
} `json:"account_data"`
})
resp.Rooms.Invite = make(map[string]struct {
State struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
} `json:"invite_state"`
})
resp.Rooms.Leave = make(map[string]struct {
State struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
} `json:"state"`
Timeline struct {
- Events []*gomatrix.Event `json:"events"`
+ Events []*mautrix.Event `json:"events"`
Limited bool `json:"limited"`
PrevBatch string `json:"prev_batch"`
} `json:"timeline"`
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 %[1]s
%[2]s
%[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)
}
}
}
diff --git a/vendor/golang.org/x/image/bmp/reader.go b/vendor/golang.org/x/image/bmp/reader.go
index a0f2715..c10a022 100644
--- a/vendor/golang.org/x/image/bmp/reader.go
+++ b/vendor/golang.org/x/image/bmp/reader.go
@@ -137,20 +137,26 @@ func decodeConfig(r io.Reader) (config image.Config, bitsPerPixel int, topDown b
// We only support those BMP images that are a BITMAPFILEHEADER
// immediately followed by a BITMAPINFOHEADER.
const (
- fileHeaderLen = 14
- infoHeaderLen = 40
+ fileHeaderLen = 14
+ infoHeaderLen = 40
+ v4InfoHeaderLen = 108
+ v5InfoHeaderLen = 124
)
var b [1024]byte
- if _, err := io.ReadFull(r, b[:fileHeaderLen+infoHeaderLen]); err != nil {
+ if _, err := io.ReadFull(r, b[:fileHeaderLen+4]); err != nil {
return image.Config{}, 0, false, err
}
if string(b[:2]) != "BM" {
return image.Config{}, 0, false, errors.New("bmp: invalid format")
}
offset := readUint32(b[10:14])
- if readUint32(b[14:18]) != infoHeaderLen {
+ infoLen := readUint32(b[14:18])
+ if infoLen != infoHeaderLen && infoLen != v4InfoHeaderLen && infoLen != v5InfoHeaderLen {
return image.Config{}, 0, false, ErrUnsupported
}
+ if _, err := io.ReadFull(r, b[fileHeaderLen+4:fileHeaderLen+infoLen]); err != nil {
+ return image.Config{}, 0, false, err
+ }
width := int(int32(readUint32(b[18:22])))
height := int(int32(readUint32(b[22:26])))
if height < 0 {
@@ -159,14 +165,22 @@ func decodeConfig(r io.Reader) (config image.Config, bitsPerPixel int, topDown b
if width < 0 || height < 0 {
return image.Config{}, 0, false, ErrUnsupported
}
- // We only support 1 plane, 8 or 24 bits per pixel and no compression.
+ // We only support 1 plane and 8, 24 or 32 bits per pixel and no
+ // compression.
planes, bpp, compression := readUint16(b[26:28]), readUint16(b[28:30]), readUint32(b[30:34])
+ // if compression is set to BITFIELDS, but the bitmask is set to the default bitmask
+ // that would be used if compression was set to 0, we can continue as if compression was 0
+ if compression == 3 && infoLen > infoHeaderLen &&
+ readUint32(b[54:58]) == 0xff0000 && readUint32(b[58:62]) == 0xff00 &&
+ readUint32(b[62:66]) == 0xff && readUint32(b[66:70]) == 0xff000000 {
+ compression = 0
+ }
if planes != 1 || compression != 0 {
return image.Config{}, 0, false, ErrUnsupported
}
switch bpp {
case 8:
- if offset != fileHeaderLen+infoHeaderLen+256*4 {
+ if offset != fileHeaderLen+infoLen+256*4 {
return image.Config{}, 0, false, ErrUnsupported
}
_, err = io.ReadFull(r, b[:256*4])
@@ -181,12 +195,12 @@ func decodeConfig(r io.Reader) (config image.Config, bitsPerPixel int, topDown b
}
return image.Config{ColorModel: pcm, Width: width, Height: height}, 8, topDown, nil
case 24:
- if offset != fileHeaderLen+infoHeaderLen {
+ if offset != fileHeaderLen+infoLen {
return image.Config{}, 0, false, ErrUnsupported
}
return image.Config{ColorModel: color.RGBAModel, Width: width, Height: height}, 24, topDown, nil
case 32:
- if offset != fileHeaderLen+infoHeaderLen {
+ if offset != fileHeaderLen+infoLen {
return image.Config{}, 0, false, ErrUnsupported
}
return image.Config{ColorModel: color.RGBAModel, Width: width, Height: height}, 32, topDown, nil
diff --git a/vendor/golang.org/x/image/tiff/reader.go b/vendor/golang.org/x/image/tiff/reader.go
index 8a941c1..ce2ef71 100644
--- a/vendor/golang.org/x/image/tiff/reader.go
+++ b/vendor/golang.org/x/image/tiff/reader.go
@@ -110,7 +110,7 @@ func (d *decoder) ifdUint(p []byte) (u []uint, err error) {
return u, nil
}
-// parseIFD decides whether the the IFD entry in p is "interesting" and
+// parseIFD decides whether the IFD entry in p is "interesting" and
// stows away the data in the decoder. It returns the tag number of the
// entry and an error, if any.
func (d *decoder) parseIFD(p []byte) (int, error) {
diff --git a/vendor/golang.org/x/image/vp8/decode.go b/vendor/golang.org/x/image/vp8/decode.go
index 1bb5028..2aa9fee 100644
--- a/vendor/golang.org/x/image/vp8/decode.go
+++ b/vendor/golang.org/x/image/vp8/decode.go
@@ -82,7 +82,7 @@ type mb struct {
pred [4]uint8
// nzMask is a mask of 8 bits: 4 for the bottom or right 4x4 luma regions,
// and 2 + 2 for the bottom or right 4x4 chroma regions. A 1 bit indicates
- // that that region has non-zero coefficients.
+ // that region has non-zero coefficients.
nzMask uint8
// nzY16 is a 0/1 value that is 1 if the macroblock used Y16 prediction and
// had non-zero coefficients.
@@ -274,7 +274,7 @@ func (d *Decoder) parseOtherPartitions() error {
var partLens [maxNOP]int
d.nOP = 1 << d.fp.readUint(uniformProb, 2)
- // The final partition length is implied by the the remaining chunk data
+ // The final partition length is implied by the remaining chunk data
// (d.r.n) and the other d.nOP-1 partition lengths. Those d.nOP-1 partition
// lengths are stored as 24-bit uints, i.e. up to 16 MiB per partition.
n := 3 * (d.nOP - 1)
diff --git a/vendor/golang.org/x/image/webp/decode.go b/vendor/golang.org/x/image/webp/decode.go
index 111f358..f77a4eb 100644
--- a/vendor/golang.org/x/image/webp/decode.go
+++ b/vendor/golang.org/x/image/webp/decode.go
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build go1.6
-
package webp
import (
diff --git a/vendor/golang.org/x/image/webp/doc.go b/vendor/golang.org/x/image/webp/doc.go
new file mode 100644
index 0000000..e321c85
--- /dev/null
+++ b/vendor/golang.org/x/image/webp/doc.go
@@ -0,0 +1,9 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package webp implements a decoder for WEBP images.
+//
+// WEBP is defined at:
+// https://developers.google.com/speed/webp/docs/riff_container
+package webp // import "golang.org/x/image/webp"
diff --git a/vendor/golang.org/x/image/webp/webp.go b/vendor/golang.org/x/image/webp/webp.go
deleted file mode 100644
index 850cdc8..0000000
--- a/vendor/golang.org/x/image/webp/webp.go
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package webp implements a decoder for WEBP images.
-//
-// WEBP is defined at:
-// https://developers.google.com/speed/webp/docs/riff_container
-//
-// It requires Go 1.6 or later.
-package webp // import "golang.org/x/image/webp"
-
-// This blank Go file, other than the package clause, exists so that this
-// package can be built for Go 1.5 and earlier. (The other files in this
-// package are all marked "+build go1.6" for the NYCbCrA types introduced in Go
-// 1.6). There is no functionality in a blank package, but some image
-// manipulation programs might still underscore import this package for the
-// side effect of registering the WEBP format with the standard library's
-// image.RegisterFormat and image.Decode functions. For example, that program
-// might contain:
-//
-// // Underscore imports to register some formats for image.Decode.
-// import _ "image/gif"
-// import _ "image/jpeg"
-// import _ "image/png"
-// import _ "golang.org/x/image/webp"
-//
-// Such a program will still compile for Go 1.5 (due to this placeholder Go
-// file). It will simply not be able to recognize and decode WEBP (but still
-// handle GIF, JPEG and PNG).
diff --git a/vendor/golang.org/x/net/html/const.go b/vendor/golang.org/x/net/html/const.go
index 5eb7c5a..a3a918f 100644
--- a/vendor/golang.org/x/net/html/const.go
+++ b/vendor/golang.org/x/net/html/const.go
@@ -97,8 +97,16 @@ func isSpecialElement(element *Node) bool {
switch element.Namespace {
case "", "html":
return isSpecialElementMap[element.Data]
+ case "math":
+ switch element.Data {
+ case "mi", "mo", "mn", "ms", "mtext", "annotation-xml":
+ return true
+ }
case "svg":
- return element.Data == "foreignObject"
+ switch element.Data {
+ case "foreignObject", "desc", "title":
+ return true
+ }
}
return false
}
diff --git a/vendor/golang.org/x/net/html/parse.go b/vendor/golang.org/x/net/html/parse.go
index 4b1fa42..64a5793 100644
--- a/vendor/golang.org/x/net/html/parse.go
+++ b/vendor/golang.org/x/net/html/parse.go
@@ -470,6 +470,10 @@ func (p *parser) resetInsertionMode() {
case a.Table:
p.im = inTableIM
case a.Template:
+ // TODO: remove this divergence from the HTML5 spec.
+ if n.Namespace != "" {
+ continue
+ }
p.im = p.templateStack.top()
case a.Head:
// TODO: remove this divergence from the HTML5 spec.
@@ -984,6 +988,14 @@ func inBodyIM(p *parser) bool {
p.acknowledgeSelfClosingTag()
p.popUntil(buttonScope, a.P)
p.parseImpliedToken(StartTagToken, a.Form, a.Form.String())
+ if p.form == nil {
+ // NOTE: The 'isindex' element has been removed,
+ // and the 'template' element has not been designed to be
+ // collaborative with the index element.
+ //
+ // Ignore the token.
+ return true
+ }
if action != "" {
p.form.Attr = []Attribute{{Key: "action", Val: action}}
}
@@ -1252,12 +1264,6 @@ func (p *parser) inBodyEndTagFormatting(tagAtom a.Atom) {
switch commonAncestor.DataAtom {
case a.Table, a.Tbody, a.Tfoot, a.Thead, a.Tr:
p.fosterParent(lastNode)
- case a.Template:
- // TODO: remove namespace checking
- if commonAncestor.Namespace == "html" {
- commonAncestor = commonAncestor.LastChild
- }
- fallthrough
default:
commonAncestor.AppendChild(lastNode)
}
@@ -2209,6 +2215,15 @@ func (p *parser) parse() error {
}
// Parse returns the parse tree for the HTML from the given Reader.
+//
+// It implements the HTML5 parsing algorithm
+// (https://html.spec.whatwg.org/multipage/syntax.html#tree-construction),
+// which is very complicated. The resultant tree can contain implicitly created
+// nodes that have no explicit listed in r's data, and nodes' parents can
+// differ from the nesting implied by a naive processing of start and end
+// s. Conversely, explicit s in r's data can be silently dropped,
+// with no corresponding node in the resulting tree.
+//
// The input is assumed to be UTF-8 encoded.
func Parse(r io.Reader) (*Node, error) {
p := &parser{
@@ -2230,6 +2245,8 @@ func Parse(r io.Reader) (*Node, error) {
// ParseFragment parses a fragment of HTML and returns the nodes that were
// found. If the fragment is the InnerHTML for an existing element, pass that
// element in context.
+//
+// It has the same intricacies as Parse.
func ParseFragment(r io.Reader, context *Node) ([]*Node, error) {
contextTag := ""
if context != nil {
diff --git a/vendor/gopkg.in/russross/blackfriday.v2/.travis.yml b/vendor/gopkg.in/russross/blackfriday.v2/.travis.yml
index a4eb257..b0b525a 100644
--- a/vendor/gopkg.in/russross/blackfriday.v2/.travis.yml
+++ b/vendor/gopkg.in/russross/blackfriday.v2/.travis.yml
@@ -1,18 +1,17 @@
-# Travis CI (http://travis-ci.org/) is a continuous integration service for
-# open source projects. This file configures it to run unit tests for
-# blackfriday.
-
+sudo: false
language: go
-
go:
- - 1.5
- - 1.6
- - 1.7
-
+ - "1.10.x"
+ - "1.11.x"
+ - tip
+matrix:
+ fast_finish: true
+ allow_failures:
+ - go: tip
install:
- - go get -d -t -v ./...
- - go build -v ./...
-
+ - # Do nothing. This is needed to prevent default install action "go get -t -v ./..." from happening here (we want it to happen inside script step).
script:
- - go test -v ./...
- - go test -run=^$ -bench=BenchmarkReference -benchmem
+ - go get -t -v ./...
+ - diff -u <(echo -n) <(gofmt -d -s .)
+ - go tool vet .
+ - go test -v ./...
diff --git a/vendor/gopkg.in/russross/blackfriday.v2/README.md b/vendor/gopkg.in/russross/blackfriday.v2/README.md
index 2e0db35..d5a8649 100644
--- a/vendor/gopkg.in/russross/blackfriday.v2/README.md
+++ b/vendor/gopkg.in/russross/blackfriday.v2/README.md
@@ -34,9 +34,15 @@ Versions
--------
Currently maintained and recommended version of Blackfriday is `v2`. It's being
-developed on its own branch: https://github.com/russross/blackfriday/v2. You
-should install and import it via [gopkg.in][6] at
-`gopkg.in/russross/blackfriday.v2`.
+developed on its own branch: https://github.com/russross/blackfriday/tree/v2 and the
+documentation is available at
+https://godoc.org/gopkg.in/russross/blackfriday.v2.
+
+It is `go get`-able via via [gopkg.in][6] at `gopkg.in/russross/blackfriday.v2`,
+but we highly recommend using package management tool like [dep][7] or
+[Glide][8] and make use of semantic versioning. With package management you
+should import `github.com/russross/blackfriday` and specify that you're using
+version 2.0.0.
Version 2 offers a number of improvements over v1:
@@ -198,7 +204,7 @@ implements the following extensions:
Cat
: Fluffy animal everyone likes
-
+
Internet
: Vector of transmission for pictures of cats
@@ -209,7 +215,7 @@ implements the following extensions:
end of the document. A footnote looks like this:
This is a footnote.[^1]
-
+
[^1]: the footnote text.
* **Autolinking**. Blackfriday can find URLs that have not been
@@ -255,9 +261,11 @@ are a few of note:
* [markdownfmt](https://github.com/shurcooL/markdownfmt): like gofmt,
but for markdown.
-* [LaTeX output](https://bitbucket.org/ambrevar/blackfriday-latex):
+* [LaTeX output](https://github.com/Ambrevar/Blackfriday-LaTeX):
renders output as LaTeX.
+* [Blackfriday-Confluence](https://github.com/kentaro-m/blackfriday-confluence): provides a [Confluence Wiki Markup](https://confluence.atlassian.com/doc/confluence-wiki-markup-251003035.html) renderer.
+
Todo
----
diff --git a/vendor/gopkg.in/russross/blackfriday.v2/block.go b/vendor/gopkg.in/russross/blackfriday.v2/block.go
index d7da33f..b860747 100644
--- a/vendor/gopkg.in/russross/blackfriday.v2/block.go
+++ b/vendor/gopkg.in/russross/blackfriday.v2/block.go
@@ -17,6 +17,7 @@ import (
"bytes"
"html"
"regexp"
+ "strings"
"github.com/shurcooL/sanitized_anchor_name"
)
@@ -568,8 +569,8 @@ func (*Markdown) isHRule(data []byte) bool {
// isFenceLine checks if there's a fence line (e.g., ``` or ``` go) at the beginning of data,
// and returns the end index if so, or 0 otherwise. It also returns the marker found.
-// If syntax is not nil, it gets set to the syntax specified in the fence line.
-func isFenceLine(data []byte, syntax *string, oldmarker string) (end int, marker string) {
+// If info is not nil, it gets set to the syntax specified in the fence line.
+func isFenceLine(data []byte, info *string, oldmarker string) (end int, marker string) {
i, size := 0, 0
// skip up to three spaces
@@ -605,9 +606,9 @@ func isFenceLine(data []byte, syntax *string, oldmarker string) (end int, marker
}
// TODO(shurcooL): It's probably a good idea to simplify the 2 code paths here
- // into one, always get the syntax, and discard it if the caller doesn't care.
- if syntax != nil {
- syn := 0
+ // into one, always get the info string, and discard it if the caller doesn't care.
+ if info != nil {
+ infoLength := 0
i = skipChar(data, i, ' ')
if i >= len(data) {
@@ -617,14 +618,14 @@ func isFenceLine(data []byte, syntax *string, oldmarker string) (end int, marker
return 0, ""
}
- syntaxStart := i
+ infoStart := i
if data[i] == '{' {
i++
- syntaxStart++
+ infoStart++
for i < len(data) && data[i] != '}' && data[i] != '\n' {
- syn++
+ infoLength++
i++
}
@@ -634,31 +635,30 @@ func isFenceLine(data []byte, syntax *string, oldmarker string) (end int, marker
// strip all whitespace at the beginning and the end
// of the {} block
- for syn > 0 && isspace(data[syntaxStart]) {
- syntaxStart++
- syn--
+ for infoLength > 0 && isspace(data[infoStart]) {
+ infoStart++
+ infoLength--
}
- for syn > 0 && isspace(data[syntaxStart+syn-1]) {
- syn--
+ for infoLength > 0 && isspace(data[infoStart+infoLength-1]) {
+ infoLength--
}
-
i++
+ i = skipChar(data, i, ' ')
} else {
- for i < len(data) && !isspace(data[i]) {
- syn++
+ for i < len(data) && !isverticalspace(data[i]) {
+ infoLength++
i++
}
}
- *syntax = string(data[syntaxStart : syntaxStart+syn])
+ *info = strings.TrimSpace(string(data[infoStart : infoStart+infoLength]))
}
- i = skipChar(data, i, ' ')
- if i >= len(data) || data[i] != '\n' {
- if i == len(data) {
- return i, marker
- }
+ if i == len(data) {
+ return i, marker
+ }
+ if i > len(data) || data[i] != '\n' {
return 0, ""
}
return i + 1, marker // Take newline into account.
@@ -668,14 +668,14 @@ func isFenceLine(data []byte, syntax *string, oldmarker string) (end int, marker
// or 0 otherwise. It writes to out if doRender is true, otherwise it has no side effects.
// If doRender is true, a final newline is mandatory to recognize the fenced code block.
func (p *Markdown) fencedCodeBlock(data []byte, doRender bool) int {
- var syntax string
- beg, marker := isFenceLine(data, &syntax, "")
+ var info string
+ beg, marker := isFenceLine(data, &info, "")
if beg == 0 || beg >= len(data) {
return 0
}
var work bytes.Buffer
- work.Write([]byte(syntax))
+ work.Write([]byte(info))
work.WriteByte('\n')
for {
@@ -1148,6 +1148,18 @@ func (p *Markdown) list(data []byte, flags ListType) int {
return i
}
+// Returns true if the list item is not the same type as its parent list
+func (p *Markdown) listTypeChanged(data []byte, flags *ListType) bool {
+ if p.dliPrefix(data) > 0 && *flags&ListTypeDefinition == 0 {
+ return true
+ } else if p.oliPrefix(data) > 0 && *flags&ListTypeOrdered == 0 {
+ return true
+ } else if p.uliPrefix(data) > 0 && (*flags&ListTypeOrdered != 0 || *flags&ListTypeDefinition != 0) {
+ return true
+ }
+ return false
+}
+
// Returns true if block ends with a blank line, descending if needed
// into lists and sublists.
func endsWithBlankLine(block *Node) bool {
@@ -1246,6 +1258,7 @@ func (p *Markdown) listItem(data []byte, flags *ListType) int {
// process the following lines
containsBlankLine := false
sublist := 0
+ codeBlockMarker := ""
gatherlines:
for line < len(data) {
@@ -1279,6 +1292,27 @@ gatherlines:
chunk := data[line+indentIndex : i]
+ if p.extensions&FencedCode != 0 {
+ // determine if in or out of codeblock
+ // if in codeblock, ignore normal list processing
+ _, marker := isFenceLine(chunk, nil, codeBlockMarker)
+ if marker != "" {
+ if codeBlockMarker == "" {
+ // start of codeblock
+ codeBlockMarker = marker
+ } else {
+ // end of codeblock.
+ codeBlockMarker = ""
+ }
+ }
+ // we are in a codeblock, write line, and continue
+ if codeBlockMarker != "" || marker != "" {
+ raw.Write(data[line+indentIndex : i])
+ line = i
+ continue gatherlines
+ }
+ }
+
// evaluate how this line fits in
switch {
// is this a nested list item?
@@ -1286,14 +1320,21 @@ gatherlines:
p.oliPrefix(chunk) > 0 ||
p.dliPrefix(chunk) > 0:
- if containsBlankLine {
- *flags |= ListItemContainsBlock
+ // to be a nested list, it must be indented more
+ // if not, it is either a different kind of list
+ // or the next item in the same list
+ if indent <= itemIndent {
+ if p.listTypeChanged(chunk, flags) {
+ *flags |= ListItemEndOfList
+ } else if containsBlankLine {
+ *flags |= ListItemContainsBlock
+ }
+
+ break gatherlines
}
- // to be a nested list, it must be indented more
- // if not, it is the next item in the same list
- if indent <= itemIndent {
- break gatherlines
+ if containsBlankLine {
+ *flags |= ListItemContainsBlock
}
// is this the first item in the nested list?
diff --git a/vendor/gopkg.in/russross/blackfriday.v2/go.mod b/vendor/gopkg.in/russross/blackfriday.v2/go.mod
new file mode 100644
index 0000000..620b74e
--- /dev/null
+++ b/vendor/gopkg.in/russross/blackfriday.v2/go.mod
@@ -0,0 +1 @@
+module github.com/russross/blackfriday/v2
diff --git a/vendor/gopkg.in/russross/blackfriday.v2/html.go b/vendor/gopkg.in/russross/blackfriday.v2/html.go
index 25fb185..284c871 100644
--- a/vendor/gopkg.in/russross/blackfriday.v2/html.go
+++ b/vendor/gopkg.in/russross/blackfriday.v2/html.go
@@ -35,6 +35,7 @@ const (
Safelink // Only link to trusted protocols
NofollowLinks // Only link with rel="nofollow"
NoreferrerLinks // Only link with rel="noreferrer"
+ NoopenerLinks // Only link with rel="noopener"
HrefTargetBlank // Add a blank target
CompletePage // Generate a complete HTML page
UseXHTML // Generate XHTML output instead of HTML
@@ -87,6 +88,10 @@ type HTMLRendererParameters struct {
HeadingIDPrefix string
// If set, add this text to the back of each Heading ID, to ensure uniqueness.
HeadingIDSuffix string
+ // Increase heading levels: if the offset is 1,