mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
use $resource class methods to avoid sending whole model to server & reduce some responses
This commit is contained in:
@@ -45,19 +45,20 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
|
|||||||
$scope.removeMember = function(group, member, isMember){
|
$scope.removeMember = function(group, member, isMember){
|
||||||
var yes = confirm("Do you really want to remove this member from the party?")
|
var yes = confirm("Do you really want to remove this member from the party?")
|
||||||
if(yes){
|
if(yes){
|
||||||
group.$removeMember({uuid: member._id});
|
Groups.Group.removeMember({gid: group._id, uuid: member._id }, undefined, function(){
|
||||||
if(isMember){
|
if(isMember){
|
||||||
_.pull(group.members, member);
|
_.pull(group.members, member);
|
||||||
}else{
|
}else{
|
||||||
_.pull(group.invites, member);
|
_.pull(group.invites, member);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------ Invites ------
|
// ------ Invites ------
|
||||||
|
|
||||||
$scope.invite = function(group){
|
$scope.invite = function(group){
|
||||||
group.$invite({uuid:group.invitee}, function(){
|
Groups.Group.invite({gid: group._id, uuid: group.invitee}, undefined, function(){
|
||||||
group.invitee = '';
|
group.invitee = '';
|
||||||
}, function(){
|
}, function(){
|
||||||
group.invitee = '';
|
group.invitee = '';
|
||||||
@@ -85,8 +86,8 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
|
|||||||
$scope.postChat = function(group, message){
|
$scope.postChat = function(group, message){
|
||||||
if (_.isEmpty(message) || $scope._sending) return;
|
if (_.isEmpty(message) || $scope._sending) return;
|
||||||
$scope._sending = true;
|
$scope._sending = true;
|
||||||
group.$postChat({message:message}, function(data){
|
Groups.Group.postChat({gid: group._id, message:message}, undefined, function(data){
|
||||||
group.chat = data.chat;
|
group.chat.unshift(data.message);
|
||||||
$scope._chatMessage = '';
|
$scope._chatMessage = '';
|
||||||
$scope._sending = false;
|
$scope._sending = false;
|
||||||
}, function(err){
|
}, function(err){
|
||||||
@@ -96,7 +97,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
|
|||||||
|
|
||||||
$scope.deleteChatMessage = function(group, message){
|
$scope.deleteChatMessage = function(group, message){
|
||||||
if(message.uuid === User.user.id || (User.user.backer && User.user.backer.admin)){
|
if(message.uuid === User.user.id || (User.user.backer && User.user.backer.admin)){
|
||||||
group.$deleteChatMessage({messageId: message.id}, function(){
|
Groups.Group.deleteChatMessage({gid: group._id, messageId: message.id}, undefined, function(){
|
||||||
var i = _.indexOf(group.chat, message);
|
var i = _.indexOf(group.chat, message);
|
||||||
if(i !== -1) group.chat.splice(i, 1);
|
if(i !== -1) group.chat.splice(i, 1);
|
||||||
});
|
});
|
||||||
@@ -172,7 +173,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
|
|||||||
if (confirm("Are you sure you want to leave this guild?") !== true) {
|
if (confirm("Are you sure you want to leave this guild?") !== true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
group.$leave(function(){
|
Groups.Group.leave({gid: group._id}, undefined, function(){
|
||||||
$scope.groups.guilds.splice(_.indexOf($scope.groups.guilds, group), 1);
|
$scope.groups.guilds.splice(_.indexOf($scope.groups.guilds, group), 1);
|
||||||
// remove user from group members if guild is public so that he can re-join it immediately
|
// remove user from group members if guild is public so that he can re-join it immediately
|
||||||
if(group.privacy == 'public' || !group.privacy){ //public guilds with only some fields fetched
|
if(group.privacy == 'public' || !group.privacy){ //public guilds with only some fields fetched
|
||||||
@@ -221,7 +222,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
|
|||||||
if (confirm("Are you sure you want to leave this party?") !== true) {
|
if (confirm("Are you sure you want to leave this party?") !== true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
group.$leave(function(){
|
Groups.Group.leave({gid: group._id}, undefined, function(){
|
||||||
$scope.group = undefined;
|
$scope.group = undefined;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,17 +218,11 @@ api.postChat = function(req, res, next) {
|
|||||||
user.save();
|
user.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
async.series([
|
group.save(function(err, saved){
|
||||||
function(cb){
|
|
||||||
group.save(cb)
|
|
||||||
},
|
|
||||||
function(cb){
|
|
||||||
populateQuery(group.type, Group.findById(group._id)).exec(cb);
|
|
||||||
}
|
|
||||||
], function(err, results){
|
|
||||||
if (err) return res.json(500, {err:err});
|
if (err) return res.json(500, {err:err});
|
||||||
res.json(results[1]);
|
|
||||||
})
|
res.json({message: saved.chat[0]});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
api.deleteChatMessage = function(req, res){
|
api.deleteChatMessage = function(req, res){
|
||||||
|
|||||||
Reference in New Issue
Block a user