Skip to content

Commit

Permalink
Merge pull request #2334 from RocketChat/notifications-sandstorm
Browse files Browse the repository at this point in the history
Avoid using SVG for Sandstorm
  • Loading branch information
engelgabriel committed Feb 24, 2016
2 parents b07e23d + 6060dfd commit 5f38dd7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Template.accountPreferences.events
KonchatNotification.getDesktopPermission()

'click .test-notifications': ->
KonchatNotification._showDesktop
KonchatNotification.notify
payload:
sender:
username: 'rocket.cat'
Expand Down
37 changes: 20 additions & 17 deletions packages/rocketchat-ui/lib/notification.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,31 @@
if Notification.permission != status
Notification.permission = status

# notificacoes HTML5
_showDesktop: (notification) ->
notify: (notification) ->
if window.Notification && Notification.permission == "granted"
getAvatarAsPng notification.payload.sender.username, (avatarImage) ->
n = new Notification notification.title,
icon: avatarImage
body: _.stripTags(notification.text)
n = new Notification notification.title,
icon: notification.icon or getAvatarUrlFromUsername notification.payload.sender.username
body: _.stripTags(notification.text)

if notification.payload?.rid?
n.onclick = ->
window.focus()
switch notification.payload.type
when 'd'
FlowRouter.go 'direct', {username: notification.payload.sender.username}
when 'c'
FlowRouter.go 'channel', {name: notification.payload.name}
when 'p'
FlowRouter.go 'group', {name: notification.payload.name}
if notification.payload?.rid?
n.onclick = ->
window.focus()
switch notification.payload.type
when 'd'
FlowRouter.go 'direct', {username: notification.payload.sender.username}
when 'c'
FlowRouter.go 'channel', {name: notification.payload.name}
when 'p'
FlowRouter.go 'group', {name: notification.payload.name}

showDesktop: (notification) ->
if not window.document.hasFocus?() and Meteor.user().status isnt 'busy'
KonchatNotification._showDesktop(notification)
if Meteor.settings.public.sandstorm
KonchatNotification.notify(notification)
else
getAvatarAsPng notification.payload.sender.username, (avatarAsPng) ->
notification.icon = avatarAsPng
KonchatNotification.notify(notification)

newMessage: ->
unless Session.equals('user_' + Meteor.userId() + '_status', 'busy') or Meteor.user()?.settings?.preferences?.disableNewMessageNotification
Expand Down

0 comments on commit 5f38dd7

Please sign in to comment.