Remove dependency of RocketChat namespace and push-notifications (#13137)
* Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Convert rocketchat:ui to main module structure * import variables that was broken due to conversion of rocketchat:ui * Remove globals variables from eslintrc and add some to the eslintrc of livechat app * Remove dependency between RocketChat namespace and migrations * Revert commented test file * Remove dependency of RocketChat namespace and logger * Move CustomSounds Model to rocketchat:models * Remove dependency of RocketChat namespace and custom-sounds * MOve function to utils * Remove dependency of RocketChat namespace and push-notificationspull/12540/head^2
parent
c3c2f5a324
commit
06a523f865
@ -1,28 +1,3 @@ |
|||||||
RocketChat.getUserNotificationPreference = function _getUserNotificationPreference(user, pref) { |
import { getUserNotificationPreference } from 'meteor/rocketchat:utils'; |
||||||
if (typeof user === 'string') { |
|
||||||
user = RocketChat.models.Users.findOneById(user); |
|
||||||
} |
|
||||||
|
|
||||||
let preferenceKey; |
RocketChat.getUserNotificationPreference = getUserNotificationPreference; |
||||||
switch (pref) { |
|
||||||
case 'desktop': preferenceKey = 'desktopNotifications'; break; |
|
||||||
case 'mobile': preferenceKey = 'mobileNotifications'; break; |
|
||||||
case 'email': preferenceKey = 'emailNotificationMode'; break; |
|
||||||
} |
|
||||||
|
|
||||||
if (user && user.settings && user.settings.preferences && user.settings.preferences[preferenceKey] !== 'default') { |
|
||||||
return { |
|
||||||
value: user.settings.preferences[preferenceKey], |
|
||||||
origin: 'user', |
|
||||||
}; |
|
||||||
} |
|
||||||
const serverValue = RocketChat.settings.get(`Accounts_Default_User_Preferences_${ preferenceKey }`); |
|
||||||
if (serverValue) { |
|
||||||
return { |
|
||||||
value: serverValue, |
|
||||||
origin: 'server', |
|
||||||
}; |
|
||||||
} |
|
||||||
|
|
||||||
return null; |
|
||||||
}; |
|
||||||
|
@ -1,2 +1 @@ |
|||||||
import './models/Subscriptions'; |
|
||||||
import './methods/saveNotificationSettings'; |
import './methods/saveNotificationSettings'; |
||||||
|
@ -1,278 +0,0 @@ |
|||||||
import { RocketChat } from 'meteor/rocketchat:lib'; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.updateAudioNotificationsById = function(_id, audioNotifications) { |
|
||||||
const query = { |
|
||||||
_id, |
|
||||||
}; |
|
||||||
|
|
||||||
const update = {}; |
|
||||||
|
|
||||||
if (audioNotifications === 'default') { |
|
||||||
update.$unset = { audioNotifications: 1 }; |
|
||||||
} else { |
|
||||||
update.$set = { audioNotifications }; |
|
||||||
} |
|
||||||
|
|
||||||
return this.update(query, update); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.updateAudioNotificationValueById = function(_id, audioNotificationValue) { |
|
||||||
const query = { |
|
||||||
_id, |
|
||||||
}; |
|
||||||
|
|
||||||
const update = { |
|
||||||
$set: { |
|
||||||
audioNotificationValue, |
|
||||||
}, |
|
||||||
}; |
|
||||||
|
|
||||||
return this.update(query, update); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.updateDesktopNotificationsById = function(_id, desktopNotifications) { |
|
||||||
const query = { |
|
||||||
_id, |
|
||||||
}; |
|
||||||
|
|
||||||
const update = {}; |
|
||||||
|
|
||||||
if (desktopNotifications === null) { |
|
||||||
update.$unset = { |
|
||||||
desktopNotifications: 1, |
|
||||||
desktopPrefOrigin: 1, |
|
||||||
}; |
|
||||||
} else { |
|
||||||
update.$set = { |
|
||||||
desktopNotifications: desktopNotifications.value, |
|
||||||
desktopPrefOrigin: desktopNotifications.origin, |
|
||||||
}; |
|
||||||
} |
|
||||||
|
|
||||||
return this.update(query, update); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.updateDesktopNotificationDurationById = function(_id, value) { |
|
||||||
const query = { |
|
||||||
_id, |
|
||||||
}; |
|
||||||
|
|
||||||
const update = { |
|
||||||
$set: { |
|
||||||
desktopNotificationDuration: parseInt(value), |
|
||||||
}, |
|
||||||
}; |
|
||||||
|
|
||||||
return this.update(query, update); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.updateMobilePushNotificationsById = function(_id, mobilePushNotifications) { |
|
||||||
const query = { |
|
||||||
_id, |
|
||||||
}; |
|
||||||
|
|
||||||
const update = {}; |
|
||||||
|
|
||||||
if (mobilePushNotifications === null) { |
|
||||||
update.$unset = { |
|
||||||
mobilePushNotifications: 1, |
|
||||||
mobilePrefOrigin: 1, |
|
||||||
}; |
|
||||||
} else { |
|
||||||
update.$set = { |
|
||||||
mobilePushNotifications: mobilePushNotifications.value, |
|
||||||
mobilePrefOrigin: mobilePushNotifications.origin, |
|
||||||
}; |
|
||||||
} |
|
||||||
|
|
||||||
return this.update(query, update); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.updateEmailNotificationsById = function(_id, emailNotifications) { |
|
||||||
const query = { |
|
||||||
_id, |
|
||||||
}; |
|
||||||
|
|
||||||
const update = {}; |
|
||||||
|
|
||||||
if (emailNotifications === null) { |
|
||||||
update.$unset = { |
|
||||||
emailNotifications: 1, |
|
||||||
emailPrefOrigin: 1, |
|
||||||
}; |
|
||||||
} else { |
|
||||||
update.$set = { |
|
||||||
emailNotifications: emailNotifications.value, |
|
||||||
emailPrefOrigin: emailNotifications.origin, |
|
||||||
}; |
|
||||||
} |
|
||||||
|
|
||||||
return this.update(query, update); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.updateUnreadAlertById = function(_id, unreadAlert) { |
|
||||||
const query = { |
|
||||||
_id, |
|
||||||
}; |
|
||||||
|
|
||||||
const update = { |
|
||||||
$set: { |
|
||||||
unreadAlert, |
|
||||||
}, |
|
||||||
}; |
|
||||||
|
|
||||||
return this.update(query, update); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.updateDisableNotificationsById = function(_id, disableNotifications) { |
|
||||||
const query = { |
|
||||||
_id, |
|
||||||
}; |
|
||||||
|
|
||||||
const update = { |
|
||||||
$set: { |
|
||||||
disableNotifications, |
|
||||||
}, |
|
||||||
}; |
|
||||||
|
|
||||||
return this.update(query, update); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.updateHideUnreadStatusById = function(_id, hideUnreadStatus) { |
|
||||||
const query = { |
|
||||||
_id, |
|
||||||
}; |
|
||||||
|
|
||||||
const update = { |
|
||||||
$set: { |
|
||||||
hideUnreadStatus, |
|
||||||
}, |
|
||||||
}; |
|
||||||
|
|
||||||
return this.update(query, update); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.updateMuteGroupMentions = function(_id, muteGroupMentions) { |
|
||||||
const query = { |
|
||||||
_id, |
|
||||||
}; |
|
||||||
|
|
||||||
const update = { |
|
||||||
$set: { |
|
||||||
muteGroupMentions, |
|
||||||
}, |
|
||||||
}; |
|
||||||
|
|
||||||
return this.update(query, update); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.findAlwaysNotifyAudioUsersByRoomId = function(roomId) { |
|
||||||
const query = { |
|
||||||
rid: roomId, |
|
||||||
audioNotifications: 'all', |
|
||||||
}; |
|
||||||
|
|
||||||
return this.find(query); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.findAlwaysNotifyDesktopUsersByRoomId = function(roomId) { |
|
||||||
const query = { |
|
||||||
rid: roomId, |
|
||||||
desktopNotifications: 'all', |
|
||||||
}; |
|
||||||
|
|
||||||
return this.find(query); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.findDontNotifyDesktopUsersByRoomId = function(roomId) { |
|
||||||
const query = { |
|
||||||
rid: roomId, |
|
||||||
desktopNotifications: 'nothing', |
|
||||||
}; |
|
||||||
|
|
||||||
return this.find(query); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.findAlwaysNotifyMobileUsersByRoomId = function(roomId) { |
|
||||||
const query = { |
|
||||||
rid: roomId, |
|
||||||
mobilePushNotifications: 'all', |
|
||||||
}; |
|
||||||
|
|
||||||
return this.find(query); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.findDontNotifyMobileUsersByRoomId = function(roomId) { |
|
||||||
const query = { |
|
||||||
rid: roomId, |
|
||||||
mobilePushNotifications: 'nothing', |
|
||||||
}; |
|
||||||
|
|
||||||
return this.find(query); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.findWithSendEmailByRoomId = function(roomId) { |
|
||||||
const query = { |
|
||||||
rid: roomId, |
|
||||||
emailNotifications: { |
|
||||||
$exists: true, |
|
||||||
}, |
|
||||||
}; |
|
||||||
|
|
||||||
return this.find(query, { fields: { emailNotifications: 1, u: 1 } }); |
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.findNotificationPreferencesByRoom = function(query/* { roomId: rid, desktopFilter: desktopNotifications, mobileFilter: mobilePushNotifications, emailFilter: emailNotifications }*/) { |
|
||||||
|
|
||||||
return this._db.find(query, { |
|
||||||
fields: { |
|
||||||
|
|
||||||
// fields needed for notifications
|
|
||||||
rid: 1, |
|
||||||
t: 1, |
|
||||||
u: 1, |
|
||||||
name: 1, |
|
||||||
fname: 1, |
|
||||||
code: 1, |
|
||||||
|
|
||||||
// fields to define if should send a notification
|
|
||||||
ignored: 1, |
|
||||||
audioNotifications: 1, |
|
||||||
audioNotificationValue: 1, |
|
||||||
desktopNotificationDuration: 1, |
|
||||||
desktopNotifications: 1, |
|
||||||
mobilePushNotifications: 1, |
|
||||||
emailNotifications: 1, |
|
||||||
disableNotifications: 1, |
|
||||||
muteGroupMentions: 1, |
|
||||||
userHighlights: 1, |
|
||||||
}, |
|
||||||
}); |
|
||||||
}; |
|
||||||
|
|
||||||
RocketChat.models.Subscriptions.findAllMessagesNotificationPreferencesByRoom = function(roomId) { |
|
||||||
const query = { |
|
||||||
rid: roomId, |
|
||||||
'u._id': { $exists: true }, |
|
||||||
$or: [ |
|
||||||
{ desktopNotifications: { $in: ['all', 'mentions'] } }, |
|
||||||
{ mobilePushNotifications: { $in: ['all', 'mentions'] } }, |
|
||||||
{ emailNotifications: { $in: ['all', 'mentions'] } }, |
|
||||||
], |
|
||||||
}; |
|
||||||
|
|
||||||
return this._db.find(query, { |
|
||||||
fields: { |
|
||||||
'u._id': 1, |
|
||||||
audioNotifications: 1, |
|
||||||
audioNotificationValue: 1, |
|
||||||
desktopNotificationDuration: 1, |
|
||||||
desktopNotifications: 1, |
|
||||||
mobilePushNotifications: 1, |
|
||||||
emailNotifications: 1, |
|
||||||
disableNotifications: 1, |
|
||||||
muteGroupMentions: 1, |
|
||||||
}, |
|
||||||
}); |
|
||||||
}; |
|
@ -0,0 +1,31 @@ |
|||||||
|
import { settings } from 'meteor/rocketchat:settings'; |
||||||
|
import { Users } from 'meteor/rocketchat:models'; |
||||||
|
|
||||||
|
export const getUserNotificationPreference = (user, pref) => { |
||||||
|
if (typeof user === 'string') { |
||||||
|
user = Users.findOneById(user); |
||||||
|
} |
||||||
|
|
||||||
|
let preferenceKey; |
||||||
|
switch (pref) { |
||||||
|
case 'desktop': preferenceKey = 'desktopNotifications'; break; |
||||||
|
case 'mobile': preferenceKey = 'mobileNotifications'; break; |
||||||
|
case 'email': preferenceKey = 'emailNotificationMode'; break; |
||||||
|
} |
||||||
|
|
||||||
|
if (user && user.settings && user.settings.preferences && user.settings.preferences[preferenceKey] !== 'default') { |
||||||
|
return { |
||||||
|
value: user.settings.preferences[preferenceKey], |
||||||
|
origin: 'user', |
||||||
|
}; |
||||||
|
} |
||||||
|
const serverValue = settings.get(`Accounts_Default_User_Preferences_${ preferenceKey }`); |
||||||
|
if (serverValue) { |
||||||
|
return { |
||||||
|
value: serverValue, |
||||||
|
origin: 'server', |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
}; |
Loading…
Reference in new issue