4.6 KiB
streams
let streams = zulip.streams()
Functions
streams.getAll
Gets all of the streams that a user can access.
Parameters
includePublic
(optional, defaulttrue
): Whether all public streams should be included.includeSubscribed
(optional, defaulttrue
): Whether all subscribed-to streams should be includedincludeDefault
(optional, defaultfalse
): Whether all default streams should be included.includeActive
(optional, defaultfalse
): Whether all active streams should be included. This option will cause aZulipError
if the user not an admin.callback
: A callback, which will be passed the streams, or an error.
streams.getID
Gets the ID of a stream.
Parameters
name
: The name of the stream.callback
: A callback, which will be passed the ID, or an error.
streams.getSubscribed
Gets the user's subscribed streams.
Parameters
callback
: A callback, which will be passed the streams, or an error.
streams.subscribe
Subscribes a user to streams, or creates them if they do not exist yet.
Parameters
-
streams
: The streams to subscribe a user to.- example:
[["name": "test here"]]
- example:
["name": "test here"], ["name": "announce"]]
- example:
-
inviteOnly
(optional, defaultfalse
): Whether the streams are invite only or not. -
announce
(optional, defaultfalse
): Whether an announcement should be made that a new stream is created, if it is. -
principals
: The users to subscribe to the streams. Ifprincipals
is empty, the current user will be subscribed. -
authorizationErrorsFatal
(optional, defaultfalse
): Whether authorization errors should be reported in the response. -
callback
: A callback, which will be passed- a dictionary where the key is user's email, and the value is a list of streams they were subscribed to;
- a dictionary where the key is a user's email, and the value is a list of streams they were already subscribed to; and
- a list of names of streams that could not be subscribed to because the user was unauthorized;
or an error if there is one.
streams.unsubscribe
Unsubscribes a user from streams.
Parameters
-
streamNames
: The names of the streams to unsubscribe a user from.- example:
["test here"]
- example:
["test here", "announce"]
- example:
-
principals
: The users to unsubscribe from the streams. Ifprincipals
is empty, the current user will be subscribed. Unsubscribing other users will cause aZulipError
if the current user is not an admin. -
callback
: A callback, which will be passed- a list of names of the streams that were unsubscribed from and
- a list of names of the streams that could not be unsubscribed from because the user was already subscribed,
or an error if there is one.
Examples
streams.getAll
streams.getAll(
includePublic: true,
includeSubscribed: true,
includeDefault: false,
includeActive: false,
callback: { (streams, error) in
// Prints a list of streams with various properties.
print(streams)
}
)
streams.getID
streams.getID(
name: "test here",
callback: { (id, error) in
// Prints a number, like 13.
print(streams)
}
)
streams.getSubscribed
streams.getSubscribed(
callback: { (streams, error) in
// Prints a list of streams with various properties.
print(streams)
}
)
streams.subscribe
streams.subscribe(
streams: [["name": "test here"]],
principals: ["user1@example.com", "user2@example.com"]
callback: { (subscribed, alreadySubscribed, unauthorized, error) in
// Prints something like
//
// [
// "user1@example.com": "test here"
// ]
print(subscribed)
// Prints something like
//
// [
// "user2@example.com": "test here"
// ]
print(alreadySubscribed)
// Prints something like
//
// []
//
// if no streams are unauthorized.
print(unauthorized)
}
)
streams.unsubscribe
streams.unsubscribe(
streamsNames: ["test here", "announce"],
principals: ["user1@example.com", "user2@example.com"]
callback: { (unsubscribed, notSubscribed, error) in
// Prints something like
//
// ["test here"]
print(unsubscribed)
// Prints something like
//
// ["announce"]
print(notSubscribed)
}
)