mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-03 12:40:00 +00:00
feat(flag-message): add server methods
This commit is contained in:
parent
e49e8f5765
commit
ae6e0255c6
7 changed files with 67 additions and 24 deletions
|
|
@ -105,24 +105,11 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
|||
$rootScope.openModal('private-message',{controller:'MemberModalCtrl'});
|
||||
});
|
||||
}
|
||||
$scope.flagChatMessage = function(message) {
|
||||
if(!message.flags) message.flags = {};
|
||||
if(message.flags[User.user._id])
|
||||
Notification.text(window.env.t('abuseAlreadyReported'));
|
||||
else {
|
||||
$scope.abuseObject = message;
|
||||
Members.selectMember(message.uuid, function(){
|
||||
$rootScope.openModal('abuse-flag',{controller:'MemberModalCtrl',
|
||||
scope: $scope
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
.controller("MemberModalCtrl", ['$scope', '$rootScope', 'Members', 'Shared', '$http', 'Notification',
|
||||
function($scope, $rootScope, Members, Shared, $http, Notification) {
|
||||
.controller("MemberModalCtrl", ['$scope', '$rootScope', 'Members', 'Shared', '$http', 'Notification', 'Groups',
|
||||
function($scope, $rootScope, Members, Shared, $http, Notification, Groups) {
|
||||
$scope.timestamp = function(timestamp){
|
||||
return moment(timestamp).format('MM/DD/YYYY');
|
||||
}
|
||||
|
|
@ -152,12 +139,12 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
|||
$scope.$close();
|
||||
})
|
||||
}
|
||||
$scope.reportAbuse = function(reporter, message) {
|
||||
$scope.reportAbuse = function(reporter, message, groupId) {
|
||||
message.flags[reporter._id] = true;
|
||||
// @TODO @paglias API Call goes here
|
||||
Notification.text(window.env.t('abuseReported'));
|
||||
$rootScope.User.sync();
|
||||
$scope.$close();
|
||||
Groups.Group.flagChatMessage({gid: groupId, messageId: message.id}, undefined, function(data){
|
||||
Notification.text(window.env.t('abuseReported'));
|
||||
$scope.$close();
|
||||
});
|
||||
}
|
||||
}
|
||||
])
|
||||
|
|
@ -217,7 +204,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
|||
});
|
||||
}])
|
||||
|
||||
.controller('ChatCtrl', ['$scope', 'Groups', 'User', '$http', 'ApiUrlService', 'Notification', function($scope, Groups, User, $http, ApiUrlService, Notification){
|
||||
.controller('ChatCtrl', ['$scope', 'Groups', 'User', '$http', 'ApiUrlService', 'Notification', 'Members', '$rootScope', function($scope, Groups, User, $http, ApiUrlService, Notification, Members, $rootScope){
|
||||
$scope.message = {content:''};
|
||||
$scope._sending = false;
|
||||
|
||||
|
|
@ -282,6 +269,22 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
|||
$http.post(ApiUrlService.get() + '/api/v2/groups/' + group._id + '/chat/' + message.id + '/like');
|
||||
}
|
||||
|
||||
$scope.flagChatMessage = function(groupId,message) {
|
||||
if(!message.flags) message.flags = {};
|
||||
if(message.flags[User.user._id])
|
||||
Notification.text(window.env.t('abuseAlreadyReported'));
|
||||
else {
|
||||
$scope.abuseObject = message;
|
||||
$scope.groupId = groupId;
|
||||
Members.selectMember(message.uuid, function(){
|
||||
$rootScope.openModal('abuse-flag',{
|
||||
controller:'MemberModalCtrl',
|
||||
scope: $scope
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$scope.sync = function(group){
|
||||
group.$get();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ angular.module('groupServices', ['ngResource']).
|
|||
//query: {method: "GET", isArray:false},
|
||||
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'},
|
||||
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'},
|
||||
|
|
|
|||
|
|
@ -256,6 +256,22 @@ api.deleteChatMessage = function(req, res, next){
|
|||
});
|
||||
}
|
||||
|
||||
api.flagChatMessage = 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(message.uuid == user._id) return res.json(401, {err: "Can't report your own message."});
|
||||
|
||||
message.flags[user._id] = true;
|
||||
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
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ var chatDefaults = module.exports.chatDefaults = function(msg,user){
|
|||
text: msg,
|
||||
timestamp: +new Date,
|
||||
likes: {},
|
||||
flags: {} // for @paglias, @crookedneighbor added this.
|
||||
flags: {}
|
||||
};
|
||||
if (user) {
|
||||
_.defaults(message, {
|
||||
|
|
@ -317,6 +317,18 @@ GroupSchema.statics.bossQuest = function(user, progress, cb) {
|
|||
})
|
||||
}
|
||||
|
||||
GroupSchema.methods.toJSON = function() {
|
||||
var doc = this.toObject();
|
||||
if(doc.chat){
|
||||
doc.chat.forEach(function(msg){
|
||||
msg.flags = {};
|
||||
});
|
||||
}
|
||||
|
||||
return doc;
|
||||
};
|
||||
|
||||
|
||||
module.exports.schema = GroupSchema;
|
||||
var Group = module.exports.model = mongoose.model("Group", GroupSchema);
|
||||
|
||||
|
|
|
|||
|
|
@ -577,6 +577,17 @@ module.exports = (swagger, v2) ->
|
|||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action: groups.likeChatMessage
|
||||
|
||||
"/groups/{gid}/chat/{mid}/flag":
|
||||
spec:
|
||||
method: 'POST'
|
||||
description: "Flag a chat message"
|
||||
parameters: [
|
||||
path 'gid','Group id','string'
|
||||
path 'mid','Message id','string'
|
||||
]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action: groups.flagChatMessage
|
||||
|
||||
# ---------------------------------
|
||||
# Members
|
||||
# ---------------------------------
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ mixin chatMessages(inbox)
|
|||
|
|
||||
a(ng-click='#{inbox? "user.ops.deletePM({params:{id:message.$key}})" : "deleteChatMessage(group, message)"}', ng-if='#{inbox ? "true" : ":: user.contributor.admin || message.uuid == user.id"}')
|
||||
span.glyphicon.glyphicon-trash(tooltip=env.t('delete'))
|
||||
a(ng-click="flagChatMessage(message)", ng-if='#{inbox ? "true" : ":: message.uuid != user.id && message.uuid != \'system\'"}')
|
||||
a(ng-click="flagChatMessage(group._id, message)", ng-if='#{inbox ? "true" : ":: message.uuid != user.id && message.uuid != \'system\'"}')
|
||||
span.glyphicon.glyphicon-flag(tooltip="{{message.flags[user._id] ? env.t('abuseAlreadyReported') : env.t('abuseFlag')}}" ng-class='message.flags[user._id] ? "text-danger" : ""')
|
||||
span.float-label
|
||||
a.label.label-default.chat-message(ng-if=':: message.user', ng-class='::userLevelStyleFromLevel(message.contributor.level, message.backer.npc, style)', ng-click='clickMember(message.uuid, true)')
|
||||
|
|
|
|||
|
|
@ -99,4 +99,4 @@ script(type='text/ng-template', id='modals/abuse-flag.html')
|
|||
p!=env.t('abuseFlagModalBody', {firstLinkStart: "<a href='/static/community-guidelines' target='_blank'>", secondLinkStart: "<a href='/static/terms' target='_blank'>", linkEnd: "</a>"})
|
||||
.modal-footer
|
||||
button.btn.btn-primary(ng-click='$close()')=env.t('cancel')
|
||||
button.btn.btn-default(ng-click='reportAbuse(user, abuseObject)')=env.t("abuseFlagModalButton")
|
||||
button.btn.btn-default(ng-click='reportAbuse(user, abuseObject, groupId)')=env.t("abuseFlagModalButton")
|
||||
|
|
|
|||
Loading…
Reference in a new issue