Documentation ¶
Index ¶
- func TimeNow() time.Time
- type AccessMode
- func (grant AccessMode) BetterEqual(want AccessMode) bool
- func (o AccessMode) Delta(n AccessMode) string
- func (a AccessMode) IsAdmin() bool
- func (a AccessMode) IsApprover() bool
- func (a AccessMode) IsDeleter() bool
- func (a AccessMode) IsInvalid() bool
- func (a AccessMode) IsJoiner() bool
- func (a AccessMode) IsOwner() bool
- func (a AccessMode) IsPresencer() bool
- func (a AccessMode) IsReader() bool
- func (a AccessMode) IsSharer() bool
- func (a AccessMode) IsWriter() bool
- func (a AccessMode) IsZero() bool
- func (m AccessMode) MarshalJSON() ([]byte, error)
- func (m AccessMode) MarshalText() ([]byte, error)
- func (m AccessMode) String() string
- func (m *AccessMode) UnmarshalJSON(b []byte) error
- func (m *AccessMode) UnmarshalText(b []byte) error
- type BrowseOpt
- type Contact
- type DefaultAccess
- type DeviceDef
- type Message
- type ObjHeader
- type SoftDelete
- type Subscription
- func (s *Subscription) GetDefaultAccess() *DefaultAccess
- func (s *Subscription) GetHardClearId() int
- func (s *Subscription) GetLastSeen() time.Time
- func (s *Subscription) GetPublic() interface{}
- func (s *Subscription) GetSeqId() int
- func (s *Subscription) GetUserAgent() string
- func (s *Subscription) GetWith() string
- func (s *Subscription) SetDefaultAccess(auth, anon AccessMode)
- func (s *Subscription) SetHardClearId(id int)
- func (s *Subscription) SetLastSeenAndUA(when time.Time, ua string)
- func (s *Subscription) SetPublic(pub interface{})
- func (s *Subscription) SetSeqId(id int)
- func (s *Subscription) SetWith(with string)
- type Topic
- type TopicAccess
- 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) String() 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 User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AccessMode ¶
type AccessMode uint
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) ModeDelete // user can hard-delete messages (D:0x40) ModeOwner // user is the owner (O:0x80) - full access ModeUnset // Non-zero value to indicate unknown or undefined mode (:0x100), ModeNone AccessMode = 0 // No access, requests to gain access are processed normally (N) // Normal user's access to a topic ModeCPublic AccessMode = ModeJoin | ModeRead | ModeWrite | ModePres | ModeShare // User's subscription to 'me' and 'fnd' - user can only read and delete incoming invites ModeCSelf AccessMode = ModeJoin | ModeRead | ModeDelete | ModePres // Owner's subscription to a generic topic ModeCFull AccessMode = ModeJoin | ModeRead | ModeWrite | ModePres | ModeApprove | ModeShare | ModeDelete | ModeOwner // Default P2P access mode ModeCP2P AccessMode = ModeJoin | ModeRead | ModeWrite | ModePres | ModeApprove // Read-only access to topic (0x3) ModeCReadOnly = ModeJoin | ModeRead // Admin: user who can modify access mode (hex: 0x90, dec: 144) ModeCAdmin = ModeOwner | ModeApprove ModeCSharer = ModeCAdmin | ModeShare // Invalid mode to indicate an error ModeInvalid AccessMode = 0x100000 )
Various access mode constants
func (AccessMode) BetterEqual ¶
func (grant AccessMode) BetterEqual(want AccessMode) bool
Check if grant mode allows all that was 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) IsDeleter ¶
func (a AccessMode) IsDeleter() bool
Check if user can hard-delete messages
func (AccessMode) IsPresencer ¶
func (a AccessMode) IsPresencer() bool
Check if user recieves presence updates
func (AccessMode) MarshalJSON ¶
func (m AccessMode) MarshalJSON() ([]byte, error)
func (AccessMode) MarshalText ¶
func (m AccessMode) MarshalText() ([]byte, error)
func (AccessMode) String ¶
func (m AccessMode) String() string
func (*AccessMode) UnmarshalJSON ¶
func (m *AccessMode) UnmarshalJSON(b []byte) error
func (*AccessMode) UnmarshalText ¶
func (m *AccessMode) UnmarshalText(b []byte) error
Parse access mode string. Do 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 interface{} }
Result of a search for connections
type DefaultAccess ¶
type DefaultAccess struct { Auth AccessMode Anon AccessMode }
Per-topic default access modes
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 }
Data provided by connected device. Used primarily for push notifications
type Message ¶
type Message struct { ObjHeader // List of users who have marked this message as soft-deleted DeletedFor []SoftDelete SeqId int Topic string // UID as string of the user who sent the message, could be empty From string Head map[string]string Content interface{} }
Stored {data} message
type ObjHeader ¶
type ObjHeader struct { Id string // using string to get around rethinkdb's problems with unit64 CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time // contains filtered or unexported fields }
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 ¶
InitTimes intelligently copies time.Time variables from h2 to h.
type SoftDelete ¶
type Subscription ¶
type Subscription struct { ObjHeader // User who has relationship with the topic User string // Topic subscribed to Topic string // Subscription state, currently unused State int // User soft-deleted messages equal or lower to this seq ID ClearId 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 interface{} // contains filtered or unexported fields }
Subscription to a topic
func (*Subscription) GetDefaultAccess ¶
func (s *Subscription) GetDefaultAccess() *DefaultAccess
func (*Subscription) GetHardClearId ¶
func (s *Subscription) GetHardClearId() int
func (*Subscription) GetLastSeen ¶
func (s *Subscription) GetLastSeen() time.Time
func (*Subscription) GetPublic ¶
func (s *Subscription) GetPublic() interface{}
func (*Subscription) GetSeqId ¶
func (s *Subscription) GetSeqId() int
func (*Subscription) GetUserAgent ¶
func (s *Subscription) GetUserAgent() string
func (*Subscription) GetWith ¶
func (s *Subscription) GetWith() string
func (*Subscription) SetDefaultAccess ¶
func (s *Subscription) SetDefaultAccess(auth, anon AccessMode)
func (*Subscription) SetHardClearId ¶
func (s *Subscription) SetHardClearId(id int)
func (*Subscription) SetLastSeenAndUA ¶
func (s *Subscription) SetLastSeenAndUA(when time.Time, ua string)
func (*Subscription) SetPublic ¶
func (s *Subscription) SetPublic(pub interface{})
SetPublic assigns to public, otherwise not accessible from outside the package
func (*Subscription) SetSeqId ¶
func (s *Subscription) SetSeqId(id int)
func (*Subscription) SetWith ¶
func (s *Subscription) SetWith(with string)
type Topic ¶
type Topic struct { ObjHeader State int // Use bearer token or use ACL UseBt bool // Default access to topic Access DefaultAccess // Server-issued sequential ID SeqId int // If messages were deleted, id of the last deleted message ClearId int Public interface{} // contains filtered or unexported fields }
Topic stored in database
func (*Topic) GetAccess ¶
func (t *Topic) GetAccess(uid Uid) (mode AccessMode)
func (*Topic) GetPrivate ¶
func (*Topic) GiveAccess ¶
func (t *Topic) GiveAccess(uid Uid, want AccessMode, given AccessMode)
func (*Topic) SetPrivate ¶
type TopicAccess ¶
type TopicAccess struct { User string Topic string Want AccessMode Given AccessMode }
Relationship between users & topics, stored in database as Subscription
type Uid ¶
type Uid uint64
Uid is a database-specific record id, suitable to be used as a primary key.
var ZeroUid Uid = 0
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 ¶
func (*Uid) MarshalJSON ¶
func (*Uid) MarshalText ¶
func (*Uid) UnmarshalBinary ¶
func (*Uid) UnmarshalJSON ¶
func (*Uid) UnmarshalText ¶
type UidGenerator ¶
type UidGenerator struct {
// contains filtered or unexported fields
}
RethinkDB generates UUIDs as primary keys. Using snowflake-generated uint64 instead.
func (*UidGenerator) Get ¶
func (ug *UidGenerator) Get() Uid
Get generates a unique weakly encryped id it so ids are random-looking.
func (*UidGenerator) GetStr ¶
func (ug *UidGenerator) GetStr() string
GetStr generates a unique id then returns it as base64-encrypted string.
type User ¶
type User struct { ObjHeader // Currently unused: Unconfirmed, Active, etc. State int // Default access to user for P2P topics (used as default modeGiven) Access DefaultAccess // Values for 'me' topic: // Server-issued sequence ID for messages in 'me' SeqId int // If messages were hard-deleted in the topic, id of the last deleted message ClearId int // 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 interface{} // Unique indexed tags (email, phone) for finding this user. Stored on the // 'users' as well as indexed in 'tagunique' Tags []string // Info on known devices, used for push notifications Devices map[string]*DeviceDef }
Stored user