Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make unread messages badges only show mentions #153

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions client/startup/startup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ Meteor.startup ->
KonchatNotification.newMessage()

Tracker.autorun ->
unreadCount = 0
subscriptions = ChatSubscription.find({}, { fields: { unread: 1 } })
(unreadCount += r.unread) for r in subscriptions.fetch()
mentionsCount = 0
subscriptions = ChatSubscription.find({}, { fields: { mentions: 1 } })
(mentionsCount += r.mentions) for r in subscriptions.fetch()

rxFavico.set 'type', 'warn'
rxFavico.set 'count', unreadCount
rxFavico.set 'count', mentionsCount

if unreadCount > 0
document.title = '(' + unreadCount + ') Rocket.Chat'
if mentionsCount > 0
document.title = '(' + mentionsCount + ') Rocket.Chat'
else
document.title = 'Rocket.Chat'

Expand Down
8 changes: 6 additions & 2 deletions client/stylesheets/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ a.github-fork {
}
}
}
.unread {
.mentions {
background-color: #1dce73;
min-width: 15px;
padding: 0 2px;
Expand Down Expand Up @@ -1208,7 +1208,11 @@ a.github-fork {
background-color: transparent;
}
}
&.has-unread {
&.has-unread a, &.has-mentions a {
font-weight: bold;
color: #fff;
}
&.has-mentions {
.opt {
opacity: 0;
}
Expand Down
6 changes: 6 additions & 0 deletions client/views/app/sideNav/chatRoomItem.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Template.chatRoomItem.helpers
else if Router.current().params._id is this.rid and this.unread > 0
Meteor.call 'readMessages', this.rid

mentions: ->
if (not Router.current().params._id) or Router.current().params._id isnt this.rid
return this.mentions
else if Router.current().params._id is this.rid and this.mentions > 0
Meteor.call 'readMessages', this.rid

isDirectRoom: ->
return this.t is 'd'

Expand Down
6 changes: 3 additions & 3 deletions client/views/app/sideNav/chatRoomItem.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template name="chatRoomItem">
<li class="link-room-{{rid}} {{active}} {{#if unread}}has-unread{{/if}}">
<li class="link-room-{{rid}} {{active}} {{#if unread}}has-unread{{/if}} {{#if mentions}}has-mentions{{/if}}">
<a href="{{ pathFor 'room' _id=rid}}" title="{{name}}">
{{#if unread}}
<span class="unread">{{unread}}</span>
{{#if mentions}}
<span class="mentions">{{mentions}}</span>
{{/if}}
<i class="{{roomIcon}} {{userStatus}}"></i>
<span>{{name}}</span>
Expand Down
1 change: 1 addition & 0 deletions server/methods/addUserToRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Meteor.methods
rn: room.name
t: room.t
unread: 0
mentions: 0

ChatMessage.insert
rid: data.rid
Expand Down
1 change: 1 addition & 0 deletions server/methods/canAccessRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Meteor.methods
rn: room.name
t: room.t
unread: 0
mentions: 0
$set:
ls: (new Date())
ts: (new Date())
Expand Down
1 change: 1 addition & 0 deletions server/methods/createChannel.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Meteor.methods
rn: name
t: 'c'
unread: 0
mentions: 0

if username is Meteor.user().username
sub.ls = now
Expand Down
2 changes: 2 additions & 0 deletions server/methods/createDirectRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Meteor.methods
$setOnInsert:
t: 'd'
unread: 0
mentions: 0
'u._id': userTo._id

ChatSubscription.upsert { $and: [{'u._id': userTo._id}], rid: roomId },
Expand All @@ -40,6 +41,7 @@ Meteor.methods
$setOnInsert:
t: 'd'
unread: 0
mentions: 0
'u._id': userTo._id

return {
Expand Down
1 change: 1 addition & 0 deletions server/methods/createPrivateGroup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Meteor.methods
rn: name
t: 'p'
unread: 0
mentions: 0

if username is Meteor.user().username
sub.ls = now
Expand Down
2 changes: 1 addition & 1 deletion server/methods/readMessages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Meteor.methods
else
throw new Meteor.Error 203, '[methods] readMessages -> Invalid user'

ChatSubscription.update filter, { $set: { unread: 0, ls: (new Date()) } }
ChatSubscription.update filter, { $set: { unread: 0, mentions: 0, ls: (new Date()) } }
12 changes: 12 additions & 0 deletions server/methods/sendMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ Meteor.methods
# increment unread counter on which user in room
Meteor.defer -> ChatSubscription.update activityFilter, { $inc: { unread: 1 }, $set: { ts: now } }, { multi: true }

updateMentions = (username, rid) ->
user = Meteor.users.findOne({username: username}, {fields: {_id: 1}})
if !user
return
filter = { rid: rid, 'u._id': user._id }
Meteor.defer -> ChatSubscription.update filter, { $inc: { mentions: 1 }, $set: { ts: now } }, { multi: true }

if mentions
updateMentions m.username, rid for m in mentions

Meteor.defer -> ChatSubscription.update activityFilter, { $inc: { unread: 1 }, $set: { ts: now } }, { multi: true }

return retObj

updateMessage: (msg) ->
Expand Down
1 change: 1 addition & 0 deletions server/methods/setUsername.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Meteor.methods
f: true
ts: new Date()
unread: 0
mentions: 0

ChatMessage.insert
u:
Expand Down