From 32a1556de162c959fe484014ca5be391f733e266 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Sun, 18 Aug 2019 18:40:10 +0400 Subject: [PATCH] fix: RoomEvent methods now use the pointer to the self --- internal/backends/memory/backend.go | 12 +----------- internal/backends/memory/user.go | 4 ++-- internal/models/events/room_event.go | 12 ++++++------ 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/internal/backends/memory/backend.go b/internal/backends/memory/backend.go index 82a6f4c..5b40948 100644 --- a/internal/backends/memory/backend.go +++ b/internal/backends/memory/backend.go @@ -15,7 +15,6 @@ import ( "github.com/signaller-matrix/signaller/internal/models/createroom" "github.com/signaller-matrix/signaller/internal/models/events" "github.com/tidwall/buntdb" - "github.com/wangjia184/sortedset" ) type Backend struct { @@ -232,7 +231,7 @@ func (backend *Backend) GetEventsSince(user internal.User, sinceToken string, li if err == nil { json.Unmarshal([]byte(val), sinceEvent) } - sinceRoomEvent := sinceEvent.(events.RoomEvent) + sinceRoomEvent := sinceEvent.(*events.RoomEvent) tx.AscendRange("origin_server_ts", `{"origin_server_ts": `+string(sinceRoomEvent.OriginServerTs)+`}`, `{"origin_server_ts": `+string(time.Now().Unix())+`}`, func(key, value string) bool { var unmarshalledEvent events.Event json.Unmarshal([]byte(value), unmarshalledEvent) @@ -261,15 +260,6 @@ func (backend *Backend) GetEventsSince(user internal.User, sinceToken string, li return nil } -func extractEventsFromNodes(nodes []*sortedset.SortedSetNode) []events.Event { - var eventsSlice []events.Event - for _, e := range nodes { - eventsSlice = append(eventsSlice, e.Value.(events.Event)) - } - - return eventsSlice -} - func isEventRelatedToUser(event events.Event, user internal.User) bool { if roomEvent, ok := event.(*events.RoomEvent); ok { if internal.InArray(roomEvent.RoomID, extractRoomIDsFromModel(user.JoinedRooms())) { // TODO check for invited or archived rooms diff --git a/internal/backends/memory/user.go b/internal/backends/memory/user.go index 8398739..2d321ae 100644 --- a/internal/backends/memory/user.go +++ b/internal/backends/memory/user.go @@ -404,9 +404,9 @@ func (user *User) Sync(token string, request mSync.SyncRequest) (response *mSync func filterEventsByRoom(roomID string, eventList []events.Event) []events.RoomEvent { var filteredEventList []events.RoomEvent for _, event := range eventList { - if roomEvent, ok := event.(events.RoomEvent); ok { + if roomEvent, ok := event.(*events.RoomEvent); ok { if roomEvent.RoomID == roomID { - filteredEventList = append(filteredEventList, event.(events.RoomEvent)) + filteredEventList = append(filteredEventList, *event.(*events.RoomEvent)) } } } diff --git a/internal/models/events/room_event.go b/internal/models/events/room_event.go index 36f714d..fbeb1ac 100644 --- a/internal/models/events/room_event.go +++ b/internal/models/events/room_event.go @@ -15,14 +15,14 @@ type RoomEvent struct { 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. } -func (roomEvent RoomEvent) Content() json.RawMessage { - return roomEvent.ContentData +func (this *RoomEvent) Content() json.RawMessage { + return this.ContentData } -func (roomEvent RoomEvent) ID() string { - return roomEvent.EventID +func (this *RoomEvent) ID() string { + return this.EventID } -func (roomEvent RoomEvent) Type() EventType { - return roomEvent.EType +func (this *RoomEvent) Type() EventType { + return this.EType }