diff --git a/Gopkg.lock b/Gopkg.lock
index a8f4ee4..c69ae5d 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -164,14 +164,14 @@
[[projects]]
branch = "master"
- digest = "1:6dd6ac30401547ebcd1c0ee7a08e74e9ae872eba28607309979e9ed9776cee21"
+ digest = "1:f0a9c6bdcbf2bbaa02f4f913b1956cc722daf92bec1715b51e001e53ba93b3a2"
name = "maunium.net/go/mautrix"
packages = [
".",
"format",
]
pruneopts = "UT"
- revision = "e8080dcf484d1db9021d2019fee132ffc9e37e3c"
+ revision = "5012a3c49b63ccb3c72cd01d2fd3442759c3ea3c"
[[projects]]
branch = "master"
diff --git a/matrix/matrix_test.go b/matrix/matrix_test.go
index 0d8bc3c..21ba34e 100644
--- a/matrix/matrix_test.go
+++ b/matrix/matrix_test.go
@@ -21,8 +21,8 @@ import (
"fmt"
"github.com/stretchr/testify/assert"
"io/ioutil"
- "maunium.net/go/mautrix"
"maunium.net/go/gomuks/config"
+ "maunium.net/go/mautrix"
"net/http"
"os"
"strings"
@@ -69,7 +69,7 @@ func TestContainer_SendMarkdownMessage_WithMarkdown(t *testing.T) {
body := parseBody(req)
assert.Equal(t, "m.text", body["msgtype"])
- assert.Equal(t, "**formatted** test _message_", body["body"])
+ assert.Equal(t, "**formatted** test _message_", body["body"])
assert.Equal(t, "formatted test message", body["formatted_body"])
return mockResponse(http.StatusOK, `{"event_id": "!foobar2:example.com"}`), nil
})}
diff --git a/matrix/pushrules/condition.go b/matrix/pushrules/condition.go
index bacab56..d547a3f 100644
--- a/matrix/pushrules/condition.go
+++ b/matrix/pushrules/condition.go
@@ -112,6 +112,9 @@ func (cond *PushCondition) matchDisplayName(room Room, event *mautrix.Event) boo
return false
}
member := room.GetMember(ownerID)
+ if member == nil {
+ return false
+ }
return strings.Contains(event.Content.Body, member.Displayname)
}
diff --git a/matrix/pushrules/condition_displayname_test.go b/matrix/pushrules/condition_displayname_test.go
index e859ff8..0ae85d1 100644
--- a/matrix/pushrules/condition_displayname_test.go
+++ b/matrix/pushrules/condition_displayname_test.go
@@ -17,42 +17,43 @@
package pushrules_test
import (
+ "maunium.net/go/mautrix"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPushCondition_Match_DisplayName(t *testing.T) {
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.text",
- "body": "tulir: test mention",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ MsgType: mautrix.MsgText,
+ Body: "tulir: test mention",
})
event.Sender = "@someone_else:matrix.org"
assert.True(t, displaynamePushCondition.Match(displaynameTestRoom, event))
}
func TestPushCondition_Match_DisplayName_Fail(t *testing.T) {
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.text",
- "body": "not a mention",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ MsgType: mautrix.MsgText,
+ Body: "not a mention",
})
event.Sender = "@someone_else:matrix.org"
assert.False(t, displaynamePushCondition.Match(displaynameTestRoom, event))
}
func TestPushCondition_Match_DisplayName_CantHighlightSelf(t *testing.T) {
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.text",
- "body": "tulir: I can't highlight myself",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ MsgType: mautrix.MsgText,
+ Body: "tulir: I can't highlight myself",
})
assert.False(t, displaynamePushCondition.Match(displaynameTestRoom, event))
}
func TestPushCondition_Match_DisplayName_FailsOnEmptyRoom(t *testing.T) {
emptyRoom := newFakeRoom(0)
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.text",
- "body": "tulir: this room doesn't have the owner Member available, so it fails.",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ MsgType: mautrix.MsgText,
+ Body: "tulir: this room doesn't have the owner Member available, so it fails.",
})
event.Sender = "@someone_else:matrix.org"
assert.False(t, displaynamePushCondition.Match(emptyRoom, event))
diff --git a/matrix/pushrules/condition_eventmatch_test.go b/matrix/pushrules/condition_eventmatch_test.go
index 160edd5..0591656 100644
--- a/matrix/pushrules/condition_eventmatch_test.go
+++ b/matrix/pushrules/condition_eventmatch_test.go
@@ -17,6 +17,7 @@
package pushrules_test
import (
+ "maunium.net/go/mautrix"
"testing"
"github.com/stretchr/testify/assert"
@@ -24,9 +25,11 @@ import (
func TestPushCondition_Match_KindEvent_MsgType(t *testing.T) {
condition := newMatchPushCondition("content.msgtype", "m.emote")
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.emote",
- "body": "tests gomuks pushconditions",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ Raw: map[string]interface{}{
+ "msgtype": "m.emote",
+ "body": "tests gomuks pushconditions",
+ },
})
assert.True(t, condition.Match(blankTestRoom, event))
}
@@ -34,58 +37,60 @@ func TestPushCondition_Match_KindEvent_MsgType(t *testing.T) {
func TestPushCondition_Match_KindEvent_MsgType_Fail(t *testing.T) {
condition := newMatchPushCondition("content.msgtype", "m.emote")
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.text",
- "body": "I'm testing gomuks pushconditions",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ Raw: map[string]interface{}{
+ "msgtype": "m.text",
+ "body": "I'm testing gomuks pushconditions",
+ },
})
assert.False(t, condition.Match(blankTestRoom, event))
}
func TestPushCondition_Match_KindEvent_EventType(t *testing.T) {
condition := newMatchPushCondition("type", "m.room.foo")
- event := newFakeEvent("m.room.foo", map[string]interface{}{})
+ event := newFakeEvent(mautrix.NewEventType("m.room.foo"), mautrix.Content{})
assert.True(t, condition.Match(blankTestRoom, event))
}
func TestPushCondition_Match_KindEvent_EventType_IllegalGlob(t *testing.T) {
condition := newMatchPushCondition("type", "m.room.invalid_glo[b")
- event := newFakeEvent("m.room.invalid_glob", map[string]interface{}{})
+ event := newFakeEvent(mautrix.NewEventType("m.room.invalid_glob"), mautrix.Content{})
assert.False(t, condition.Match(blankTestRoom, event))
}
func TestPushCondition_Match_KindEvent_Sender_Fail(t *testing.T) {
condition := newMatchPushCondition("sender", "@foo:maunium.net")
- event := newFakeEvent("m.room.foo", map[string]interface{}{})
+ event := newFakeEvent(mautrix.NewEventType("m.room.foo"), mautrix.Content{})
assert.False(t, condition.Match(blankTestRoom, event))
}
func TestPushCondition_Match_KindEvent_RoomID(t *testing.T) {
condition := newMatchPushCondition("room_id", "!fakeroom:maunium.net")
- event := newFakeEvent("", map[string]interface{}{})
+ event := newFakeEvent(mautrix.NewEventType(""), mautrix.Content{})
assert.True(t, condition.Match(blankTestRoom, event))
}
func TestPushCondition_Match_KindEvent_BlankStateKey(t *testing.T) {
condition := newMatchPushCondition("state_key", "")
- event := newFakeEvent("m.room.foo", map[string]interface{}{})
+ event := newFakeEvent(mautrix.NewEventType("m.room.foo"), mautrix.Content{})
assert.True(t, condition.Match(blankTestRoom, event))
}
func TestPushCondition_Match_KindEvent_BlankStateKey_Fail(t *testing.T) {
condition := newMatchPushCondition("state_key", "not blank")
- event := newFakeEvent("m.room.foo", map[string]interface{}{})
+ event := newFakeEvent(mautrix.NewEventType("m.room.foo"), mautrix.Content{})
assert.False(t, condition.Match(blankTestRoom, event))
}
func TestPushCondition_Match_KindEvent_NonBlankStateKey(t *testing.T) {
condition := newMatchPushCondition("state_key", "*:maunium.net")
- event := newFakeEvent("m.room.foo", map[string]interface{}{})
+ event := newFakeEvent(mautrix.NewEventType("m.room.foo"), mautrix.Content{})
event.StateKey = &event.Sender
assert.True(t, condition.Match(blankTestRoom, event))
}
func TestPushCondition_Match_KindEvent_UnknownKey(t *testing.T) {
condition := newMatchPushCondition("non-existent key", "doesn't affect anything")
- event := newFakeEvent("m.room.foo", map[string]interface{}{})
+ event := newFakeEvent(mautrix.NewEventType("m.room.foo"), mautrix.Content{})
assert.False(t, condition.Match(blankTestRoom, event))
}
diff --git a/matrix/pushrules/condition_test.go b/matrix/pushrules/condition_test.go
index 750f2c7..4e8e8a1 100644
--- a/matrix/pushrules/condition_test.go
+++ b/matrix/pushrules/condition_test.go
@@ -40,13 +40,13 @@ func init() {
countConditionTestEvent = &mautrix.Event{
Sender: "@tulir:maunium.net",
- Type: "m.room.message",
+ Type: mautrix.EventMessage,
Timestamp: 1523791120,
ID: "$123:maunium.net",
RoomID: "!fakeroom:maunium.net",
- Content: map[string]interface{}{
- "msgtype": "m.text",
- "body": "test",
+ Content: mautrix.Content{
+ MsgType: mautrix.MsgText,
+ Body: "test",
},
}
@@ -56,7 +56,7 @@ func init() {
}
}
-func newFakeEvent(evtType string, content map[string]interface{}) *mautrix.Event {
+func newFakeEvent(evtType mautrix.EventType, content mautrix.Content) *mautrix.Event {
return &mautrix.Event{
Sender: "@tulir:maunium.net",
Type: evtType,
@@ -86,49 +86,47 @@ func TestPushCondition_Match_InvalidKind(t *testing.T) {
condition := &pushrules.PushCondition{
Kind: pushrules.PushCondKind("invalid"),
}
- event := newFakeEvent("m.room.foobar", map[string]interface{}{})
+ event := newFakeEvent(mautrix.EventType{Type: "m.room.foobar"}, mautrix.Content{})
assert.False(t, condition.Match(blankTestRoom, event))
}
type FakeRoom struct {
- members map[string]*rooms.Member
+ members map[string]*mautrix.Member
owner string
}
func newFakeRoom(memberCount int) *FakeRoom {
room := &FakeRoom{
owner: "@tulir:maunium.net",
- members: make(map[string]*rooms.Member),
+ members: make(map[string]*mautrix.Member),
}
if memberCount >= 1 {
- room.members["@tulir:maunium.net"] = &rooms.Member{
- UserID: "@tulir:maunium.net",
- Membership: rooms.MembershipJoin,
- DisplayName: "tulir",
+ room.members["@tulir:maunium.net"] = &mautrix.Member{
+ Membership: mautrix.MembershipJoin,
+ Displayname: "tulir",
}
}
for i := 0; i < memberCount-1; i++ {
mxid := fmt.Sprintf("@extrauser_%d:matrix.org", i)
- room.members[mxid] = &rooms.Member{
- UserID: mxid,
- Membership: rooms.MembershipJoin,
- DisplayName: fmt.Sprintf("Extra User %d", i),
+ room.members[mxid] = &mautrix.Member{
+ Membership: mautrix.MembershipJoin,
+ Displayname: fmt.Sprintf("Extra User %d", i),
}
}
return room
}
-func (fr *FakeRoom) GetMember(mxid string) *rooms.Member {
+func (fr *FakeRoom) GetMember(mxid string) *mautrix.Member {
return fr.members[mxid]
}
-func (fr *FakeRoom) GetSessionOwner() *rooms.Member {
- return fr.members[fr.owner]
+func (fr *FakeRoom) GetSessionOwner() string {
+ return fr.owner
}
-func (fr *FakeRoom) GetMembers() map[string]*rooms.Member {
+func (fr *FakeRoom) GetMembers() map[string]*mautrix.Member {
return fr.members
}
diff --git a/matrix/pushrules/pushrules_test.go b/matrix/pushrules/pushrules_test.go
index 73fa787..c56fd10 100644
--- a/matrix/pushrules/pushrules_test.go
+++ b/matrix/pushrules/pushrules_test.go
@@ -25,18 +25,13 @@ import (
"maunium.net/go/gomuks/matrix/pushrules"
)
-var mapExamplePushRules map[string]interface{}
-
-func init() {
- mapExamplePushRules = make(map[string]interface{})
- json.Unmarshal([]byte(JSONExamplePushRules), &mapExamplePushRules)
-}
-
func TestEventToPushRules(t *testing.T) {
event := &mautrix.Event{
- Type: "m.push_rules",
+ Type: mautrix.AccountDataPushRules,
Timestamp: 1523380910,
- Content: mapExamplePushRules,
+ Content: mautrix.Content{
+ VeryRaw: json.RawMessage(JSONExamplePushRules),
+ },
}
pushRuleset, err := pushrules.EventToPushRules(event)
assert.Nil(t, err)
diff --git a/matrix/pushrules/rule_array_test.go b/matrix/pushrules/rule_array_test.go
index 9396411..5a5bd3d 100644
--- a/matrix/pushrules/rule_array_test.go
+++ b/matrix/pushrules/rule_array_test.go
@@ -19,6 +19,7 @@ package pushrules_test
import (
"github.com/stretchr/testify/assert"
"maunium.net/go/gomuks/matrix/pushrules"
+ "maunium.net/go/mautrix"
"testing"
)
@@ -61,9 +62,9 @@ func TestPushRuleArray_GetActions_FirstMatchReturns(t *testing.T) {
rules := pushrules.PushRuleArray{rule1, rule2, rule3}
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.emote",
- "body": "is testing pushrules",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ MsgType: mautrix.MsgEmote,
+ Body: "is testing pushrules",
})
assert.Equal(t, rules.GetActions(blankTestRoom, event), actions2)
}
@@ -107,9 +108,9 @@ func TestPushRuleArray_GetActions_NoMatchesIsNil(t *testing.T) {
rules := pushrules.PushRuleArray{rule1, rule2, rule3}
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.emote",
- "body": "is testing pushrules",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ MsgType: mautrix.MsgEmote,
+ Body: "is testing pushrules",
})
assert.Nil(t, rules.GetActions(blankTestRoom, event))
}
@@ -156,9 +157,9 @@ func TestPushRuleMap_GetActions_RoomRuleExists(t *testing.T) {
Type: pushrules.RoomRule,
}
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.emote",
- "body": "is testing pushrules",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ MsgType: mautrix.MsgEmote,
+ Body: "is testing pushrules",
})
assert.Equal(t, rules.GetActions(blankTestRoom, event), actions3)
}
@@ -194,9 +195,9 @@ func TestPushRuleMap_GetActions_RoomRuleDoesntExist(t *testing.T) {
Type: pushrules.RoomRule,
}
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.emote",
- "body": "is testing pushrules",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ MsgType: mautrix.MsgEmote,
+ Body: "is testing pushrules",
})
assert.Nil(t, rules.GetActions(blankTestRoom, event))
}
@@ -243,9 +244,9 @@ func TestPushRuleMap_GetActions_SenderRuleExists(t *testing.T) {
Type: pushrules.SenderRule,
}
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.emote",
- "body": "is testing pushrules",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ MsgType: mautrix.MsgEmote,
+ Body: "is testing pushrules",
})
assert.Equal(t, rules.GetActions(blankTestRoom, event), actions1)
}
diff --git a/matrix/pushrules/rule_test.go b/matrix/pushrules/rule_test.go
index bedcfca..aad6a77 100644
--- a/matrix/pushrules/rule_test.go
+++ b/matrix/pushrules/rule_test.go
@@ -19,6 +19,7 @@ package pushrules_test
import (
"github.com/stretchr/testify/assert"
"maunium.net/go/gomuks/matrix/pushrules"
+ "maunium.net/go/mautrix"
"testing"
)
@@ -31,9 +32,13 @@ func TestPushRule_Match_Conditions(t *testing.T) {
Conditions: []*pushrules.PushCondition{cond1, cond2},
}
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.emote",
- "body": "is testing pushrules",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ Raw: map[string]interface{}{
+ "msgtype": "m.emote",
+ "body": "is testing pushrules",
+ },
+ MsgType: mautrix.MsgEmote,
+ Body: "is testing pushrules",
})
assert.True(t, rule.Match(blankTestRoom, event))
}
@@ -47,9 +52,13 @@ func TestPushRule_Match_Conditions_Disabled(t *testing.T) {
Conditions: []*pushrules.PushCondition{cond1, cond2},
}
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.emote",
- "body": "is testing pushrules",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ Raw: map[string]interface{}{
+ "msgtype": "m.emote",
+ "body": "is testing pushrules",
+ },
+ MsgType: mautrix.MsgEmote,
+ Body: "is testing pushrules",
})
assert.False(t, rule.Match(blankTestRoom, event))
}
@@ -63,9 +72,13 @@ func TestPushRule_Match_Conditions_FailIfOneFails(t *testing.T) {
Conditions: []*pushrules.PushCondition{cond1, cond2},
}
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.text",
- "body": "I'm testing pushrules",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ Raw: map[string]interface{}{
+ "msgtype": "m.text",
+ "body": "I'm testing pushrules",
+ },
+ MsgType: mautrix.MsgText,
+ Body: "I'm testing pushrules",
})
assert.False(t, rule.Match(blankTestRoom, event))
}
@@ -77,9 +90,9 @@ func TestPushRule_Match_Content(t *testing.T) {
Pattern: "is testing*",
}
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.emote",
- "body": "is testing pushrules",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ MsgType: mautrix.MsgEmote,
+ Body: "is testing pushrules",
})
assert.True(t, rule.Match(blankTestRoom, event))
}
@@ -91,9 +104,9 @@ func TestPushRule_Match_Content_Fail(t *testing.T) {
Pattern: "is testing*",
}
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.emote",
- "body": "is not testing pushrules",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ MsgType: mautrix.MsgEmote,
+ Body: "is not testing pushrules",
})
assert.False(t, rule.Match(blankTestRoom, event))
}
@@ -105,9 +118,9 @@ func TestPushRule_Match_Content_ImplicitGlob(t *testing.T) {
Pattern: "testing",
}
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.emote",
- "body": "is not testing pushrules",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ MsgType: mautrix.MsgEmote,
+ Body: "is not testing pushrules",
})
assert.True(t, rule.Match(blankTestRoom, event))
}
@@ -119,9 +132,9 @@ func TestPushRule_Match_Content_IllegalGlob(t *testing.T) {
Pattern: "this is not a valid glo[b",
}
- event := newFakeEvent("m.room.message", map[string]interface{}{
- "msgtype": "m.emote",
- "body": "this is not a valid glob",
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{
+ MsgType: mautrix.MsgEmote,
+ Body: "this is not a valid glob",
})
assert.False(t, rule.Match(blankTestRoom, event))
}
@@ -133,7 +146,7 @@ func TestPushRule_Match_Room(t *testing.T) {
RuleID: "!fakeroom:maunium.net",
}
- event := newFakeEvent("m.room.message", map[string]interface{}{})
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{})
assert.True(t, rule.Match(blankTestRoom, event))
}
@@ -144,7 +157,7 @@ func TestPushRule_Match_Room_Fail(t *testing.T) {
RuleID: "!otherroom:maunium.net",
}
- event := newFakeEvent("m.room.message", map[string]interface{}{})
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{})
assert.False(t, rule.Match(blankTestRoom, event))
}
@@ -155,7 +168,7 @@ func TestPushRule_Match_Sender(t *testing.T) {
RuleID: "@tulir:maunium.net",
}
- event := newFakeEvent("m.room.message", map[string]interface{}{})
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{})
assert.True(t, rule.Match(blankTestRoom, event))
}
@@ -166,7 +179,7 @@ func TestPushRule_Match_Sender_Fail(t *testing.T) {
RuleID: "@someone:matrix.org",
}
- event := newFakeEvent("m.room.message", map[string]interface{}{})
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{})
assert.False(t, rule.Match(blankTestRoom, event))
}
@@ -177,6 +190,6 @@ func TestPushRule_Match_UnknownTypeAlwaysFail(t *testing.T) {
RuleID: "@someone:matrix.org",
}
- event := newFakeEvent("m.room.message", map[string]interface{}{})
+ event := newFakeEvent(mautrix.EventMessage, mautrix.Content{})
assert.False(t, rule.Match(blankTestRoom, event))
}
diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go
index 72251c4..628a0e3 100644
--- a/matrix/rooms/room.go
+++ b/matrix/rooms/room.go
@@ -424,7 +424,7 @@ func (room *Room) GetMember(userID string) *mautrix.Member {
return member
}
-// GetSessionOwner returns the Member instance of the user whose session this room was created for.
+// GetSessionOwner returns the ID of the user whose session this room was created for.
func (room *Room) GetSessionOwner() string {
return room.SessionUserID
}
diff --git a/matrix/rooms/room_test.go b/matrix/rooms/room_test.go
index db7f586..891e541 100644
--- a/matrix/rooms/room_test.go
+++ b/matrix/rooms/room_test.go
@@ -21,8 +21,8 @@ import (
"testing"
"github.com/stretchr/testify/assert"
- "maunium.net/go/mautrix"
"maunium.net/go/gomuks/matrix/rooms"
+ "maunium.net/go/mautrix"
)
func TestNewRoom_DefaultValues(t *testing.T) {
@@ -34,15 +34,15 @@ func TestNewRoom_DefaultValues(t *testing.T) {
assert.Empty(t, room.GetAliases())
assert.Empty(t, room.GetCanonicalAlias())
assert.Empty(t, room.GetTopic())
- assert.Nil(t, room.GetSessionOwner())
+ assert.Nil(t, room.GetMember(room.GetSessionOwner()))
}
func TestRoom_GetCanonicalAlias(t *testing.T) {
room := rooms.NewRoom("!test:maunium.net", "@tulir:maunium.net")
room.UpdateState(&mautrix.Event{
- Type: "m.room.canonical_alias",
- Content: map[string]interface{}{
- "alias": "#foo:maunium.net",
+ Type: mautrix.StateCanonicalAlias,
+ Content: mautrix.Content{
+ Alias: "#foo:maunium.net",
},
})
assert.Equal(t, "#foo:maunium.net", room.GetCanonicalAlias())
@@ -51,9 +51,9 @@ func TestRoom_GetCanonicalAlias(t *testing.T) {
func TestRoom_GetTopic(t *testing.T) {
room := rooms.NewRoom("!test:maunium.net", "@tulir:maunium.net")
room.UpdateState(&mautrix.Event{
- Type: "m.room.topic",
- Content: map[string]interface{}{
- "topic": "test topic",
+ Type: mautrix.StateTopic,
+ Content: mautrix.Content{
+ Topic: "test topic",
},
})
assert.Equal(t, "test topic", room.GetTopic())
@@ -88,18 +88,18 @@ func TestRoom_GetAliases(t *testing.T) {
func addName(room *rooms.Room) {
room.UpdateState(&mautrix.Event{
- Type: "m.room.name",
- Content: map[string]interface{}{
- "name": "Test room",
+ Type: mautrix.StateRoomName,
+ Content: mautrix.Content{
+ Name: "Test room",
},
})
}
func addCanonicalAlias(room *rooms.Room) {
room.UpdateState(&mautrix.Event{
- Type: "m.room.canonical_alias",
- Content: map[string]interface{}{
- "alias": "#foo:maunium.net",
+ Type: mautrix.StateCanonicalAlias,
+ Content: mautrix.Content{
+ Alias: "#foo:maunium.net",
},
})
}
@@ -107,19 +107,19 @@ func addCanonicalAlias(room *rooms.Room) {
func addAliases(room *rooms.Room) {
server1 := "maunium.net"
room.UpdateState(&mautrix.Event{
- Type: "m.room.aliases",
+ Type: mautrix.StateAliases,
StateKey: &server1,
- Content: map[string]interface{}{
- "aliases": []interface{}{"#bar:maunium.net", "#test:maunium.net", "#foo:maunium.net"},
+ Content: mautrix.Content{
+ Aliases: []string{"#bar:maunium.net", "#test:maunium.net", "#foo:maunium.net"},
},
})
server2 := "matrix.org"
room.UpdateState(&mautrix.Event{
- Type: "m.room.aliases",
+ Type: mautrix.StateAliases,
StateKey: &server2,
- Content: map[string]interface{}{
- "aliases": []interface{}{"#foo:matrix.org", "#test:matrix.org"},
+ Content: mautrix.Content{
+ Aliases: []string{"#foo:matrix.org", "#test:matrix.org"},
},
})
}
@@ -127,27 +127,31 @@ func addAliases(room *rooms.Room) {
func addMembers(room *rooms.Room, count int) {
user1 := "@tulir:maunium.net"
room.UpdateState(&mautrix.Event{
- Type: "m.room.member",
+ Type: mautrix.StateMember,
StateKey: &user1,
- Content: map[string]interface{}{
- "displayname": "tulir",
- "membership": "join",
+ Content: mautrix.Content{
+ Member: mautrix.Member{
+ Displayname: "tulir",
+ Membership: mautrix.MembershipJoin,
+ },
},
})
for i := 1; i < count; i++ {
userN := fmt.Sprintf("@user_%d:matrix.org", i+1)
- content := map[string]interface{}{
- "membership": "join",
+ content := mautrix.Content{
+ Member: mautrix.Member{
+ Membership: mautrix.MembershipJoin,
+ },
}
if i%2 == 1 {
- content["displayname"] = fmt.Sprintf("User #%d", i+1)
+ content.Displayname = fmt.Sprintf("User #%d", i+1)
}
if i%5 == 0 {
- content["membership"] = "invite"
+ content.Membership = mautrix.MembershipInvite
}
room.UpdateState(&mautrix.Event{
- Type: "m.room.member",
+ Type: mautrix.StateMember,
StateKey: &userN,
Content: content,
})
@@ -168,7 +172,7 @@ func TestRoom_GetMember(t *testing.T) {
assert.NotNil(t, room.GetMember("@user_2:matrix.org"))
assert.NotNil(t, room.GetMember("@tulir:maunium.net"))
- assert.Equal(t, room.GetMember("@tulir:maunium.net"), room.GetSessionOwner())
+ assert.Equal(t, "@tulir:maunium.net", room.GetSessionOwner())
}
func TestRoom_GetTitle_ExplicitName(t *testing.T) {
diff --git a/matrix/sync_test.go b/matrix/sync_test.go
index 79cb11b..d3ae15e 100644
--- a/matrix/sync_test.go
+++ b/matrix/sync_test.go
@@ -20,9 +20,9 @@ import (
"testing"
"github.com/stretchr/testify/assert"
- "maunium.net/go/mautrix"
"maunium.net/go/gomuks/matrix"
"maunium.net/go/gomuks/matrix/rooms"
+ "maunium.net/go/mautrix"
)
func TestGomuksSyncer_ProcessResponse_Initial(t *testing.T) {
@@ -54,47 +54,47 @@ func TestGomuksSyncer_ProcessResponse(t *testing.T) {
}
ml := &mockListener{}
syncer := matrix.NewGomuksSyncer(mss)
- syncer.OnEventType("m.room.member", ml.receive)
- syncer.OnEventType("m.room.message", ml.receive)
+ syncer.OnEventType(mautrix.EventMessage, ml.receive)
+ syncer.OnEventType(mautrix.StateMember, ml.receive)
syncer.GetFilterJSON("@tulir:maunium.net")
joinEvt := &mautrix.Event{
ID: "!join:maunium.net",
- Type: "m.room.member",
+ Type: mautrix.StateMember,
Sender: "@tulir:maunium.net",
StateKey: ptr("̣@tulir:maunium.net"),
- Content: map[string]interface{}{
- "membership": "join",
+ Content: mautrix.Content{
+ Membership: mautrix.MembershipJoin,
},
}
messageEvt := &mautrix.Event{
ID: "!msg:maunium.net",
- Type: "m.room.message",
- Content: map[string]interface{}{
- "body": "foo",
- "msgtype": "m.text",
+ Type: mautrix.EventMessage,
+ Content: mautrix.Content{
+ Body: "foo",
+ MsgType: mautrix.MsgText,
},
}
unhandledEvt := &mautrix.Event{
ID: "!unhandled:maunium.net",
- Type: "m.room.unhandled_event",
+ Type: mautrix.EventType{Type: "m.room.unhandled_event"},
}
inviteEvt := &mautrix.Event{
ID: "!invite:matrix.org",
- Type: "m.room.member",
+ Type: mautrix.StateMember,
Sender: "@you:matrix.org",
StateKey: ptr("̣@tulir:maunium.net"),
- Content: map[string]interface{}{
- "membership": "invite",
+ Content: mautrix.Content{
+ Membership: mautrix.MembershipInvite,
},
}
leaveEvt := &mautrix.Event{
ID: "!leave:matrix.org",
- Type: "m.room.member",
+ Type: mautrix.StateMember,
Sender: "@you:matrix.org",
StateKey: ptr("̣@tulir:maunium.net"),
- Content: map[string]interface{}{
- "membership": "leave",
+ Content: mautrix.Content{
+ Membership: mautrix.MembershipLeave,
},
}
@@ -116,8 +116,8 @@ func TestGomuksSyncer_ProcessResponse(t *testing.T) {
} `json:"state"`
Timeline struct {
Events []*mautrix.Event `json:"events"`
- Limited bool `json:"limited"`
- PrevBatch string `json:"prev_batch"`
+ Limited bool `json:"limited"`
+ PrevBatch string `json:"prev_batch"`
} `json:"timeline"`
}{
State: events{Events: []*mautrix.Event{leaveEvt}},
@@ -150,8 +150,8 @@ type events struct {
type timeline struct {
Events []*mautrix.Event `json:"events"`
- Limited bool `json:"limited"`
- PrevBatch string `json:"prev_batch"`
+ Limited bool `json:"limited"`
+ PrevBatch string `json:"prev_batch"`
}
type join struct {
State struct {
@@ -159,8 +159,8 @@ type join struct {
} `json:"state"`
Timeline struct {
Events []*mautrix.Event `json:"events"`
- Limited bool `json:"limited"`
- PrevBatch string `json:"prev_batch"`
+ Limited bool `json:"limited"`
+ PrevBatch string `json:"prev_batch"`
} `json:"timeline"`
Ephemeral struct {
Events []*mautrix.Event `json:"events"`
@@ -190,8 +190,8 @@ func newRespSync() *mautrix.RespSync {
} `json:"state"`
Timeline struct {
Events []*mautrix.Event `json:"events"`
- Limited bool `json:"limited"`
- PrevBatch string `json:"prev_batch"`
+ Limited bool `json:"limited"`
+ PrevBatch string `json:"prev_batch"`
} `json:"timeline"`
Ephemeral struct {
Events []*mautrix.Event `json:"events"`
@@ -211,8 +211,8 @@ func newRespSync() *mautrix.RespSync {
} `json:"state"`
Timeline struct {
Events []*mautrix.Event `json:"events"`
- Limited bool `json:"limited"`
- PrevBatch string `json:"prev_batch"`
+ Limited bool `json:"limited"`
+ PrevBatch string `json:"prev_batch"`
} `json:"timeline"`
})
return resp
diff --git a/vendor/maunium.net/go/mautrix/events.go b/vendor/maunium.net/go/mautrix/events.go
index c974bf9..7151c27 100644
--- a/vendor/maunium.net/go/mautrix/events.go
+++ b/vendor/maunium.net/go/mautrix/events.go
@@ -200,9 +200,9 @@ type Content struct {
PowerLevels
Member
Aliases []string `json:"aliases,omitempty"`
- CanonicalAlias
- RoomName
- RoomTopic
+ Alias string `json:"alias,omitempty"`
+ Name string `json:"name,omitempty"`
+ Topic string `json:"name,omitempty"`
RoomTags Tags `json:"tags,omitempty"`
TypingUserIDs []string `json:"user_ids,omitempty"`
@@ -244,11 +244,6 @@ func (content *Content) UnmarshalMember() (m Member, err error) {
return
}
-func (content *Content) UnmarshalCanonicalAlias() (ca CanonicalAlias, err error) {
- err = json.Unmarshal(content.VeryRaw, &ca)
- return
-}
-
func (content *Content) GetInfo() *FileInfo {
if content.Info == nil {
content.Info = &FileInfo{}
@@ -260,14 +255,6 @@ type Tags map[string]struct {
Order json.Number `json:"order"`
}
-type RoomName struct {
- Name string `json:"name,omitempty"`
-}
-
-type RoomTopic struct {
- Topic string `json:"topic,omitempty"`
-}
-
// Membership is an enum specifying the membership state of a room member.
type Membership string
@@ -297,10 +284,6 @@ type ThirdPartyInvite struct {
}
}
-type CanonicalAlias struct {
- Alias string `json:"alias,omitempty"`
-}
-
type PowerLevels struct {
usersLock sync.RWMutex `json:"-"`
Users map[string]int `json:"users,omitempty"`