-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
mobile.js
67 lines (56 loc) · 2.14 KB
/
mobile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { parseMessageText } from './index';
const CATEGORY_MESSAGE = 'MESSAGE';
const CATEGORY_MESSAGE_NOREPLY = 'MESSAGE_NOREPLY';
let alwaysNotifyMobileBoolean;
RocketChat.settings.get('Notifications_Always_Notify_Mobile', (key, value) => {
alwaysNotifyMobileBoolean = value;
});
// function getBadgeCount(userId) {
// const subscriptions = RocketChat.models.Subscriptions.findUnreadByUserId(userId).fetch();
// return subscriptions.reduce((unread, sub) => {
// return sub.unread + unread;
// }, 0);
// }
function canSendMessageToRoom(room, username) {
return !((room.muted || []).includes(username));
}
export function sendSinglePush({ room, message, userId, receiverUsername, senderUsername }) {
RocketChat.PushNotification.send({
roomId: message.rid,
payload: {
host: Meteor.absoluteUrl(),
rid: message.rid,
sender: message.u,
type: room.t,
name: room.name
},
roomName: RocketChat.settings.get('Push_show_username_room') ? `#${ RocketChat.roomTypes.getRoomName(room.t, room) }` : '',
username: RocketChat.settings.get('Push_show_username_room') ? senderUsername : '',
message: RocketChat.settings.get('Push_show_message') ? parseMessageText(message, userId) : ' ',
// badge: getBadgeCount(userIdToNotify),
usersTo: {
userId
},
category: canSendMessageToRoom(room, receiverUsername) ? CATEGORY_MESSAGE : CATEGORY_MESSAGE_NOREPLY
});
}
export function shouldNotifyMobile({ disableAllMessageNotifications, mobilePushNotifications, hasMentionToAll, isHighlighted, hasMentionToUser, statusConnection }) {
if (disableAllMessageNotifications && mobilePushNotifications == null) {
return false;
}
if (mobilePushNotifications === 'nothing') {
return false;
}
if (!alwaysNotifyMobileBoolean && statusConnection === 'online') {
return false;
}
if (!mobilePushNotifications) {
if (RocketChat.settings.get('Accounts_Default_User_Preferences_mobileNotifications') === 'all') {
return true;
}
if (RocketChat.settings.get('Accounts_Default_User_Preferences_mobileNotifications') === 'nothing') {
return false;
}
}
return hasMentionToAll || isHighlighted || mobilePushNotifications === 'all' || hasMentionToUser;
}