Documentation
¶
Overview ¶
Package types provides data types for persisting objects in the databases.
Index ¶
- Constants
- func ChnToGrp(chn string) string
- func FlattenDoubleSlice(data [][]string) []string
- func GrpToChn(grp string) string
- func IsChannel(name string) bool
- func P2PNameForUser(uid Uid, p2p string) (string, error)
- func TimeNow() time.Time
- type AccessMode
- func (m *AccessMode) ApplyDelta(delta string) error
- func (m *AccessMode) ApplyMutation(mutation string) error
- func (grant AccessMode) BetterEqual(want AccessMode) bool
- func (grant AccessMode) BetterThan(want AccessMode) bool
- func (o AccessMode) Delta(n AccessMode) string
- func (m AccessMode) IsAdmin() bool
- func (m AccessMode) IsApprover() bool
- func (m AccessMode) IsDefined() bool
- func (m AccessMode) IsDeleter() bool
- func (m AccessMode) IsInvalid() bool
- func (m AccessMode) IsJoiner() bool
- func (m AccessMode) IsOwner() bool
- func (m AccessMode) IsPresencer() bool
- func (m AccessMode) IsReader() bool
- func (m AccessMode) IsSharer() bool
- func (m AccessMode) IsWriter() bool
- func (m AccessMode) IsZero() bool
- func (m AccessMode) MarshalJSON() ([]byte, error)
- func (m AccessMode) MarshalText() ([]byte, error)
- func (m *AccessMode) Scan(val any) error
- func (m AccessMode) String() string
- func (m *AccessMode) UnmarshalJSON(b []byte) error
- func (m *AccessMode) UnmarshalText(b []byte) error
- func (m AccessMode) Value() (driver.Value, error)
- type Contact
- type Credential
- type DefaultAccess
- type DelMessage
- type DeviceDef
- type FileDef
- type KVMap
- type LastSeenUA
- type Message
- type ObjHeader
- type ObjState
- type QueryOpt
- type Range
- type RangeSorter
- type SoftDelete
- type StoreError
- type StringSlice
- type Subscription
- func (s *Subscription) GetDefaultAccess() *DefaultAccess
- func (s *Subscription) GetLastSeen() *time.Time
- func (s *Subscription) GetPublic() any
- func (s *Subscription) GetSeqId() int
- func (s *Subscription) GetState() ObjState
- func (s *Subscription) GetTouchedAt() time.Time
- func (s *Subscription) GetTrusted() any
- func (s *Subscription) GetUserAgent() string
- func (s *Subscription) GetWith() string
- func (s *Subscription) IsDummy() bool
- func (s *Subscription) LastModified() time.Time
- func (s *Subscription) SetDefaultAccess(auth, anon AccessMode)
- func (s *Subscription) SetDummy(dummy bool)
- func (s *Subscription) SetLastSeenAndUA(when *time.Time, ua string)
- func (s *Subscription) SetPublic(pub any)
- func (s *Subscription) SetSeqId(id int)
- func (s *Subscription) SetState(state ObjState)
- func (s *Subscription) SetTouchedAt(touchedAt time.Time)
- func (s *Subscription) SetTrusted(tstd any)
- func (s *Subscription) SetWith(with string)
- type Topic
- type TopicCat
- type Uid
- func (uid Uid) Compare(u2 Uid) int
- func (uid Uid) FndName() string
- func (uid Uid) IsZero() bool
- func (uid Uid) MarshalBinary() ([]byte, error)
- func (uid *Uid) MarshalJSON() ([]byte, error)
- func (uid *Uid) MarshalText() ([]byte, error)
- func (uid Uid) P2PName(u2 Uid) string
- func (uid Uid) PrefixId(prefix string) string
- func (uid Uid) SlfName() string
- func (uid Uid) String() string
- func (uid Uid) String32() string
- func (uid *Uid) UnmarshalBinary(b []byte) error
- func (uid *Uid) UnmarshalJSON(b []byte) error
- func (uid *Uid) UnmarshalText(src []byte) error
- func (uid Uid) UserId() string
- type UidGenerator
- type UidSlice
- type User
Constants ¶
const ( // ErrInternal means DB or other internal failure. ErrInternal = StoreError("internal") // ErrMalformed means the secret cannot be parsed or otherwise wrong. ErrMalformed = StoreError("malformed") // ErrFailed means authentication failed (wrong login or password, etc). ErrFailed = StoreError("failed") // ErrDuplicate means duplicate credential, i.e. non-unique login. ErrDuplicate = StoreError("duplicate value") // ErrUnsupported means an operation is not supported. ErrUnsupported = StoreError("unsupported") // ErrExpired means the secret has expired. ErrExpired = StoreError("expired") // ErrPolicy means policy violation, e.g. password too weak. ErrPolicy = StoreError("policy") // ErrCredentials means credentials like email or captcha must be validated. ErrCredentials = StoreError("credentials") // ErrUserNotFound means the user was not found. ErrUserNotFound = StoreError("user not found") // ErrTopicNotFound means the topic was not found. ErrTopicNotFound = StoreError("topic not found") // ErrNotFound means the object other then user or topic was not found. ErrNotFound = StoreError("not found") // ErrPermissionDenied means the operation is not permitted. ErrPermissionDenied = StoreError("denied") // ErrInvalidResponse means the client's response does not match server's expectation. ErrInvalidResponse = StoreError("invalid response") // ErrRedirected means the subscription request was redirected to another topic. ErrRedirected = StoreError("redirected") )
const ( // UploadStarted indicates that the upload has started but not finished yet. UploadStarted = iota // UploadCompleted indicates that the upload has completed successfully. UploadCompleted // UploadFailed indicates that the upload has failed. UploadFailed // UploadDeleted indicates that the upload is no longer needed and can be deleted. UploadDeleted )
Media handling constants
const NullValue = "\u2421"
NullValue is a Unicode DEL character which indicated that the value is being deleted.
const TimeFormatRFC3339 = "2006-01-02T15:04:05.999"
TimeFormatRFC3339 is a format string for writing timestamps as RFC3339.
Variables ¶
This section is empty.
Functions ¶
func ChnToGrp ¶ added in v0.16.8
ChnToGrp gets group topic name from channel name. If it's a non-channel group topic, the name is returned unchanged.
func FlattenDoubleSlice ¶ added in v0.16.7
FlattenDoubleSlice turns 2d slice into a 1d slice.
func IsChannel ¶ added in v0.17.0
IsChannel checks if the given topic name is a reference to a channel. The "nch" should not be considered a channel reference because it can only be used by the topic owner at the time of group topic creation.
func P2PNameForUser ¶ added in v0.18.0
P2PNameForUser takes a user ID and a full name of a P2P topic and generates the name of the P2P topic as it should be seen by the given user.
Types ¶
type AccessMode ¶
type AccessMode uint
AccessMode is a definition of access mode bits.
const ( ModeJoin AccessMode = 1 << iota // user can join, i.e. {sub} (J:1) ModeRead // user can receive broadcasts ({data}, {info}) (R:2) ModeWrite // user can Write, i.e. {pub} (W:4) ModePres // user can receive presence updates (P:8) ModeApprove // user can approve new members or evict existing members (A:0x10, 16) ModeDelete // user can hard-delete messages (D:0x40, 64) ModeOwner // user is the owner (O:0x80, 128) - full access ModeUnset // Non-zero value to indicate unknown or undefined mode (:0x100, 256), to make it different from ModeNone. ModeNone AccessMode = 0 // No access, requests to gain access are processed normally (N:0) // Normal user's access to a topic ("JRWPS", 47, 0x2F). ModeCPublic AccessMode = ModeJoin | ModeRead | ModeWrite | ModePres | ModeShare // User's subscription to 'me' and 'fnd' ("JPS", 41, 0x29). ModeCMeFnd AccessMode = ModeJoin | ModePres | ModeShare // User's subscription to 'slf' topic ("JRWDO", 199, 0xC7). ModeCSelf = ModeJoin | ModeRead | ModeWrite | ModeDelete | ModeOwner // Owner's subscription to a generic topic ("JRWPASDO", 255, 0xFF). ModeCFull AccessMode = ModeJoin | ModeRead | ModeWrite | ModePres | ModeApprove | ModeShare | ModeDelete | ModeOwner // Default P2P access mode ("JRWPA", 31, 0x1F). ModeCP2P AccessMode = ModeJoin | ModeRead | ModeWrite | ModePres | ModeApprove // P2P acess mode when hard-deleting messages is enabled ("JRWPAD", 95, 0x5F) ModeCP2PD AccessMode = ModeJoin | ModeRead | ModeWrite | ModePres | ModeApprove | ModeDelete // Default Auth access mode for a user ("JRWPAS", 63, 0x3F). ModeCAuth AccessMode = ModeCP2P | ModeCPublic // Read-only access to topic ("JR", 3). ModeCReadOnly = ModeJoin | ModeRead // Access to 'sys' topic by a root user ("JRWPD", 79, 0x4F). ModeCSys = ModeJoin | ModeRead | ModeWrite | ModePres | ModeDelete // Channel publisher: person authorized to publish content; no J: by invitation only ("RWPD", 78, 0x4E). ModeCChnWriter = ModeRead | ModeWrite | ModePres | ModeShare // Reader's access mode to a channel (JRP, 11, 0xB). ModeCChnReader = ModeJoin | ModeRead | ModePres // Admin: user who can modify access mode ("OA", dec: 144, hex: 0x90). ModeCAdmin = ModeOwner | ModeApprove ModeCSharer = ModeCAdmin | ModeShare // Invalid mode to indicate an error. ModeInvalid AccessMode = 0x100000 // All possible valid bits (excluding ModeInvalid and ModeUnset) = 0xFF, 255. ModeBitmask AccessMode = ModeJoin | ModeRead | ModeWrite | ModePres | ModeApprove | ModeShare | ModeDelete | ModeOwner )
Various access mode constants.
func ParseAcs ¶ added in v0.16.6
func ParseAcs(b []byte) (AccessMode, error)
ParseAcs parses AccessMode from a byte array.
func (*AccessMode) ApplyDelta ¶ added in v0.16.6
func (m *AccessMode) ApplyDelta(delta string) error
ApplyDelta applies the acs delta to AccessMode. Delta is in the same format as generated by AccessMode.Delta. E.g. JPRA.ApplyDelta(-PR+W) -> JWA.
func (*AccessMode) ApplyMutation ¶ added in v0.16.6
func (m *AccessMode) ApplyMutation(mutation string) error
ApplyMutation sets of modifies access mode: * if `mutation` contains either '+' or '-', attempts to apply a delta change on `m`. * otherwise, treats it as an assignment.
func (AccessMode) BetterEqual ¶
func (grant AccessMode) BetterEqual(want AccessMode) bool
BetterEqual checks if grant mode allows all permissions requested in want mode.
func (AccessMode) BetterThan ¶ added in v0.15.13
func (grant AccessMode) BetterThan(want AccessMode) bool
BetterThan checks if grant mode allows more permissions than requested in want mode.
func (AccessMode) Delta ¶
func (o AccessMode) Delta(n AccessMode) string
Delta between two modes as a string old.Delta(new). JRPAS -> JRWS: "+W-PA" Zero delta is an empty string ""
func (AccessMode) IsAdmin ¶
func (m AccessMode) IsAdmin() bool
IsAdmin check if owner O or approver A flag is set.
func (AccessMode) IsApprover ¶
func (m AccessMode) IsApprover() bool
IsApprover checks if approver A bit is set.
func (AccessMode) IsDefined ¶ added in v0.15.13
func (m AccessMode) IsDefined() bool
IsDefined checks if the mode is defined: not invalid and not unset. ModeNone is considered to be defined.
func (AccessMode) IsDeleter ¶
func (m AccessMode) IsDeleter() bool
IsDeleter checks if user can hard-delete messages (D flag is set).
func (AccessMode) IsInvalid ¶
func (m AccessMode) IsInvalid() bool
IsInvalid checks if mode is invalid.
func (AccessMode) IsJoiner ¶
func (m AccessMode) IsJoiner() bool
IsJoiner checks if joiner flag J is set.
func (AccessMode) IsOwner ¶
func (m AccessMode) IsOwner() bool
IsOwner checks if owner bit O is set.
func (AccessMode) IsPresencer ¶
func (m AccessMode) IsPresencer() bool
IsPresencer checks if user receives presence updates (P flag set).
func (AccessMode) IsReader ¶
func (m AccessMode) IsReader() bool
IsReader checks if reader flag R is set.
func (AccessMode) IsSharer ¶
func (m AccessMode) IsSharer() bool
IsSharer checks if approver A or sharer S or owner O flag is set.
func (AccessMode) IsWriter ¶
func (m AccessMode) IsWriter() bool
IsWriter checks if allowed to publish (writer flag W is set).
func (AccessMode) MarshalJSON ¶
func (m AccessMode) MarshalJSON() ([]byte, error)
MarshalJSON converts AccessMode to a quoted string.
func (AccessMode) MarshalText ¶
func (m AccessMode) MarshalText() ([]byte, error)
MarshalText converts AccessMode to ASCII byte slice.
func (*AccessMode) Scan ¶ added in v0.14.2
func (m *AccessMode) Scan(val any) error
Scan is an implementation of sql.Scanner interface. It expects the value to be a byte slice representation of an ASCII string.
func (AccessMode) String ¶
func (m AccessMode) String() string
String returns string representation of AccessMode.
func (*AccessMode) UnmarshalJSON ¶
func (m *AccessMode) UnmarshalJSON(b []byte) error
UnmarshalJSON reads AccessMode from a quoted string.
func (*AccessMode) UnmarshalText ¶
func (m *AccessMode) UnmarshalText(b []byte) error
UnmarshalText parses access mode string as byte slice. Does not change the mode if the string is empty or invalid.
type Contact ¶
type Contact struct {
Id string
MatchOn []string
Access DefaultAccess
LastSeen time.Time
Public any
}
Contact is a result of a search for connections
type Credential ¶ added in v0.14.4
type Credential struct {
ObjHeader `bson:",inline"`
// Credential owner
User string
// Verification method (email, tel, captcha, etc)
Method string
// Credential value - `jdoe@example.com` or `+12345678901`
Value string
// Expected response
Resp string
// If credential was successfully confirmed
Done bool
// Retry count
Retries int
}
Credential hold data needed to validate and check validity of a credential like email or phone.
type DefaultAccess ¶
type DefaultAccess struct {
Auth AccessMode
Anon AccessMode
}
DefaultAccess is a per-topic default access modes
func (*DefaultAccess) Scan ¶ added in v0.14.2
func (da *DefaultAccess) Scan(val any) error
Scan is an implementation of Scanner interface so the value can be read from SQL DBs It assumes the value is serialized and stored as JSON
type DelMessage ¶ added in v0.14.2
type DelMessage struct {
ObjHeader `bson:",inline"`
Topic string
DeletedFor string
DelId int
SeqIdRanges []Range
// contains filtered or unexported fields
}
DelMessage is a log entry of a deleted message range.
func (*DelMessage) GetNewerThan ¶ added in v0.24.0
func (dm *DelMessage) GetNewerThan() *time.Time
GetNewerThan returns a newerThan delete query parameter.
func (*DelMessage) SetNewerThan ¶ added in v0.24.0
func (dm *DelMessage) SetNewerThan(t time.Time)
SetNewerThan sets a newerThan delete query parameter.
type DeviceDef ¶
type DeviceDef struct {
// Device registration ID
DeviceId string
// Device platform (iOS, Android, Web)
Platform string
// Last logged in
LastSeen time.Time
// Device language, ISO code
Lang string
}
DeviceDef is the data provided by connected device. Used primarily for push notifications.
type FileDef ¶ added in v0.15.2
type FileDef struct {
ObjHeader `bson:",inline"`
// Status of upload
Status int
// User who created the file
User string
// Type of the file.
MimeType string
// Size of the file in bytes.
Size int64
// Internal file location, i.e. path on disk or an S3 blob address.
Location string
// ETag generated by the file server.
ETag string
}
FileDef is a stored record of a file upload
type KVMap ¶ added in v0.24.0
MessageHeaders is needed to attach Scan() to.
type LastSeenUA ¶ added in v0.17.9
type LastSeenUA struct {
// When is the timestamp when the user was last online.
When time.Time
// UserAgent is the client UA of the last online access.
UserAgent string
}
LastSeenUA is a timestamp and a user agent of when the user was last seen.
type Message ¶
type Message struct {
ObjHeader `bson:",inline"`
DeletedAt *time.Time `json:"DeletedAt,omitempty" bson:",omitempty"`
// ID of the hard-delete operation
DelId int `json:"DelId,omitempty" bson:",omitempty"`
// List of users who have marked this message as soft-deleted
DeletedFor []SoftDelete `json:"DeletedFor,omitempty" bson:",omitempty"`
SeqId int
Topic string
// Sender's user ID as string (without 'usr' prefix), could be empty.
From string
Head KVMap `json:"Head,omitempty" bson:",omitempty"`
Content any
}
Message is a stored {data} message
type ObjHeader ¶
type ObjHeader struct {
// using string to get around rethinkdb's problems with uint64;
// `bson:"_id"` tag is for mongodb to use as primary key '_id'.
Id string `bson:"_id"`
CreatedAt time.Time
UpdatedAt time.Time
// contains filtered or unexported fields
}
ObjHeader is the header shared by all stored objects.
func (*ObjHeader) InitTimes ¶
func (h *ObjHeader) InitTimes()
InitTimes initializes time.Time variables in the header to current time.
func (*ObjHeader) MergeTimes ¶
MergeTimes intelligently copies time.Time variables from h2 to h.
type ObjState ¶ added in v0.16.4
type ObjState int
ObjState represents information on objects state, such as an indication that User or Topic is suspended/soft-deleted.
const ( // StateOK indicates normal user or topic. StateOK ObjState = 0 // StateSuspended indicates suspended user or topic. StateSuspended ObjState = 10 // StateDeleted indicates soft-deleted user or topic. StateDeleted ObjState = 20 // StateUndefined indicates state which has not been set explicitly. StateUndefined ObjState = 30 )
func NewObjState ¶ added in v0.16.4
NewObjState parses string into an ObjState.
func (ObjState) MarshalJSON ¶ added in v0.16.4
MarshalJSON converts ObjState to a quoted string.
func (*ObjState) Scan ¶ added in v0.16.4
Scan is an implementation of sql.Scanner interface. It expects the value to be a byte slice representation of an ASCII string.
func (*ObjState) UnmarshalJSON ¶ added in v0.16.4
UnmarshalJSON reads ObjState from a quoted string.
type QueryOpt ¶ added in v0.15.0
type QueryOpt struct {
// Subscription query
User Uid
Topic string
IfModifiedSince *time.Time
// ID-based query parameters: Messages
Since int
Before int
// Common parameter
Limit int
// Ranges of IDs.
IdRanges []Range
}
QueryOpt is options of a query, [since, before] - both ends inclusive (closed)
type Range ¶ added in v0.14.2
Range is a range of message SeqIDs. Low end is inclusive (closed), high end is exclusive (open): [Low, Hi). If the range contains just one ID, Hi is set to 0
func SliceToRanges ¶ added in v0.24.0
Convert a slice of int values to a slice of ranges. The int slice must be sorted low -> high.
type RangeSorter ¶ added in v0.14.2
type RangeSorter []Range
RangeSorter is a helper type required by 'sort' package.
func (RangeSorter) Len ¶ added in v0.14.2
func (rs RangeSorter) Len() int
Len is the length of the range.
func (RangeSorter) Less ¶ added in v0.14.2
func (rs RangeSorter) Less(i, j int) bool
Less is a comparator. Sort by Low ascending, then sort by Hi descending
func (RangeSorter) Normalize ¶ added in v0.14.2
func (rs RangeSorter) Normalize() RangeSorter
Normalize ranges - remove overlaps: [1..4],[2..4],[5..7] -> [1..7]. The ranges are expected to be sorted. Ranges are inclusive-inclusive, i.e. [1..3] -> 1, 2, 3.
func (RangeSorter) Swap ¶ added in v0.14.2
func (rs RangeSorter) Swap(i, j int)
Swap swaps two items in a slice.
type SoftDelete ¶
SoftDelete is a single DB record of soft-deletetion.
type StoreError ¶ added in v0.14.4
type StoreError string
StoreError satisfies Error interface but allows constant values for direct comparison.
func (StoreError) Error ¶ added in v0.14.4
func (s StoreError) Error() string
Error is required by error interface.
type StringSlice ¶ added in v0.14.2
type StringSlice []string
StringSlice is defined so Scanner and Valuer can be attached to it.
func (*StringSlice) Scan ¶ added in v0.14.2
func (ss *StringSlice) Scan(val any) error
Scan implements sql.Scanner interface.
type Subscription ¶
type Subscription struct {
ObjHeader `bson:",inline"`
// User who has relationship with the topic
User string
// Topic subscribed to
Topic string
DeletedAt *time.Time `bson:",omitempty"`
// ID of the latest Soft-delete operation
DelId int
// Last SeqId reported by user as received by at least one of his sessions
RecvSeqId int
// Last SeqID reported read by the user
ReadSeqId int
// Access mode requested by this user
ModeWant AccessMode
// Access mode granted to this user
ModeGiven AccessMode
// User's private data associated with the subscription to topic
Private any
// contains filtered or unexported fields
}
Subscription to a topic
func (*Subscription) GetDefaultAccess ¶
func (s *Subscription) GetDefaultAccess() *DefaultAccess
GetDefaultAccess returns default access.
func (*Subscription) GetLastSeen ¶
func (s *Subscription) GetLastSeen() *time.Time
GetLastSeen returns lastSeen.
func (*Subscription) GetPublic ¶
func (s *Subscription) GetPublic() any
GetPublic reads value of `public`.
func (*Subscription) GetState ¶ added in v0.16.4
func (s *Subscription) GetState() ObjState
GetState returns topic's or user's state.
func (*Subscription) GetTouchedAt ¶ added in v0.14.6
func (s *Subscription) GetTouchedAt() time.Time
GetTouchedAt returns touchedAt.
func (*Subscription) GetTrusted ¶ added in v0.18.0
func (s *Subscription) GetTrusted() any
GetTrusted reads value of `trusted`.
func (*Subscription) GetUserAgent ¶
func (s *Subscription) GetUserAgent() string
GetUserAgent returns userAgent.
func (*Subscription) GetWith ¶
func (s *Subscription) GetWith() string
GetWith returns the other user for P2P subscriptions.
func (*Subscription) IsDummy ¶ added in v0.21.2
func (s *Subscription) IsDummy() bool
IsDummy is true if this subscription object as only partially intialized.
func (*Subscription) LastModified ¶ added in v0.18.0
func (s *Subscription) LastModified() time.Time
LastModified returns the greater of either TouchedAt or UpdatedAt.
func (*Subscription) SetDefaultAccess ¶
func (s *Subscription) SetDefaultAccess(auth, anon AccessMode)
SetDefaultAccess updates default access values.
func (*Subscription) SetDummy ¶ added in v0.21.2
func (s *Subscription) SetDummy(dummy bool)
SetDummy marks this subscription object as only partially intialized.
func (*Subscription) SetLastSeenAndUA ¶
func (s *Subscription) SetLastSeenAndUA(when *time.Time, ua string)
SetLastSeenAndUA updates lastSeen time and userAgent.
func (*Subscription) SetPublic ¶
func (s *Subscription) SetPublic(pub any)
SetPublic assigns a value to `public`, otherwise not accessible from outside the package.
func (*Subscription) SetState ¶ added in v0.16.4
func (s *Subscription) SetState(state ObjState)
SetState assigns topic's or user's state.
func (*Subscription) SetTouchedAt ¶ added in v0.14.6
func (s *Subscription) SetTouchedAt(touchedAt time.Time)
SetTouchedAt sets the value of touchedAt.
func (*Subscription) SetTrusted ¶ added in v0.18.0
func (s *Subscription) SetTrusted(tstd any)
SetTrusted assigns a value to `trusted`, otherwise not accessible from outside the package.
func (*Subscription) SetWith ¶
func (s *Subscription) SetWith(with string)
SetWith sets other user for P2P subscriptions.
type Topic ¶
type Topic struct {
ObjHeader `bson:",inline"`
// State of the topic: normal (ok), suspended, deleted
State ObjState
StateAt *time.Time `json:"StateAt,omitempty" bson:",omitempty"`
// Timestamp when the last message has passed through the topic
TouchedAt time.Time
// Indicates that the topic is a channel.
UseBt bool
// Topic owner. Could be zero
Owner string
// Default access to topic
Access DefaultAccess
// Server-issued sequential ID
SeqId int
// If messages were deleted, sequential id of the last operation to delete them
DelId int
Public any
Trusted any
// Indexed tags for finding this topic.
Tags StringSlice
// Auxiliary set of key-value pairs.
Aux KVMap `json:"Aux,omitempty" bson:",omitempty"`
// contains filtered or unexported fields
}
Topic stored in database. Topic's name is Id
func (*Topic) GetAccess ¶
func (t *Topic) GetAccess(uid Uid) (mode AccessMode)
GetAccess returns given user's access mode.
func (*Topic) GetPrivate ¶
GetPrivate returns given user's private value.
func (*Topic) GiveAccess ¶
func (t *Topic) GiveAccess(uid Uid, want, given AccessMode)
GiveAccess updates access mode for the given user.
func (*Topic) SetPrivate ¶
SetPrivate updates private value for the given user.
type TopicCat ¶
type TopicCat int
TopicCat is an enum of topic categories.
const ( // TopicCatMe is a value denoting 'me' topic. TopicCatMe TopicCat = iota // TopicCatFnd is a value denoting 'fnd' topic. TopicCatFnd // TopicCatP2P is a value denoting 'p2p topic. TopicCatP2P // TopicCatGrp is a value denoting group topic. TopicCatGrp // TopicCatSys is a constant indicating a system topic. TopicCatSys // TopicCatSlf si a constant indicating a 'self' topic, i.e. topic for saved messages and notes. TopicCatSlf )
func GetTopicCat ¶
GetTopicCat given topic name returns topic category.
type Uid ¶
type Uid uint64
Uid is a database-specific record id, suitable to be used as a primary key.
const ZeroUid Uid = 0
ZeroUid is a constant representing uninitialized Uid.
func ParseUid32 ¶ added in v0.15.2
ParseUid32 parses base32-encoded string into Uid.
func ParseUserId ¶
ParseUserId parses user ID of the form "usrXXXXXX".
func (Uid) Compare ¶
Compare returns 0 if uid is equal to u2, 1 if u2 is greater than uid, -1 if u2 is smaller.
func (Uid) MarshalBinary ¶
MarshalBinary converts Uid to byte slice.
func (*Uid) MarshalJSON ¶
MarshalJSON converts Uid to double quoted ("ajjj") string.
func (*Uid) MarshalText ¶
MarshalText converts Uid to string represented as byte slice.
func (Uid) String32 ¶ added in v0.15.2
String32 converts Uid to lowercase base32 string (suitable for file names on Windows).
func (*Uid) UnmarshalBinary ¶
UnmarshalBinary reads Uid from byte slice.
func (*Uid) UnmarshalJSON ¶
UnmarshalJSON reads Uid from a double quoted string.
func (*Uid) UnmarshalText ¶
UnmarshalText reads Uid from string represented as byte slice.
type UidGenerator ¶
type UidGenerator struct {
// contains filtered or unexported fields
}
UidGenerator holds snowflake and encryption paramenets. RethinkDB generates UUIDs as primary keys. Using snowflake-generated uint64 instead.
func (*UidGenerator) DecodeUid ¶ added in v0.14.2
func (ug *UidGenerator) DecodeUid(uid Uid) int64
DecodeUid takes an encrypted Uid and decrypts it into a non-negative int64. This is needed for go/sql compatibility where uint64 with high bit set is unsupported and possibly for other uses such as MySQL's recommendation for sequential primary keys.
func (*UidGenerator) EncodeInt64 ¶ added in v0.14.2
func (ug *UidGenerator) EncodeInt64(val int64) Uid
EncodeInt64 takes a positive int64 and encrypts it into a Uid. This is needed for go/sql compatibility where uint64 with high bit set is unsupported and possibly for other uses such as MySQL's recommendation for sequential primary keys.
func (*UidGenerator) Get ¶
func (ug *UidGenerator) Get() Uid
Get generates a unique weakly-encryped random-looking ID. The Uid is a unit64 with the highest bit possibly set which makes it incompatible with go's pre-1.9 sql package.
func (*UidGenerator) GetStr ¶
func (ug *UidGenerator) GetStr() string
GetStr generates the same unique ID as Get then returns it as base64-encoded string. Slightly more efficient than calling Get() then base64-encoding the result.
type UidSlice ¶ added in v0.15.7
type UidSlice []Uid
UidSlice is a slice of Uids sorted in ascending order.
func (*UidSlice) Add ¶ added in v0.15.7
Add uid to UidSlice keeping it sorted. Duplicates are ignored.
type User ¶
type User struct {
ObjHeader `bson:",inline"`
State ObjState
StateAt *time.Time `json:"StateAt,omitempty" bson:",omitempty"`
// Default access to user for P2P topics (used as default modeGiven)
Access DefaultAccess
// Last time when the user joined 'me' topic, by User Agent
LastSeen *time.Time
// User agent provided when accessing the topic last time
UserAgent string
Public any
Trusted any
// Unique indexed tags (email, phone) for finding this user. Stored on the
// 'users' as well as indexed in 'tagunique'
Tags StringSlice
// Info on known devices, used for push notifications
Devices map[string]*DeviceDef `bson:"__devices,skip,omitempty"`
// Same for mongodb scheme. Ignore in other db backends if its not suitable.
DeviceArray []*DeviceDef `json:"-" bson:"devices"`
}
User is a representation of a DB-stored user record.