internal

package
v0.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeviceListChanged = 1
	DeviceListLeft    = 2
)
View Source
const StateKeyLazy = "$LAZY"

Variables

This section is empty.

Functions

func Assert

func Assert(msg string, expr bool)

Assert that the expression is true, similar to assert() in C. If expr is false, print or panic.

If expr is false and SYNCV3_DEBUG=1 then the program panics. If expr is false and SYNCV3_DEBUG is unset or not '1' then the program logs an error along with a field which contains the file/line number of the caller/assertion of Assert. Assert should be used to verify invariants which should never be broken during normal functioning of the program, and shouldn't be used to log a normal error e.g network errors. Developers can make use of this function by setting SYNCV3_DEBUG=1 when running the server, which will fail-fast whenever a programming or logic error occurs.

The msg provided should be the expectation of the assert e.g:

Assert("list is not empty", len(list) > 0)

Which then produces:

assertion failed: list is not empty

func CalculateRoomName

func CalculateRoomName(heroInfo *RoomMetadata, maxNumNamesPerRoom int) string

func DecorateLogger added in v0.3.1

func DecorateLogger(ctx context.Context, l *zerolog.Event) *zerolog.Event

func DeviceListChangesArrays added in v0.5.0

func DeviceListChangesArrays(m map[string]int) (changed, left []string)

func HashedTokenFromRequest added in v0.2.0

func HashedTokenFromRequest(req *http.Request) (hashAccessToken string, accessToken string, err error)

func IsMembershipChange

func IsMembershipChange(eventJSON gjson.Result) bool

func RequestContext added in v0.3.1

func RequestContext(ctx context.Context) context.Context

prepare a request context so it can contain syncv3 info

func SetRequestContextResponseInfo added in v0.3.1

func SetRequestContextResponseInfo(
	ctx context.Context, since, next int64, numRooms int, txnID string, numToDeviceEvents, numGlobalAccountData int,
	numChangedDevices, numLeftDevices int,
)

func SetRequestContextUserID added in v0.3.1

func SetRequestContextUserID(ctx context.Context, userID string)

add the user ID to this request context. Need to have called RequestContext first.

func ToDeviceListChangesMap added in v0.5.0

func ToDeviceListChangesMap(changed, left []string) map[string]int

Types

type DeviceData added in v0.5.0

type DeviceData struct {
	// Contains the latest device_one_time_keys_count values.
	// Set whenever this field arrives down the v2 poller, and it replaces what was previously there.
	OTKCounts map[string]int `json:"otk"`
	// Contains the latest device_unused_fallback_key_types value
	// Set whenever this field arrives down the v2 poller, and it replaces what was previously there.
	FallbackKeyTypes []string `json:"fallback"`

	DeviceLists DeviceLists `json:"dl"`

	UserID   string
	DeviceID string
}

DeviceData contains useful data for this user's device. This list can be expanded without prompting schema changes. These values are upserted into the database and persisted forever.

type DeviceDataMap added in v0.5.0

type DeviceDataMap struct {
	Pos int64
	// contains filtered or unexported fields
}

func NewDeviceDataMap added in v0.5.0

func NewDeviceDataMap(startPos int64, devices []DeviceData) *DeviceDataMap

func (*DeviceDataMap) Get added in v0.5.0

func (d *DeviceDataMap) Get(userID, deviceID string) *DeviceData

func (*DeviceDataMap) Update added in v0.5.0

func (d *DeviceDataMap) Update(dd DeviceData) DeviceData

type DeviceLists added in v0.5.0

type DeviceLists struct {
	// map user_id -> DeviceList enum
	New  map[string]int `json:"n"`
	Sent map[string]int `json:"s"`
}

func (DeviceLists) Combine added in v0.5.0

func (dl DeviceLists) Combine(newer DeviceLists) DeviceLists

type HandlerError

type HandlerError struct {
	StatusCode int
	Err        error
	ErrCode    string
}

func ExpiredSessionError added in v0.7.1

func ExpiredSessionError() *HandlerError

func (*HandlerError) Error

func (e *HandlerError) Error() string

func (HandlerError) JSON

func (e HandlerError) JSON() []byte

type Hero

type Hero struct {
	ID   string
	Name string
}

type Receipt added in v0.7.3

type Receipt struct {
	RoomID    string `db:"room_id"`
	EventID   string `db:"event_id"`
	UserID    string `db:"user_id"`
	TS        int64  `db:"ts"`
	ThreadID  string `db:"thread_id"`
	IsPrivate bool
}

type RequiredStateMap added in v0.2.0

type RequiredStateMap struct {
	// contains filtered or unexported fields
}

func NewRequiredStateMap added in v0.2.0

func NewRequiredStateMap(eventTypesWithWildcardStateKeys map[string]struct{},
	stateKeysForWildcardEventType []string,
	eventTypeToStateKeys map[string][]string,
	allState, lazyLoading bool) *RequiredStateMap

func (*RequiredStateMap) Include added in v0.2.0

func (rsm *RequiredStateMap) Include(evType, stateKey string) bool

func (*RequiredStateMap) IsLazyLoading added in v0.7.0

func (rsm *RequiredStateMap) IsLazyLoading() bool

func (*RequiredStateMap) QueryStateMap added in v0.2.0

func (rsm *RequiredStateMap) QueryStateMap() map[string][]string

work out what to ask the storage layer: if we have wildcard event types we need to pull all room state and cannot only pull out certain event types. If we have wildcard state keys we need to use an empty list for state keys.

type RoomMetadata

type RoomMetadata struct {
	RoomID               string
	Heroes               []Hero
	NameEvent            string // the content of m.room.name, NOT the calculated name
	CanonicalAlias       string
	JoinCount            int
	InviteCount          int
	LastMessageTimestamp uint64
	Encrypted            bool
	PredecessorRoomID    *string
	UpgradedRoomID       *string
	RoomType             *string
	// if this room is a space, which rooms are m.space.child state events. This is the same for all users hence is global.
	ChildSpaceRooms map[string]struct{}
	// The latest m.typing ephemeral event for this room.
	TypingEvent json.RawMessage
}

Metadata about a room that is consistent between all users in the room.

func (*RoomMetadata) IsSpace added in v0.2.1

func (m *RoomMetadata) IsSpace() bool

func (*RoomMetadata) RemoveHero

func (m *RoomMetadata) RemoveHero(userID string)

func (*RoomMetadata) SameInviteCount added in v0.4.1

func (m *RoomMetadata) SameInviteCount(other *RoomMetadata) bool

func (*RoomMetadata) SameJoinCount added in v0.4.1

func (m *RoomMetadata) SameJoinCount(other *RoomMetadata) bool

func (*RoomMetadata) SameRoomName added in v0.3.1

func (m *RoomMetadata) SameRoomName(other *RoomMetadata) bool

SameRoomName checks if the fields relevant for room names have changed between the two metadatas. Returns true if there are no changes.

type UserDeviceKey added in v0.5.0

type UserDeviceKey struct {
	UserID   string
	DeviceID string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL