Streams.Stream Class
Class representing 'Stream' rows in the 'Streams' database
stored primarily on publisherId's fm server
Constructor
Streams.Stream
-
fields
Parameters:
-
fields
ObjectThe fields values to initialize table row as an associative array of
{column: value}
pairs
Item Index
Methods
- addPermission
- calculateAccess
- clear
- clearAllAttributes
- clearAttribute
- get
- getAllAttributes
- getAllPermissions
- getAttribute
- getConfigField static
- getSubscriptionTemplate
- hasPermission
- iconUrl
- inheritAccess
- join
- notify
- notifyObservers
- notifyParticipants
- post Currently this is not nearly as robust as the PHP method, and doesn't perform any access checks, so it is only meant to be called internally.
- removePermission
- restrictedFromClient static
- set
- setAttribute
- setUp
- subscribe
- testAdminLevel
- testLevel
- testPermission
- testReadLevel
- testWriteLevel
- updateParticipantCounts
Methods
calculateAccess
-
$asUserId=''
-
callback=null
Set access data for the stream. Acces data is calculated:
- from read/write/admin level fields of the stream
- from labels. Streams_Access record may contain <publisherId>, <streamName> (allowed exact match or generic name "<streamType>/") and <ofContactLabel>. If <publisherId> is recorded in Users_Contact to have either current user or <ofContactLabel> as contact, access claculation is considering such record.
- from user. Stream_Access record may contain <publisherId>, <streamName> (allowed exact match or generic name "<streamType>/") and <ofUserId>. Such record is considered in access calculation.
clear
-
[key=null]
Clears the value of an extra field
Parameters:
-
[key=null]
String optionalA key to clear. If null, clears all keys.
clearAllAttributes
()
clearAttribute
-
attributeName
Parameters:
-
attributeName
StringThe name of the attribute to remove
get
-
key
-
[def=null]
Gets the value of an extra field
Parameters:
-
key
String -
[def=null]
Mixed optionalThe value to return if the field is not found. Defaults to undefined.
Returns:
The field if it is found, otherwise def or undefined.
getAttribute
-
attributeName
-
def
Parameters:
-
attributeName
StringThe name of the attribute to get
-
def
MixedThe value to return if the attribute is missing
Returns:
The value of the attribute, or the default value, or null
getConfigField
-
type
-
field
-
def
-
[merge=true]
Gets a value from the config corresponding to this stream type and a field name, using defaults from "Streams"/"types"/"*" and merging the value under "Streams"/"types"/$stream->type, if any.
Parameters:
Returns:
mixed
getSubscriptionTemplate
-
className
-
ofUserId
-
[templateType=null]
Parameters:
Returns:
Returns the template subscription, or an array if $templateType is true
iconUrl
-
[size=40]
Calculate the url of a stream's icon
Parameters:
-
[size=40]
Number optionalthe size of the icon to render. Defaults to 40.
Returns:
the url
inheritAccess
-
callback=null
Inherits access from any streams specified in the inheritAccess field.
Parameters:
-
callback=null
FunctionCallback receives "error" and boolean as arguments - whether the access potentially changed.
join
-
options=
-
callback
If the user is not participating in the stream yet, inserts a participant record and posts a "Streams/join" type message to the stream. Otherwise update timestamp
Parameters:
-
options=
Object{object} An associative array of options. 'userId' is mandatory. The keys can be:
"subscribed" => boolean
"posted" => boolean
"reputation" => integer
"reason" => string
"enthusiasm" => decimal
"userId" => The user who is joining the stream. -
callback
Functionreceives error if any and participant object as arguments
notify
-
participant
-
event
-
userId
-
message
-
[callback]
Notify participants of the stream depending on user status. Set the "Streams/notifications/onlyIfAllClientsOffline" config field to false to send offline notifications whenever all clients related to device sessions are offline, even if other clients are online.
Parameters:
-
participant
Streams_ParticipantThe stream participant to notify
-
event
StringThe type of Streams event, such as "post" or "remove"
-
userId
StringThe user who initiated the message
-
message
Streams_MessageMessage on 'post' event or stream on other events
-
[callback]
Function optionalThis would be called after all the notifying was done
notifyObservers
-
event
-
userId
-
message
Sends a message to all observers of a stream, i.e. socket clients besides the ones which are associated to participants. This can include socket clients that are not associated to any user.
notifyParticipants
-
event
-
userId
-
message
-
dontNotifyObservers
Sends a message to all participants of a stream. Also sends it to observers unless dontNotifyObservers is true.
post
Currently this is not nearly as robust as the PHP method,
and doesn't perform any access checks, so it is only
meant to be called internally.
-
asUserId
-
fields
-
callback=null
Posts a message to the stream.
restrictedFromClient
-
streamType
-
fieldName
-
[whenCreating=false]
Find out whether a certain field is restricted from being edited by clients via the regular Streams REST API.
Returns:
set
-
key
-
value
Sets some extra data
Parameters:
-
key
String -
value
MixedThe value to set for that extra data
setAttribute
-
attributeName
-
value
Parameters:
-
attributeName
StringThe name of the attribute to set, or an array of {attributeName: attributeValue} pairs
-
value
MixedThe value to set the attribute to
setUp
()
The setUp() method is called the first time an object of this class is constructed.
subscribe
-
[options={}]
Subscribe to the stream's messages
If options are not given check the subscription templates:
- exact stream name and exact user id
- generic stream name and exact user id
- exact stream name and generic user
- generic stream name and generic user
If options supplied - skip templates and use options
Using subscribe if subscription is already active will modify existing subscription - change type(s) or modify notifications
Parameters:
-
[options={}]
Object optional-
[filter]
Array optionaloptional array with two keys
-
[types]
Array optionalarray of message types, if this is empty then subscribes to all types -
[notifications=0]
Integer optionallimit number of notifications, 0 means no limit
-
-
[untilTime=null]
Datetime optionaltime limit, if any for subscription
-
[readyTime]
Datetime optionaltime from which user is ready to receive notifications again
-
[userId]
String optionalthe user subscribing to the stream. Defaults to the logged in user.
-
[rule=array()]
Array optionaloptionally override the rule for new subscriptions
-
[deliver=array('to']
Array optionalunder "to" key, named the field under Streams/rules/deliver config, which will contain the names of destinations, which can include "email", "mobile", "email+pending", "mobile+pending" -
[readyTime]
Datetime optionaltime from which user is ready to receive notifications again -
[filter]
Array optionaloptionally set a filter for the rules to add
-
-
[skipRules]
Boolean optionalif true, do not attempt to create rules for new subscriptions
-
Returns:
testAdminLevel
-
level
-
callback=null
Verifies wheather Stream can be administered. Can be called syncronously and in such case skips verification of inherited access or asyncronously to make ful check
Parameters:
Returns:
testLevel
-
type
-
values
-
level
-
callback=null
Verifies wheather Stream can be handled. Can be called syncronously and in such case skips verification of inherited access or asyncronously to make ful check
testPermission
-
permission
-
callback=null
Verifies whether the user has at least the given permission
Parameters:
Returns:
testReadLevel
-
level
-
callback=null
Verifies wheather Stream can be read. Can be called syncronously and in such case skips verification of inherited access or asyncronously to make ful check
Parameters:
Returns:
testWriteLevel
-
level
-
callback=null
Verifies wheather Stream can be written. Can be called syncronously and in such case skips verification of inherited access or asyncronously to make ful check