fix: RoomEvent methods now use the pointer to the self

This commit is contained in:
ChronosX88 2019-08-18 18:40:10 +04:00
parent 06686b753f
commit 32a1556de1
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
3 changed files with 9 additions and 19 deletions

View File

@ -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

View File

@ -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))
}
}
}

View File

@ -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
}