@@ -223,8 +223,8 @@ module.exports = function(AV) {
223223 /**
224224 * Count unread statuses in someone's inbox.
225225 * @since 0.3.0
226- * @param {Object } source The status source .
227- * @param {String } inboxType The inbox type,'default' by default.
226+ * @param {Object } owner The status owner .
227+ * @param {String } inboxType The inbox type, 'default' by default.
228228 * @param {AuthOptions } options
229229 * @return {Promise } A promise that is fulfilled when the count
230230 * completes.
@@ -234,17 +234,43 @@ module.exports = function(AV) {
234234 * console.log(response.total); //total statuses number.
235235 * });
236236 */
237- AV . Status . countUnreadStatuses = function ( owner ) {
238- var options = ( ! _ . isString ( arguments [ 1 ] ) ? arguments [ 1 ] : arguments [ 2 ] ) || { } ;
239- var inboxType = ! _ . isString ( arguments [ 1 ] ) ? 'default' : arguments [ 1 ] ;
240- if ( ! options . sessionToken && owner == null && ! AV . User . current ( ) ) {
237+ AV . Status . countUnreadStatuses = function ( owner , inboxType = 'default' , options = { } ) {
238+ if ( ! _ . isString ( inboxType ) ) options = inboxType ;
239+ if ( ! options . sessionToken && owner == null && ! AV . User . current ( ) ) {
240+ throw new Error ( 'Please signin an user or pass the owner objectId.' ) ;
241+ }
242+ return getUser ( options ) . then ( owner => {
243+ var params = { } ;
244+ params . inboxType = AV . _encode ( inboxType ) ;
245+ params . owner = AV . _encode ( owner ) ;
246+ return AVRequest ( 'subscribe/statuses/count' , null , null , 'GET' , params , options ) ;
247+ } ) ;
248+ } ;
249+
250+ /**
251+ * reset unread statuses count in someone's inbox.
252+ * @since 2.1.0
253+ * @param {Object } owner The status owner.
254+ * @param {String } inboxType The inbox type, 'default' by default.
255+ * @param {AuthOptions } options
256+ * @return {Promise } A promise that is fulfilled when the reset
257+ * completes.
258+ * @example
259+ * AV.Status.resetUnreadCount(AV.User.current()).then(function(response){
260+ * console.log(response.unread); //unread statuses number.
261+ * console.log(response.total); //total statuses number.
262+ * });
263+ */
264+ AV . Status . resetUnreadCount = function ( owner , inboxType = 'default' , options = { } ) {
265+ if ( ! _ . isString ( inboxType ) ) options = inboxType ;
266+ if ( ! options . sessionToken && owner == null && ! AV . User . current ( ) ) {
241267 throw new Error ( 'Please signin an user or pass the owner objectId.' ) ;
242268 }
243269 return getUser ( options ) . then ( owner => {
244270 var params = { } ;
245271 params . inboxType = AV . _encode ( inboxType ) ;
246272 params . owner = AV . _encode ( owner ) ;
247- return AVRequest ( 'subscribe/statuses/count ' , null , null , 'GET ' , params , options . sessionToken ) ;
273+ return AVRequest ( 'subscribe/statuses/resetUnreadCount ' , null , null , 'POST ' , params , options ) ;
248274 } ) ;
249275 } ;
250276
0 commit comments