Topic

Tinode. Topic

new Topic(name, callbacksopt)

Topic is a class representing a logical communication channel.
Source:
Parameters:
Name Type Attributes Description
name string Name of the topic to create.
callbacks Object <optional>
Object with various event callbacks.
Name Type Description
onData Tinode.Topic.onData Callback which receives a {data} message.
onMeta callback Callback which receives a {meta} message.
onPres callback Callback which receives a {pres} message.
onInfo callback Callback which receives an {info} message.
onMetaDesc callback Callback which receives changes to topic desctioption desc.
onMetaSub callback Called for a single subscription record change.
onSubsUpdated callback Called after a batch of subscription changes have been recieved and cached.
onDeleteTopic callback Called after the topic is deleted.
callbacls.onAllMessagesReceived callback Called when all requested {data} messages have been recived.

Methods

archive(arch) → {Promise}

Archive or un-archive the topic. Wrapper for Tinode#setMeta.
Source:
Parameters:
Name Type Description
arch Boolean true to archive the topic, false otherwise.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

cancelSend(seqId) → {boolean}

Attempt to stop message from being sent.
Source:
Parameters:
Name Type Description
seqId integer id of the message to stop sending and remove from cache.
Returns:
Type:
boolean
true if message was cancelled, false otherwise.

createMessage(data, noEchoopt) → {Object}

Create a draft of a message without sending it to the server.
Source:
Parameters:
Name Type Attributes Description
data string | Object Content to wrap in a draft.
noEcho Boolean <optional>
If true server will not echo message back to originating session. Otherwise the server will send a copy of the message to sender.
Returns:
Type:
Object
message draft.

delMessages(ranges, hardopt) → {Promise}

Delete messages. Hard-deleting messages requires Owner permission. Wrapper for Tinode#delMessages.
Source:
Parameters:
Name Type Attributes Description
ranges Array.<Tinode.DelRange> Ranges of message IDs to delete.
hard Boolean <optional>
Hard or soft delete
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

delMessagesAll(hardDel) → {Promise}

Delete all messages. Hard-deleting messages requires Owner permission.
Source:
Parameters:
Name Type Description
hardDel boolean true if messages should be hard-deleted.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

delMessagesList(list, hardDelopt) → {Promise}

Delete multiple messages defined by their IDs. Hard-deleting messages requires Owner permission.
Source:
Parameters:
Name Type Attributes Description
list Array.<Tinode.DelRange> list of seq IDs to delete
hardDel Boolean <optional>
true if messages should be hard-deleted.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

delSubscription(user) → {Promise}

Delete subscription. Requires Share permission. Wrapper for Tinode#delSubscription.
Source:
Parameters:
Name Type Description
user String ID of the user to remove subscription for.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

delTopic(hard) → {Promise}

Delete topic. Requires Owner permission. Wrapper for Tinode#delTopic.
Source:
Parameters:
Name Type Description
hard Boolean had-delete topic.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to the request.

flushMessage(seqId) → {Message}

Remove one message from local cache.
Source:
Parameters:
Name Type Description
seqId integer id of the message to remove from cache.
Returns:
Type:
Message
removed message or undefined if such message was not found.

flushMessageRange(fromId, untilId) → {Array.<Message>}

Remove a range of messages from the local cache.
Source:
Parameters:
Name Type Description
fromId integer seq ID of the first message to remove (inclusive).
untilId integer seqID of the last message to remove (exclusive).
Returns:
Type:
Array.<Message>
array of removed messages (could be empty).

getAccessMode() → {Tinode.AccessMode}

Get user's cumulative access mode of the topic.
Source:
Returns:
Type:
Tinode.AccessMode
- user's access mode

getDefaultAccess() → {Tinode.DefAcs}

Get topic's default access mode.
Source:
Returns:
Type:
Tinode.DefAcs
- access mode, such as {auth: `RWP`, anon: `N`}.

getMessagesPage(limit, forward)

Request more messages from the server
Source:
Parameters:
Name Type Description
limit integer number of messages to get.
forward boolean if true, request newer messages.

getMeta(request) → {Promise}

Request topic metadata from the server.
Source:
Parameters:
Name Type Description
request Tinode.GetQuery parameters
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

getType() → {String}

Get type of the topic: me, p2p, grp, fnd...
Source:
Returns:
Type:
String
One of 'me', 'p2p', 'grp', 'fnd', 'sys' or undefined.

invite(uid, modeopt) → {Promise}

Create new topic subscription. Wrapper for Tinode#setMeta.
Source:
Parameters:
Name Type Attributes Description
uid String ID of the user to invite
mode String <optional>
Access mode. null means to use default.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

isArchived() → {boolean}

Check if topic is archived, i.e. private.arch == true.
Source:
Returns:
Type:
boolean
- true if topic is archived, false otherwise.

isChannel() → {boolean}

Check if topic is a channel.
Source:
Returns:
Type:
boolean
- true if topic is a channel, false otherwise.

isGroup() → {boolean}

Check if topic is a group topic.
Source:
Returns:
Type:
boolean
- true if topic is a group, false otherwise.

isNewMessage(seqId)

Check if the given seq Id is id of the most recent message.
Source:
Parameters:
Name Type Description
seqId integer id of the message to check

isP2P() → {boolean}

Check if topic is a p2p topic.
Source:
Returns:
Type:
boolean
- true if topic is a p2p topic, false otherwise.

isSubscribed() → {boolean}

Check if the topic is subscribed.
Source:
Returns:
Type:
boolean
True is topic is attached/subscribed, false otherwise.

leave(unsubopt) → {Promise}

Leave the topic, optionally unsibscribe. Leaving the topic means the topic will stop receiving updates from the server. Unsubscribing will terminate user's relationship with the topic. Wrapper for Tinode#leave.
Source:
Parameters:
Name Type Attributes Description
unsub Boolean <optional>
If true, unsubscribe, otherwise just leave.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to the request.

messages(callback, sinceId, beforeId, context)

Iterate over cached messages. If callback is undefined, use this.onData.
Source:
Parameters:
Name Type Description
callback function Callback which will receive messages one by one. See Tinode.CBuffer#forEach
sinceId integer Optional seqId to start iterating from (inclusive).
beforeId integer Optional seqId to stop iterating before (exclusive).
context Object Value of `this` inside the `callback`.

msgHasMoreMessages(newer)

Check if cached message IDs indicate that the server may have more messages.
Source:
Parameters:
Name Type Description
newer boolean check for newer messages

msgReadCount(seq) → {Number}

Get the number of topic subscribers who marked this message (and all older messages) as read. The current user is excluded from the count.
Source:
Parameters:
Name Type Description
seq Number Message id to check.
Returns:
Type:
Number
Number of subscribers who claim to have received the message.

msgReceiptCount(what, seq)

Get the number of topic subscribers who marked this message as either recv or read Current user is excluded from the count.
Source:
Parameters:
Name Type Description
what String what notification to send: recv, read.
seq Number ID or the message read or received.

msgRecvCount(seq) → {number}

Get the number of topic subscribers who marked this message (and all older messages) as received. The current user is excluded from the count.
Source:
Parameters:
Name Type Description
seq number Message id to check.
Returns:
Type:
number
Number of subscribers who claim to have received the message.

msgStatus(msg)

Get status (queued, sent, received etc) of a given message in the context of this topic.
Source:
Parameters:
Name Type Description
msg Message message to check for status.
Returns:
message status constant.

note(what, seq)

Send a read/recv notification
Source:
Parameters:
Name Type Description
what String what notification to send: recv, read.
seq Number ID or the message read or received.

noteKeyPress()

Send a key-press notification. Wrapper for Tinode#noteKeyPress.
Source:

noteRead(seq)

Send a 'read' receipt. Wrapper for Tinode#noteRead.
Source:
Parameters:
Name Type Description
seq Number ID of the message to aknowledge or 0/undefined to acknowledge the latest messages.

noteRecv(seq)

Send a 'recv' receipt. Wrapper for Tinode#noteRecv.
Source:
Parameters:
Name Type Description
seq Number ID of the message to aknowledge.

p2pPeerDesc() → {Object}

Get description of the p2p peer from subscription cache.
Source:
Returns:
Type:
Object
peer's description or undefined.

publish(data, noEchoopt) → {Promise}

Immediately publish data to topic. Wrapper for Tinode#publish.
Source:
Parameters:
Name Type Attributes Description
data string | Object Data to publish, either plain string or a Drafty object.
noEcho Boolean <optional>
If true server will not echo message back to originating
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to the request.

publishDraft(pub, prom) → {Promise}

Add message to local message cache, send to the server when the promise is resolved. If promise is null or undefined, the message will be sent immediately. The message is sent when the The message should be created by Tinode.Topic#createMessage. This is probably not the final API.
Source:
Parameters:
Name Type Description
pub Object Message to use as a draft.
prom Promise Message will be sent when this promise is resolved, discarded if rejected.
Returns:
Type:
Promise
derived promise.

publishMessage(pub) → {Promise}

Publish message created by Tinode.Topic#createMessage.
Source:
Parameters:
Name Type Description
pub Object {data} object to publish. Must be created by Tinode.Topic#createMessage
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to the request.

queuedMessages(callback, context)

Iterate over cached unsent messages. Wraps Tinode.Topic#messages.
Source:
Parameters:
Name Type Description
callback function Callback which will receive messages one by one. See Tinode.CBuffer#forEach
context Object Value of `this` inside the `callback`.

setMeta(params) → {Promise}

Update topic metadata.
Source:
Parameters:
Name Type Description
params Tinode.SetParams parameters to update.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

startMetaQuery() → {Tinode.MetaGetBuilder}

Initialize new meta Tinode.GetQuery builder. The query is attched to the current topic. It will not work correctly if used with a different topic.
Source:
Returns:
Type:
Tinode.MetaGetBuilder
query attached to the current topic.

subscribe(getParamsopt, setParamsopt) → {Promise}

Request topic to subscribe. Wrapper for Tinode#subscribe.
Source:
Parameters:
Name Type Attributes Description
getParams Tinode.GetQuery <optional>
get query parameters.
setParams Tinode.SetParams <optional>
set parameters.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to the request.

subscriber(uid)

Get cached subscription for the given user ID.
Source:
Parameters:
Name Type Description
uid String id of the user to query for
Returns:
user description or undefined.

subscribers(callback, contextopt)

Iterate over cached subscribers. If callback is undefined, use this.onMetaSub.
Source:
Parameters:
Name Type Attributes Description
callback function Callback which will receive subscribers one by one.
context Object <optional>
Value of `this` inside the `callback`.

swapMessageId(pub, newSeqId)

Update message's seqId.
Source:
Parameters:
Name Type Description
pub Object message object.
newSeqId integer new seq id for pub.

tags()

Get a copy of cached tags.
Source:
Returns:
a copy of tags

updateMode(uid, update) → {Promise}

Update access mode of the current user or of another topic subsriber.
Source:
Parameters:
Name Type Description
uid string UID of the user to update or null to update current user.
update string the update value, full or delta.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

userDesc(uid) → {Object}

Get user description from global cache. The user does not need to be a subscriber of this topic.
Source:
Parameters:
Name Type Description
uid String ID of the user to fetch.
Returns:
Type:
Object
user description or undefined.

Type Definitions

onData(data)

Source:
Parameters:
Name Type Description
data Data Data packet