@@ -756,16 +756,22 @@ class Popper extends PusherPopper {
756756 */
757757 async run ( ) {
758758 this . audience . log . i ( 'popping %d uids from %s' , this . uids . length , this . audience . message . _id ) ;
759+ return this . clear ( this . uids ) ;
759760 }
760761
761762 /**
762- * Remove all message pushes
763- *
763+ * Remove all message pushes or those for specified uids
764+ *
765+ * @param {string[] } uids optional array of uids to remove pushes for
764766 * @returns {number } number of records removed
765767 */
766- async clear ( ) {
768+ async clear ( uids ) {
767769 let deleted = await Promise . all ( this . audience . platformsWithVirtuals ( ) . map ( async p => {
768- let res = await common . db . collection ( 'push' ) . deleteMany ( { m : this . audience . message . _id , p} ) ;
770+ const query = { m : this . audience . message . _id , p} ;
771+ if ( uids ) {
772+ query . u = { $in : uids } ;
773+ }
774+ let res = await common . db . collection ( 'push' ) . deleteMany ( query ) ;
769775 return { p, deleted : res . deletedCount } ;
770776 } ) ) ;
771777 let update ;
@@ -775,7 +781,9 @@ class Popper extends PusherPopper {
775781 }
776782 update . $inc [ 'result.processed' ] = ( update . $inc [ 'result.processed' ] || 0 ) + obj . deleted ;
777783 update . $inc [ 'result.errored' ] = ( update . $inc [ 'result.errored' ] || 0 ) + obj . deleted ;
778- update . $inc [ `result.errors.${ obj . p } .cancelled` ] = ( update . $inc [ `result.errors.${ obj . p } .cancelled` ] || 0 ) + obj . deleted ;
784+ update . $inc [ `result.errors.cancelled` ] = ( update . $inc [ `result.errors.cancelled` ] || 0 ) + obj . deleted ;
785+ update . $inc [ `result.subs.${ obj . p } .errors.cancelled` ] = ( update . $inc [ `result.subs.${ obj . p } .errors.cancelled` ] || 0 ) + obj . deleted ;
786+ update . $inc [ `result.subs.${ obj . p } .errored` ] = ( update . $inc [ `result.subs.${ obj . p } .errored` ] || 0 ) + obj . deleted ;
779787 }
780788 if ( update ) {
781789 await this . audience . message . update ( update , ( ) => {
0 commit comments