diff --git a/public/js/controllers/groupsCtrl.js b/public/js/controllers/groupsCtrl.js index dfd5718247..f99a79ec76 100644 --- a/public/js/controllers/groupsCtrl.js +++ b/public/js/controllers/groupsCtrl.js @@ -146,6 +146,14 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', ' $scope.$close(); }); } + $scope.clearFlagCount = function(message, groupId) { + console.log("Heeey"); + Groups.Group.clearFlagCount({gid: groupId, messageId: message.id}, undefined, function(data){ + message.flagCount = 0; + Notification.text("Flags cleared"); + $scope.$close(); + }); + } } ]) diff --git a/public/js/services/groupServices.js b/public/js/services/groupServices.js index 45ecc8b971..e07f21b15c 100644 --- a/public/js/services/groupServices.js +++ b/public/js/services/groupServices.js @@ -14,6 +14,7 @@ angular.module('groupServices', ['ngResource']). postChat: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/chat'}, deleteChatMessage: {method: "DELETE", url: ApiUrlService.get() + '/api/v2/groups/:gid/chat/:messageId'}, flagChatMessage: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/chat/:messageId/flag'}, + clearFlagCount: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/chat/:messageId/clearflags'}, join: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/join'}, leave: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/leave'}, invite: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/invite'}, diff --git a/src/controllers/groups.js b/src/controllers/groups.js index 1f40fb7684..dbeaefbd0d 100644 --- a/src/controllers/groups.js +++ b/src/controllers/groups.js @@ -285,6 +285,23 @@ api.flagChatMessage = function(req, res, next){ }); } +api.clearFlagCount = function(req, res, next){ + var user = res.locals.user + var group = res.locals.group; + var message = _.find(group.chat, {id: req.params.mid}); + + if(!message) return res.json(404, {err: "Message not found!"}); + + if(user.contributor.admin) + message.flagCount = 0; + + group.markModified('chat'); + group.save(function(err,_saved){ + if(err) return next(err); + return res.send(204); + }); +} + api.seenMessage = function(req,res,next){ // Skip the auth step, we want this to be fast. If !found with uuid/token, then it just doesn't save // Check for req.params.gid to exist diff --git a/src/routes/apiv2.coffee b/src/routes/apiv2.coffee index 5708bfac51..0f8d272c69 100644 --- a/src/routes/apiv2.coffee +++ b/src/routes/apiv2.coffee @@ -588,6 +588,17 @@ module.exports = (swagger, v2) -> middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup] action: groups.flagChatMessage + "/groups/{gid}/chat/{mid}/clearflags": + spec: + method: 'POST' + description: "Clear flag count from message and unhide it" + parameters: [ + path 'gid','Group id','string' + path 'mid','Message id','string' + ] + middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup] + action: groups.clearFlagCount + # --------------------------------- # Members # --------------------------------- diff --git a/views/shared/modals/members.jade b/views/shared/modals/members.jade index d457213d34..27d42d4623 100644 --- a/views/shared/modals/members.jade +++ b/views/shared/modals/members.jade @@ -98,5 +98,7 @@ script(type='text/ng-template', id='modals/abuse-flag.html') markdown(ng-model="abuseObject.text") p!=env.t('abuseFlagModalBody', {firstLinkStart: "", secondLinkStart: "", linkEnd: ""}) .modal-footer + button.pull-left.btn.btn-primary(ng-click='clearFlagCount(abuseObject, groupId)', ng-if='user.contributor.admin && abuseObject.flagCount >= 2') + | Reset Flag Count button.btn.btn-primary(ng-click='$close()')=env.t('cancel') button.btn.btn-default(ng-click='reportAbuse(user, abuseObject, groupId)')=env.t("abuseFlagModalButton")