Skip to content

Commit

Permalink
Add badge back to push notifications (#10779)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok authored May 16, 2018
1 parent 7e25b1c commit 19e8100
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions packages/rocketchat-lib/server/functions/notifications/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,31 @@ RocketChat.settings.get('Notifications_Always_Notify_Mobile', (key, value) => {
alwaysNotifyMobileBoolean = value;
});

// function getBadgeCount(userId) {
// const subscriptions = RocketChat.models.Subscriptions.findUnreadByUserId(userId).fetch();
let SubscriptionRaw;
Meteor.startup(() => {
SubscriptionRaw = RocketChat.models.Subscriptions.model.rawCollection();
});

async function getBadgeCount(userId) {
const [ result ] = await SubscriptionRaw.aggregate([
{ $match: { 'u._id': userId } },
{
$group: {
_id: 'total',
total: { $sum: '$unread' }
}
}
]).toArray();

// return subscriptions.reduce((unread, sub) => {
// return sub.unread + unread;
// }, 0);
// }
const { total } = result;
return total;
}

function canSendMessageToRoom(room, username) {
return !((room.muted || []).includes(username));
}

export function sendSinglePush({ room, message, userId, receiverUsername, senderUsername, notificationMessage }) {
export async function sendSinglePush({ room, message, userId, receiverUsername, senderUsername, notificationMessage }) {
RocketChat.PushNotification.send({
roomId: message.rid,
payload: {
Expand All @@ -31,7 +43,7 @@ export function sendSinglePush({ room, message, userId, receiverUsername, sender
roomName: RocketChat.settings.get('Push_show_username_room') ? `${ room.t === 'd' ? '' : '#' }${ RocketChat.roomTypes.getRoomName(room.t, room) }` : '',
username: RocketChat.settings.get('Push_show_username_room') ? senderUsername : '',
message: RocketChat.settings.get('Push_show_message') ? notificationMessage : ' ',
// badge: getBadgeCount(userIdToNotify),
badge: await getBadgeCount(userId),
usersTo: {
userId
},
Expand Down

0 comments on commit 19e8100

Please sign in to comment.