mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-07-01 00:18:19 +02:00
feat(messages): show unread messages count on header menu
This commit is contained in:
@@ -491,7 +491,8 @@
|
||||
LIST_SENDAT: 'SendedAt',
|
||||
LIST_SELECT: 'Select',
|
||||
INFO_SEND_TO: 'send to',
|
||||
INFO_SEND_AT: 'at'
|
||||
INFO_SEND_AT: 'at',
|
||||
NEW_MSG: 'New messages'
|
||||
},
|
||||
MESSAGE_TYPE_USER: 'User message',
|
||||
MESSAGE_TYPE_SYSTEM: 'System message',
|
||||
|
||||
@@ -491,7 +491,8 @@
|
||||
LIST_SENDAT: '发送时间',
|
||||
LIST_SELECT: '选择',
|
||||
INFO_SEND_TO: '发送给',
|
||||
INFO_SEND_AT: '于'
|
||||
INFO_SEND_AT: '于',
|
||||
NEW_MSG: '条未读消息'
|
||||
},
|
||||
MESSAGE_TYPE_USER: '用户消息',
|
||||
MESSAGE_TYPE_SYSTEM: '系统消息',
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
.controller('HeaderController', HeaderController);
|
||||
|
||||
HeaderController.$inject = ['$scope', '$state', '$stateParams', '$translate', 'Authentication', 'menuService', 'MeanTorrentConfig', 'localStorageService',
|
||||
'ScoreLevelService', 'InvitationsService'];
|
||||
'ScoreLevelService', 'InvitationsService', '$interval', 'MessagesService'];
|
||||
|
||||
function HeaderController($scope, $state, $stateParams, $translate, Authentication, menuService, MeanTorrentConfig, localStorageService, ScoreLevelService,
|
||||
InvitationsService) {
|
||||
InvitationsService, $interval, MessagesService) {
|
||||
var vm = this;
|
||||
vm.user = Authentication.user;
|
||||
vm.language = MeanTorrentConfig.meanTorrentConfig.language;
|
||||
@@ -42,6 +42,13 @@
|
||||
vm.getInvitationsCount();
|
||||
});
|
||||
|
||||
/**
|
||||
* user-unread-count-changed
|
||||
*/
|
||||
$scope.$on('user-unread-count-changed', function (event, args) {
|
||||
vm.getCountUnread();
|
||||
});
|
||||
|
||||
/**
|
||||
* getInvitationsCount
|
||||
*/
|
||||
@@ -57,11 +64,32 @@
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* checkMessageUnread
|
||||
*/
|
||||
vm.checkMessageUnread = function () {
|
||||
$interval(vm.getCountUnread, 120000);
|
||||
};
|
||||
|
||||
vm.getCountUnread = function () {
|
||||
MessagesService.countUnread(function (data) {
|
||||
console.log(data);
|
||||
vm.unreadCount = data.countFrom + data.countTo;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* stateChangeSuccess
|
||||
*/
|
||||
function stateChangeSuccess() {
|
||||
// Collapsing the menu after navigation
|
||||
vm.isCollapsed = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* changeLanguage
|
||||
* @param langKey
|
||||
*/
|
||||
vm.changeLanguage = function (langKey) {
|
||||
var lang = localStorageService.get('storage_user_lang');
|
||||
if (lang !== langKey) {
|
||||
|
||||
@@ -189,11 +189,7 @@ body {
|
||||
top: 3px;
|
||||
}
|
||||
|
||||
.menu-score-parent {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.menu-invitation-parent {
|
||||
.menu-parent {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="container" ng-controller="HeaderController as vm" ng-init="vm.getInvitationsCount();">
|
||||
<div class="container" ng-controller="HeaderController as vm" ng-init="vm.getInvitationsCount(); vm.checkMessageUnread(); vm.getCountUnread();">
|
||||
<div class="navbar-header">
|
||||
<button class="navbar-toggle" type="button" ng-click="vm.isCollapsed = !vm.isCollapsed">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
@@ -42,16 +42,16 @@
|
||||
</span>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li ui-sref-active="active" ng-repeat="item in vm.messagesMenu.items">
|
||||
<a ui-sref="{{item.state}}" ng-bind="item.title" menu-title="{{item.title}}"></a>
|
||||
<li ui-sref-active="active" ng-repeat="item in vm.messagesMenu.items" class="menu-parent">
|
||||
<a ui-sref="{{item.state}}" ng-bind="item.title" menu-title="{{item.title}}"></a><span class="badge menu-badge badge_danger" ng-show="vm.unreadCount>0">{{vm.unreadCount}}</span>
|
||||
</li>
|
||||
<li ui-sref-active="active" ng-repeat="item in vm.statusMenu.items">
|
||||
<a ui-sref="{{item.state}}" ng-bind="item.title" menu-title="{{item.title}}"></a>
|
||||
</li>
|
||||
<li ui-sref-active="active" ng-repeat="item in vm.scoreMenu.items" class="menu-score-parent">
|
||||
<li ui-sref-active="active" ng-repeat="item in vm.scoreMenu.items" class="menu-parent">
|
||||
<a ui-sref="{{item.state}}" ng-bind="item.title" menu-title="{{item.title}}"></a><span class="menu-score" score-level="vm.scoreLevelData.currLevel"></span>
|
||||
</li>
|
||||
<li ui-sref-active="active" ng-repeat="item in vm.inviteMenu.items" class="menu-invitation-parent">
|
||||
<li ui-sref-active="active" ng-repeat="item in vm.inviteMenu.items" class="menu-parent">
|
||||
<a ui-sref="{{item.state}}" ng-bind="item.title" menu-title="{{item.title}}"></a><span class="badge menu-badge badge_danger">{{vm.countMyInvitations}}</span>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
.controller('MessageController', MessageController);
|
||||
|
||||
MessageController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', '$filter', 'NotifycationService', '$stateParams', 'MessagesService',
|
||||
'MeanTorrentConfig', 'ModalConfirmService', 'marked'];
|
||||
'MeanTorrentConfig', 'ModalConfirmService', 'marked', '$rootScope'];
|
||||
|
||||
function MessageController($scope, $state, $translate, $timeout, Authentication, $filter, NotifycationService, $stateParams, MessagesService,
|
||||
MeanTorrentConfig, ModalConfirmService, marked) {
|
||||
MeanTorrentConfig, ModalConfirmService, marked, $rootScope) {
|
||||
var vm = this;
|
||||
vm.messageConfig = MeanTorrentConfig.meanTorrentConfig.messages;
|
||||
vm.user = Authentication.user;
|
||||
@@ -27,6 +27,13 @@
|
||||
document.getElementById('popupSlide').addEventListener('transitionend', onTransitionEnd, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* user-unread-count-changed
|
||||
*/
|
||||
$scope.$on('user-unread-count-changed', function (event, args) {
|
||||
vm.getCountUnread();
|
||||
});
|
||||
|
||||
/**
|
||||
* checkSendTo
|
||||
*/
|
||||
@@ -213,6 +220,18 @@
|
||||
vm.messages.splice(vm.messages.indexOf(m), 0, res);
|
||||
vm.messages.splice(vm.messages.indexOf(m), 1);
|
||||
vm.figureOutItemsToDisplay();
|
||||
|
||||
$rootScope.$broadcast('user-unread-count-changed');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* getCountUnread
|
||||
*/
|
||||
vm.getCountUnread = function () {
|
||||
MessagesService.countUnread(function (data) {
|
||||
console.log(data);
|
||||
vm.unreadCount = data.countFrom + data.countTo;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
}, {
|
||||
update: {
|
||||
method: 'PUT'
|
||||
},
|
||||
countUnread: {
|
||||
url: '/api/messages/countUnread',
|
||||
method: 'GET'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<section ng-controller="MessageController as vm" ng-init="vm.getMessageList()">
|
||||
<section ng-controller="MessageController as vm" ng-init="vm.getMessageList(); vm.getCountUnread();">
|
||||
<div class="row margin-top-20">
|
||||
<div class="col-sm-12 messages-list">
|
||||
|
||||
<div class="row margin-bottom-20">
|
||||
<div class="col-xs-8 col-md-9">
|
||||
<h4>{{'MESSAGES_BOX' | translate}}</h4>
|
||||
<h4>{{'MESSAGES_BOX' | translate}}<small ng-show="vm.unreadCount>0"> - (<span class="badge badge_danger">{{vm.unreadCount}}</span> {{'MESSAGES_FIELD.NEW_MSG' | translate}})</small></h4>
|
||||
</div>
|
||||
<div class="col-xs-4 col-md-3">
|
||||
<input class="form-control" type="text" ng-model="vm.search" placeholder="Search"
|
||||
|
||||
@@ -171,6 +171,50 @@ exports.createReply = function (req, res) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* countUnread
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
exports.countUnread = function (req, res) {
|
||||
var countFrom = function (callback) {
|
||||
Message.count({
|
||||
from_user: req.user._id,
|
||||
from_status: 0
|
||||
}, function (err, count) {
|
||||
if (err) {
|
||||
callback(err, null);
|
||||
} else {
|
||||
callback(null, count);
|
||||
}
|
||||
});
|
||||
};
|
||||
var countTo = function (callback) {
|
||||
Message.count({
|
||||
to_user: req.user._id,
|
||||
to_status: 0
|
||||
}, function (err, count) {
|
||||
if (err) {
|
||||
callback(err, null);
|
||||
} else {
|
||||
callback(null, count);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
async.parallel([countFrom, countTo], function (err, results) {
|
||||
if (err) {
|
||||
return res.status(422).send(err);
|
||||
} else {
|
||||
res.json({
|
||||
countFrom: results[0],
|
||||
countTo: results[1]
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Invitation middleware
|
||||
*/
|
||||
|
||||
@@ -18,7 +18,8 @@ exports.invokeRolesPolicies = function () {
|
||||
roles: ['admin', 'oper', 'user'],
|
||||
allows: [
|
||||
{resources: '/api/messages', permissions: '*'},
|
||||
{resources: '/api/messages/:messageId', permissions: '*'}
|
||||
{resources: '/api/messages/:messageId', permissions: '*'},
|
||||
{resources: '/api/messages/countUnread', permissions: '*'}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -12,6 +12,9 @@ module.exports = function (app) {
|
||||
.post(messages.create)
|
||||
.delete(messages.delete);
|
||||
|
||||
app.route('/api/messages/countUnread').all(messagesPolicy.isAllowed)
|
||||
.get(messages.countUnread);
|
||||
|
||||
app.route('/api/messages/:messageId').all(messagesPolicy.isAllowed)
|
||||
.delete(messages.delete)
|
||||
.put(messages.update)
|
||||
|
||||
Reference in New Issue
Block a user