Skip to content

Commit

Permalink
sendTypingIndicator: make callback optional (Schmavery#457)
Browse files Browse the repository at this point in the history
Added warning when there is a `callback` but it is not a function.
  • Loading branch information
ravkr authored and Schmavery committed Apr 14, 2017
1 parent 5f39cfb commit ac8de6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ login({email: "EMAIL", password: "PASSWORD"}, (err, api) => {
<a name="sendTypingIndicator"></a>
### api.sendTypingIndicator(threadID[, callback])
Sends a "USERNAME is typing" indicator to other members of the thread indicated by threadID. This indication will disappear after 30 second or when the `end` function is called. The `end` function is returned by `api.sendTypingIndicator`.
Sends a "USERNAME is typing" indicator to other members of the thread indicated by `threadID`. This indication will disappear after 30 second or when the `end` function is called. The `end` function is returned by `api.sendTypingIndicator`.
__Arguments__
Expand Down
19 changes: 14 additions & 5 deletions src/sendTypingIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function(defaultFuncs, api, ctx) {
thread: threadID
};

// Check if thread is single person chat or group chat
// Check if thread is a single person chat or a group chat
// More info on this is in api.sendMessage
api.getUserInfo(threadID, function(err, res) {
if (err) {
Expand Down Expand Up @@ -42,15 +42,24 @@ module.exports = function(defaultFuncs, api, ctx) {
}

return function sendTypingIndicator(threadID, callback) {
if(!callback) {
throw {error: "sendTypingIndicator: need callback"};
if (utils.getType(callback) !== 'Function' && utils.getType(callback) !== 'AsyncFunction') {
if (callback) {
log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
}
callback = () => {};
}

makeTypingIndicator(true, threadID, callback);

// TODO: document that we return the stop/cancel functions now
return function end(cb) {
makeTypingIndicator(false, threadID, cb || function() {***REMOVED***;
if (utils.getType(cb) !== 'Function' && utils.getType(cb) !== 'AsyncFunction') {
if (cb) {
log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
}
cb = () => {};
}

makeTypingIndicator(false, threadID, cb);
};
};
};

0 comments on commit ac8de6c

Please # to comment.