Replace reflection to type assertion

This commit is contained in:
nxshock 2019-08-11 18:47:25 +05:00
parent 197b296a24
commit d3f90c8eda

View File

@ -2,7 +2,6 @@ package memory
import ( import (
"fmt" "fmt"
"reflect"
"regexp" "regexp"
"sort" "sort"
"strings" "strings"
@ -230,13 +229,12 @@ func extractEventsFromNodes(nodes []*sortedset.SortedSetNode) []events.Event {
} }
func isEventRelatedToUser(event events.Event, user internal.User) bool { func isEventRelatedToUser(event events.Event, user internal.User) bool {
// get RoomID field from event interface if roomEvent, ok := event.(*events.RoomEvent); ok {
// TODO: what if there are no RoomID field? if internal.InArray(roomEvent.RoomID, extractRoomIDsFromModel(user.JoinedRooms())) {
roomID := reflect.ValueOf(event).Elem().FieldByName("RoomID").Addr().Interface().(string) return true
}
if internal.InArray(roomID, extractRoomIDsFromModel(user.JoinedRooms())) {
return true
} }
return false return false
} }