From cb452bbd98dcc1d77356abef7a1b54792183404d Mon Sep 17 00:00:00 2001 From: nxshock Date: Sat, 10 Aug 2019 10:48:35 +0500 Subject: [PATCH] Fix root type path --- internal/backends/memory/roomevents.go | 3 ++- internal/backends/memory/user.go | 13 ++++++------- internal/models/rooms/rooms.go | 16 +++++++++------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/internal/backends/memory/roomevents.go b/internal/backends/memory/roomevents.go index b09892c..f1469c3 100644 --- a/internal/backends/memory/roomevents.go +++ b/internal/backends/memory/roomevents.go @@ -5,12 +5,13 @@ import ( "time" "github.com/signaller-matrix/signaller/internal" + "github.com/signaller-matrix/signaller/internal/models/common" "github.com/signaller-matrix/signaller/internal/models/rooms" ) type RoomEvent struct { Content json.RawMessage - Type rooms.Type + Type common.EventType EventID string Sender internal.User OriginServerTS time.Time diff --git a/internal/backends/memory/user.go b/internal/backends/memory/user.go index b08d535..9b72485 100644 --- a/internal/backends/memory/user.go +++ b/internal/backends/memory/user.go @@ -10,7 +10,6 @@ import ( "github.com/signaller-matrix/signaller/internal/models/common" "github.com/signaller-matrix/signaller/internal/models/createroom" "github.com/signaller-matrix/signaller/internal/models/devices" - "github.com/signaller-matrix/signaller/internal/models/rooms" ) type User struct { @@ -50,7 +49,7 @@ func (user *User) CreateRoom(request createroom.Request) (internal.Room, models. // Create room event events = append(events, RoomEvent{ Content: nil, - Type: rooms.Create, + Type: common.Create, EventID: internal.RandomString(eventIDSize), Sender: user, OriginServerTS: t}) @@ -60,7 +59,7 @@ func (user *User) CreateRoom(request createroom.Request) (internal.Room, models. // Set join rules event events = append(events, RoomEvent{ Content: []byte(request.Visibility), // TODO: check visibility vs join rules - Type: rooms.JoinRules, + Type: common.JoinRules, EventID: internal.RandomString(eventIDSize), Sender: user, OriginServerTS: t}) @@ -69,7 +68,7 @@ func (user *User) CreateRoom(request createroom.Request) (internal.Room, models. if request.Name != "" { events = append(events, RoomEvent{ Content: nil, // TODO: add - Type: rooms.Name, + Type: common.Name, EventID: internal.RandomString(eventIDSize), Sender: user, OriginServerTS: t}) @@ -79,7 +78,7 @@ func (user *User) CreateRoom(request createroom.Request) (internal.Room, models. if request.RoomAliasName != "" { events = append(events, RoomEvent{ Content: nil, // TODO: add - Type: rooms.CanonicalAlias, + Type: common.CanonicalAlias, EventID: internal.RandomString(eventIDSize), Sender: user, OriginServerTS: t}) @@ -125,7 +124,7 @@ func (user *User) SetTopic(room internal.Room, topic string) models.ApiError { memRoom.mutex.Unlock() rEvent := &RoomEvent{ - Type: rooms.Topic, + Type: common.Topic, Sender: user, OriginServerTS: time.Now(), Room: room} @@ -206,7 +205,7 @@ func (user *User) SendMessage(room internal.Room, text string) models.ApiError { rEvent := &RoomEvent{ Content: nil, - Type: rooms.Message, + Type: common.Message, EventID: internal.RandomString(defaultTokenSize), Sender: user, OriginServerTS: time.Now(), diff --git a/internal/models/rooms/rooms.go b/internal/models/rooms/rooms.go index a5ee53d..185c261 100644 --- a/internal/models/rooms/rooms.go +++ b/internal/models/rooms/rooms.go @@ -3,6 +3,8 @@ package rooms import ( "encoding/json" + "github.com/signaller-matrix/signaller/internal/models/common" + "github.com/signaller-matrix/signaller/internal/models/events" ) @@ -17,13 +19,13 @@ const ( // https://matrix.org/docs/spec/client_server/latest#room-event-fields type Event struct { - Content json.RawMessage `json:"content"` // Required. The fields in this object will vary depending on the type of event. When interacting with the REST API, this is the HTTP body. - Type Type `json:"type"` // Required. The type of event. This SHOULD be namespaced similar to Java package naming conventions e.g. 'com.example.subdomain.event.type' - EventID string `json:"event_id"` // Required. The globally unique event identifier. - Sender string `json:"sender"` // Required. Contains the fully-qualified ID of the user who sent this event. - OriginServerTS int64 `json:"origin_server_ts"` // Required. Timestamp in milliseconds on originating homeserver when this event was sent. - Unsigned UnsignedData `json:"unsigned,omitempty"` // Contains optional extra information about the event. - RoomID string `json:"room_id"` // Required. The ID of the room associated with this event. Will not be present on events that arrive through /sync, despite being required everywhere else. + Content json.RawMessage `json:"content"` // Required. The fields in this object will vary depending on the type of event. When interacting with the REST API, this is the HTTP body. + Type common.EventType `json:"type"` // Required. The type of event. This SHOULD be namespaced similar to Java package naming conventions e.g. 'com.example.subdomain.event.type' + EventID string `json:"event_id"` // Required. The globally unique event identifier. + Sender string `json:"sender"` // Required. Contains the fully-qualified ID of the user who sent this event. + OriginServerTS int64 `json:"origin_server_ts"` // Required. Timestamp in milliseconds on originating homeserver when this event was sent. + Unsigned UnsignedData `json:"unsigned,omitempty"` // Contains optional extra information about the event. + RoomID string `json:"room_id"` // Required. The ID of the room associated with this event. Will not be present on events that arrive through /sync, despite being required everywhere else. } type UnsignedData struct {