diff --git a/README.md b/README.md index c4e449f..18ea5e4 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ matrix-skype is a library for bridging matrix and skype, about matrix, please re * Typing status The skype api lib of matrix-skype is [go-skypeapi](https://github.com/kelaresg/go-skypeapi). -~~Note: Use `go get github.com/kelaresg/go-skypeapi@{latest_commit_id}`, for now is: `go get github.com/kelaresg/go-skypeapi@226d1ec92858504b03e32017cd007420b3d7f205`~~ This matrix-skype bridge is based on [mautrix-whatsapp](https://github.com/tulir/mautrix-whatsapp),so the installation and usage methods are very similar to mautrix-whatsapp(matrix-skype currently does not support docker installation) diff --git a/database/upgrades/2020-08-25-message-id-column.go b/database/upgrades/2020-08-25-message-id-column.go index a74f824..00a862c 100644 --- a/database/upgrades/2020-08-25-message-id-column.go +++ b/database/upgrades/2020-08-25-message-id-column.go @@ -6,7 +6,7 @@ import ( func init() { upgrades[17] = upgrade{"Add id column to messages", func(tx *sql.Tx, ctx context) error { - _, err := tx.Exec(`ALTER TABLE message ADD COLUMN id CHAR(13) DEFAULT ""`) + _, err := tx.Exec(`ALTER TABLE message ADD COLUMN id CHAR(13) DEFAULT ''`) if err != nil { return err } diff --git a/formatting.go b/formatting.go index 22e0ff6..f87d147 100644 --- a/formatting.go +++ b/formatting.go @@ -18,6 +18,7 @@ var italicRegex = regexp.MustCompile("([\\s>~*]|^)_(.+?)_([^a-zA-Z\\d]|$)") var boldRegex = regexp.MustCompile("([\\s>_~]|^)\\*(.+?)\\*([^a-zA-Z\\d]|$)") var strikethroughRegex = regexp.MustCompile("([\\s>_*]|^)~(.+?)~([^a-zA-Z\\d]|$)") var codeBlockRegex = regexp.MustCompile("```(?:.|\n)+?```") + //var mentionRegex = regexp.MustCompile("@[0-9]+") //var mentionRegex = regexp.MustCompile("@(.*)") var mentionRegex = regexp.MustCompile("]+\\bid=\"([^\"]+)\"(.*?)*") @@ -125,6 +126,7 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent) { } if output != content.Body { output = strings.Replace(output, "\n", "
", -1) + content.Body = html.UnescapeString(content.Body) // skype messages arrive escaped which causes element rendering issues #1 // parse @user message r := regexp.MustCompile(`]+\bid="([^"]+)"(.*?)*`) diff --git a/formatting_test.go b/formatting_test.go new file mode 100644 index 0000000..6070483 --- /dev/null +++ b/formatting_test.go @@ -0,0 +1,96 @@ +package main + +import ( + "github.com/kelaresg/matrix-skype/database" + "github.com/kelaresg/matrix-skype/types" + "maunium.net/go/mautrix/event" + "maunium.net/go/mautrix/format" + "reflect" + "regexp" + "sync" + "testing" +) + +func TestFormatter_ParseSkype(t *testing.T) { + type fields struct { + bridge *Bridge + matrixHTMLParser *format.HTMLParser + waReplString map[*regexp.Regexp]string + waReplFunc map[*regexp.Regexp]func(string) string + waReplFuncText map[*regexp.Regexp]func(string) string + } + type args struct { + content *event.MessageEventContent + } + type expect struct { + content *event.MessageEventContent + } + testUser := &User{ + User: &database.User{ + MXID: "mxtestid", + }, + } + testBridge := &Bridge{ + usersLock: *new(sync.Mutex), + usersByJID: map[types.SkypeID]*User{"test": testUser}, + } + testFormatter := &Formatter{ + bridge: testBridge, + } + tests := []struct { + name string + args args + expect expect + }{ + { + "simple message", + args{ + &event.MessageEventContent{ + Body: "This is a very simple message.", + }, + }, + expect{ + &event.MessageEventContent{ + Body: "This is a very simple message.", + }, + }, + }, + { + "simple punctuation test", + args{ + &event.MessageEventContent{ + Body: "It's the inclusion of "simple" punctuation that causes most of the problems.", + }, + }, + expect{ + &event.MessageEventContent{ + Body: "It's the inclusion of \"simple\" punctuation that causes most of the problems.", + Format: event.FormatHTML, + }, + }, + }, + { + "full punctuation test", + args{ + &event.MessageEventContent{ + Body: "&<>"'", // use a few different encodings + Format: event.FormatHTML, + }, + }, + expect{ + &event.MessageEventContent{ + Body: "&<>\"'", + Format: event.FormatHTML, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + testFormatter.ParseSkype(tt.args.content) + if !reflect.DeepEqual(tt.args.content, tt.expect.content) { + t.Errorf("content = %v, wanted %v", tt.args.content, tt.expect.content) + } + }) + } +}