Chat Android SDK  4.0.2
All Classes Functions Variables
com.twilio.chat.Channel Class Reference

Container for channel object. More...

Classes

enum  ChannelStatus
 Represents the various states of the user with respect to the channel. More...
 
enum  ChannelType
 Represents the channel's visibility. More...
 
enum  NotificationLevel
 User's notification level on a channel. More...
 
enum  SynchronizationStatus
 Indicates synchronization status for channel. More...
 
enum  UpdateReason
 Indicates reason for channel update. More...
 

Public Member Functions

void dispose ()
 Dispose Channel object, freeing all allocated resources. More...
 
Getters
native String getSid ()
 Get unique identifier for this channel. More...
 
native String getFriendlyName ()
 Get friendly name of the channel. More...
 
native NotificationLevel getNotificationLevel ()
 The current user's notification level on this channel. More...
 
native ChannelType getType ()
 Get channel type. More...
 
native String getUniqueName ()
 Get unique name of the channel. More...
 
JSONObject getAttributes () throws JSONException
 Get custom attributes associated with the Channel. More...
 
native Messages getMessages ()
 Get messages object that allows access to messages in the channel. More...
 
native ChannelStatus getStatus ()
 Get the current user's participation status on this channel. More...
 
native Members getMembers ()
 Get members object that allows access to member roster in the channel. More...
 
native SynchronizationStatus getSynchronizationStatus ()
 Get the current synchronization status for channel. More...
 
native String getDateCreated ()
 Get creation date of the channel as an ISO 8601 string. More...
 
Date getDateCreatedAsDate ()
 Get creation date of the channel. More...
 
native String getCreatedBy ()
 Get creator of the channel. More...
 
native String getDateUpdated ()
 Get update date of the channel as an ISO 8601 string. More...
 
Date getDateUpdatedAsDate ()
 Get update date of the channel. More...
 
Date getLastMessageDate ()
 Get last message date in the channel. More...
 
native Long getLastMessageIndex ()
 Get last message's index in the channel. More...
 
Setters
void setFriendlyName (String friendlyName, StatusListener listener)
 Update the friendly name for this channel. More...
 
void setNotificationLevel (NotificationLevel notificationLevel, StatusListener listener)
 Set the user's notification level for the channel. More...
 
void setUniqueName (String uniqueName, StatusListener listener)
 Update the unique name for this channel. More...
 
void setAttributes (JSONObject updatedAttributes, StatusListener listener)
 Update the attribute data for this channel. More...
 
Listeners
void addListener (ChannelListener listener)
 Add a new ChannelListener for this Channel. More...
 
void removeListener (ChannelListener listener)
 Remove ChannelListener for this Channel. More...
 
void removeAllListeners ()
 Remove all ChannelListeners for this Channel. More...
 
Actions
void join (StatusListener listener)
 Join the current user to this channel. More...
 
void leave (StatusListener listener)
 Leave this channel. More...
 
void destroy (StatusListener listener)
 Destroy the current channel. More...
 
void declineInvitation (StatusListener listener)
 Decline an invite to this channel. More...
 
native void typing ()
 Indicate that Member is typing in this channel. More...
 
Counts
void getMessagesCount (CallbackListener< Long > listener)
 Get total number of messages in the channel. More...
 
void getUnconsumedMessagesCount (CallbackListener< Long > listener)
 Get number of unconsumed messages in the channel. More...
 
void getMembersCount (CallbackListener< Long > listener)
 Get total number of members in the channel roster. More...
 

Detailed Description

Container for channel object.

To obtain a Channel call Channels.createChannel(), Channels.getChannel() or get it from collections returned by Channels.getPublicChannelsList() and Channels.getUserChannelsList().

Channel is a relatively heavy-weight object. It receives state updates from the back-end in real time.

Member Function Documentation

void com.twilio.chat.Channel.addListener ( ChannelListener  listener)

Add a new ChannelListener for this Channel.

Channel listeners receive real time updates about changes in the channel state, messages and members.

This listener will be called on the originating thread if it has a Looper, otherwise on the main UI thread.

Parameters
listenerA channel listener.
See also
removeListener
removeAllListeners
void com.twilio.chat.Channel.declineInvitation ( StatusListener  listener)

Decline an invite to this channel.

If a user is invited to the channel, they can choose to either join() the channel to accept the invitation or declineInvitation() to decline.

Parameters
listenerListener that will receive callback with the result.
See also
join
leave
void com.twilio.chat.Channel.destroy ( StatusListener  listener)

Destroy the current channel.

Note: this will delete the Channel and all associated metadata from the service instance. Members in the channel and all channel messages, including posted media will be lost.

There is no undo for this operation!

Parameters
listenerListener that will receive callback with the result.
See also
dispose
void com.twilio.chat.Channel.dispose ( )

Dispose Channel object, freeing all allocated resources.

Note: this does NOT delete the Channel from the service instance.

See also
destroy
JSONObject com.twilio.chat.Channel.getAttributes ( ) throws JSONException

Get custom attributes associated with the Channel.

Attributes are stored as a JSON format object, of arbitrary internal structure. Channel attributes are limited in size to 32Kb.

Returns
JSON object with attributes or null if no attributes available.
Exceptions
JSONExceptionAttributes could not be parsed as JSON.
See also
setAttributes
native String com.twilio.chat.Channel.getCreatedBy ( )

Get creator of the channel.

Returns
Identity of the channel's creator.
native String com.twilio.chat.Channel.getDateCreated ( )

Get creation date of the channel as an ISO 8601 string.

Returns
Date when channel was created as a string in ISO 8601 format.
Date com.twilio.chat.Channel.getDateCreatedAsDate ( )

Get creation date of the channel.

Returns
Date when channel was created or null if date string could not be parsed.
native String com.twilio.chat.Channel.getDateUpdated ( )

Get update date of the channel as an ISO 8601 string.

Update date changes when channel attributes, friendly name or unique name are modified. It will not change in response to messages posted or members added or removed.

Returns
Date when channel was last updated as a string in ISO 8601 format.
Date com.twilio.chat.Channel.getDateUpdatedAsDate ( )

Get update date of the channel.

Update date changes when channel attributes, friendly name or unique name are modified. It will not change in response to messages posted or members added or removed.

Returns
Date when channel was last updated or null if date string could not be parsed.
native String com.twilio.chat.Channel.getFriendlyName ( )

Get friendly name of the channel.

Friendly name is a free-form text string, it is not unique and could be used for user-friendly channel name display in the UI.

Returns
Channel friendly name.
See also
setFriendlyName
Date com.twilio.chat.Channel.getLastMessageDate ( )

Get last message date in the channel.

See also
LastMessageChanged status update
Returns
Date of last message in the channel or null if no last message or no access to channel.
native Long com.twilio.chat.Channel.getLastMessageIndex ( )

Get last message's index in the channel.

See also
LastMessageChanged status update
Returns
Index of last message in the channel or null if no last message or no access to channel.
native Members com.twilio.chat.Channel.getMembers ( )

Get members object that allows access to member roster in the channel.

You need to synchronize the channel before you can call this method unless you just joined the channel, in which case it synchronizes automatically.

Returns
Members object for this channel.
See also
join
void com.twilio.chat.Channel.getMembersCount ( CallbackListener< Long >  listener)

Get total number of members in the channel roster.

This function performs an async call to service to obtain up-to-date member count. The retrieved value is then cached for 5 seconds so there is no reason to call this function more often than once in 5 seconds.

Parameters
listenerListener to receive results of the query.
native Messages com.twilio.chat.Channel.getMessages ( )

Get messages object that allows access to messages in the channel.

You need to synchronize the channel before you can call this method unless you just joined the channel, in which case it synchronizes automatically.

Returns
Messages object for this channel.
See also
join
void com.twilio.chat.Channel.getMessagesCount ( CallbackListener< Long >  listener)

Get total number of messages in the channel.

This function performs an async call to service to obtain up-to-date message count. The retrieved value is then cached for 5 seconds so there is no reason to call this function more often than once in 5 seconds.

Parameters
listenerListener to receive results of the query.
See also
getUnconsumedMessagesCount
native NotificationLevel com.twilio.chat.Channel.getNotificationLevel ( )

The current user's notification level on this channel.

This property reflects whether the user will receive push notifications for activity on this channel.

Returns
Current notification level.
See also
setNotificationLevel
NotificationLevel
native String com.twilio.chat.Channel.getSid ( )

Get unique identifier for this channel.

This identifier can be used to get this Channel again using Channels.getChannel().

The channel SID is persistent and globally unique.

Returns
Channel SID.
native ChannelStatus com.twilio.chat.Channel.getStatus ( )

Get the current user's participation status on this channel.

Returns
Channel participation status.
native SynchronizationStatus com.twilio.chat.Channel.getSynchronizationStatus ( )

Get the current synchronization status for channel.

Returns
current synchronization status for the channel
native ChannelType com.twilio.chat.Channel.getType ( )

Get channel type.

Returns
Type of the channel. See ChannelType for more information.
void com.twilio.chat.Channel.getUnconsumedMessagesCount ( CallbackListener< Long >  listener)

Get number of unconsumed messages in the channel.

This function performs an async call to service to obtain up-to-date message count. The retrieved value is then cached for 5 seconds so there is no reason to call this function more often than once in 5 seconds.

Parameters
listenerListener to receive results of the query.
See also
getMessagesCount
native String com.twilio.chat.Channel.getUniqueName ( )

Get unique name of the channel.

Unique name is similar to SID but can be specified by the user.

Returns
Channel unique name or null if it was not set.
See also
setUniqueName
void com.twilio.chat.Channel.join ( StatusListener  listener)

Join the current user to this channel.

Joining the channel is a prerequisite for sending and receiving messages in the channel. You can join the channel or you could be added to it by another channel member.

You could also be invited to the channel by another member. In this case you will not be added to the channel right away but instead receive a onChannelInvited() callback. You accept the invitation by calling join() or decline it by calling declineInvitation().

Parameters
listenerListener that will receive callback with the result.
See also
leave
declineInvitation
void com.twilio.chat.Channel.leave ( StatusListener  listener)

Leave this channel.

Parameters
listenerListener that will receive callback with the result.
See also
join
declineInvitation
void com.twilio.chat.Channel.removeAllListeners ( )

Remove all ChannelListeners for this Channel.

See also
addListener
removeListener
void com.twilio.chat.Channel.removeListener ( ChannelListener  listener)

Remove ChannelListener for this Channel.

Parameters
listenerListener to remove.
See also
addListener
removeAllListeners
void com.twilio.chat.Channel.setAttributes ( JSONObject  updatedAttributes,
StatusListener  listener 
)

Update the attribute data for this channel.

Attributes are stored as a JSON format object, of arbitrary internal structure. Channel attributes are limited in size to 32Kb.

Passing null attributes will reset channel attributes string to empty.

Parameters
updatedAttributesattributes to change.
listenerListener that will receive callback with the result.
See also
getAttributes
void com.twilio.chat.Channel.setFriendlyName ( String  friendlyName,
StatusListener  listener 
)

Update the friendly name for this channel.

Parameters
friendlyNameNew friendly name.
listenerListener that will receive callback with the status of update operation.
See also
getFriendlyName
void com.twilio.chat.Channel.setNotificationLevel ( NotificationLevel  notificationLevel,
StatusListener  listener 
)

Set the user's notification level for the channel.

This property determines whether the user will receive push notifications for activity on this channel.

Parameters
notificationLevelThe new notification level for the current user on this channel.
listenerListener that will receive callback with the status of update operation.
See also
getNotificationLevel
void com.twilio.chat.Channel.setUniqueName ( String  uniqueName,
StatusListener  listener 
)

Update the unique name for this channel.

Unique name is unique within Service Instance. You will receive an error if you try to set a name that is not unique.

Parameters
uniqueNameNew unique name for this channel.
listenerListener that will receive callback with the result.
See also
getUniqueName
native void com.twilio.chat.Channel.typing ( )

Indicate that Member is typing in this channel.

You should call this method to indicate that a local user is entering a message into current channel. The typing state is forwarded to users subscribed to this channel through ChannelListener.onTypingStarted() and ChannelListener.onTypingEnded() callbacks.

After approximately 5 seconds after the last typing() call the SDK will emit ChannelListener.onTypingEnded() signal.

One common way to implement this indicator is to call typing() repeatedly in response to key input events.