diff --git a/app/lib/server/functions/notifications/serviceAccount.js b/app/lib/server/functions/notifications/serviceAccount.js new file mode 100644 index 0000000000000..3776989c063b2 --- /dev/null +++ b/app/lib/server/functions/notifications/serviceAccount.js @@ -0,0 +1,27 @@ +import { metrics } from '../../../../metrics'; +import { Notifications } from '../../../../notifications'; + +export function shouldNotifyServiceAccountOwner({ + hasMentionToAll, + hasMentionToHere, + isHighlighted, + hasMentionToUser, + hasReplyToThread, + roomType, +}) { + return roomType === 'd' || hasMentionToAll || hasMentionToHere || isHighlighted || hasMentionToUser || hasReplyToThread; +} + +export function notifyServiceAccountOwner(receiver, ownerId, message, room) { + metrics.notificationsSent.inc({ notification_type: 'sa' }); + Notifications.notifyUser(ownerId, 'sa-notification', { + payload: { + _id: message._id, + rid: message.rid, + sender: message.u, + receiver: receiver.username, + type: room.t, + name: room.name, + }, + }); +} diff --git a/app/lib/server/lib/sendNotificationsOnMessage.js b/app/lib/server/lib/sendNotificationsOnMessage.js index db544f058509a..0c37d2165110d 100644 --- a/app/lib/server/lib/sendNotificationsOnMessage.js +++ b/app/lib/server/lib/sendNotificationsOnMessage.js @@ -11,6 +11,7 @@ import { sendEmail, shouldNotifyEmail } from '../functions/notifications/email'; import { sendSinglePush, shouldNotifyMobile } from '../functions/notifications/mobile'; import { notifyDesktopUser, shouldNotifyDesktop } from '../functions/notifications/desktop'; import { notifyAudioUser, shouldNotifyAudio } from '../functions/notifications/audio'; +import { notifyServiceAccountOwner, shouldNotifyServiceAccountOwner } from '../functions/notifications/serviceAccount'; export const sendNotification = async ({ subscription, @@ -46,6 +47,7 @@ export const sendNotification = async ({ status: 1, statusConnection: 1, username: 1, + u: 1, }, }), ]; @@ -149,6 +151,17 @@ export const sendNotification = async ({ return false; }); } + + if (receiver.u && shouldNotifyServiceAccountOwner({ + hasMentionToAll, + hasMentionToHere, + isHighlighted, + hasMentionToUser, + hasReplyToThread, + roomType, + })) { + notifyServiceAccountOwner(receiver, receiver.u._id, message, room); + } }; const project = { @@ -168,6 +181,7 @@ const project = { 'receiver.status': 1, 'receiver.statusConnection': 1, 'receiver.username': 1, + 'receiver.u': 1, }, }; diff --git a/app/service-accounts/client/stylesheets/serviceAccounts.css b/app/service-accounts/client/stylesheets/serviceAccounts.css new file mode 100644 index 0000000000000..7555900c62150 --- /dev/null +++ b/app/service-accounts/client/stylesheets/serviceAccounts.css @@ -0,0 +1,65 @@ +.rc-service-account-list { + &__user { + + display: flex; + + padding: 8px 0; + + cursor: pointer; + align-items: center; + + &.active, + &:hover { + background-color: #eeeeee; + + & .rc-member-list__menu { + opacity: 1; + } + } + + & > .avatar { + width: var(--sidebar-account-thumb-size); + height: var(--sidebar-account-thumb-size); + } + } + + &__username { + display: flex; + flex: 1 1 auto; + + margin: 0 12px 0 8px; + + font-size: 16px; + align-items: center; + } + + &__username-alert { + font-weight: bold; + } + + &__add { + display: inline-block; + + width: 100%; + + padding: 4px 0; + + cursor: pointer; + + user-select: none; + + transition: all 0.3s; + + text-align: center; + + color: var(--popover-item-color); + + font-size: var(--popover-item-text-size); + + align-items: center; + } +} + +.service-account-notification { + color: var(--rc-color-alert-message-primary-background); +} diff --git a/app/service-accounts/client/views/serviceAccountSidebarLogin.html b/app/service-accounts/client/views/serviceAccountSidebarLogin.html index 4fc8970a3fe3f..e3acb19e18d78 100644 --- a/app/service-accounts/client/views/serviceAccountSidebarLogin.html +++ b/app/service-accounts/client/views/serviceAccountSidebarLogin.html @@ -1,27 +1,42 @@