mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-21 19:24:15 +00:00
api: group invitations, leave, join
This commit is contained in:
parent
2672b7f6ab
commit
633d6fdb52
8 changed files with 71 additions and 17 deletions
|
|
@ -9,8 +9,6 @@ module.exports.app = (appExports, model, app) ->
|
|||
# Every 60 seconds, reset the current time so that the chat can update relative times
|
||||
setInterval (->_currentTime.set +new Date), 60000
|
||||
|
||||
user = model.at('_user')
|
||||
|
||||
appExports.groupCreate = (e,el) ->
|
||||
type = $(el).attr('data-type')
|
||||
newGroup =
|
||||
|
|
|
|||
|
|
@ -61,6 +61,14 @@ habitrpg
|
|||
$('.chat-btn').removeClass('disabled');
|
||||
});
|
||||
}
|
||||
|
||||
$scope.invitee = '';
|
||||
$scope.invite = function(group, uuid){
|
||||
debugger
|
||||
group.$invite({uuid:uuid}, function(){
|
||||
$scope.invitee = '';
|
||||
});
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
|
|
@ -90,6 +98,12 @@ habitrpg
|
|||
$scope.type = 'party';
|
||||
$scope.text = 'Party';
|
||||
$scope.group = $scope.groups.party;
|
||||
$scope.join = function(party){
|
||||
// workaround since group isn't currently a resource, this won't get saved to the server
|
||||
var group = new Groups({_id: party.id, name: party.name});
|
||||
debugger
|
||||
group.$join();
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ angular.module('groupServices', ['ngResource']).
|
|||
//'query': {method: "GET", isArray:false}
|
||||
postChat: {method: "POST", url: API_URL + '/api/v1/groups/:gid/chat'},
|
||||
join: {method: "POST", url: API_URL + '/api/v1/groups/:gid/join'},
|
||||
leave: {method: "POST", url: API_URL + '/api/v1/groups/:gid/leave'}
|
||||
leave: {method: "POST", url: API_URL + '/api/v1/groups/:gid/leave'},
|
||||
invite: {method: "POST", url: API_URL + '/api/v1/groups/:gid/invite'}
|
||||
});
|
||||
|
||||
return Group;
|
||||
|
|
|
|||
|
|
@ -122,6 +122,16 @@ api.join = function(req, res, next) {
|
|||
if (err) return res.json(500,{err:err});
|
||||
res.json(saved);
|
||||
});
|
||||
|
||||
if (group.type == 'party' && group._id == (user.invitations && user.invitations.party && user.invitations.party.id)) {
|
||||
user.invitations.party = undefined;
|
||||
user.save();
|
||||
}
|
||||
else if (group.type == 'guild' && user.invitations && user.invitations.guilds) {
|
||||
var i = _.findIndex(user.invitations.guilds, {id:group._id});
|
||||
if (~i) user.invitations.guilds.splice(i,1);
|
||||
user.save();
|
||||
}
|
||||
}
|
||||
|
||||
api.leave = function(req, res, next) {
|
||||
|
|
@ -132,4 +142,38 @@ api.leave = function(req, res, next) {
|
|||
if (err) return res.json(500,{err:err});
|
||||
res.send(200, saved);
|
||||
})
|
||||
}
|
||||
|
||||
api.invite = function(req, res, next) {
|
||||
var group = res.locals.group;
|
||||
var uuid = req.query.uuid;
|
||||
|
||||
User.findById(uuid, function(err,invite){
|
||||
if (err) return res.json(500,{err:err});
|
||||
if (!invite)
|
||||
return res.json(400,{err:'User with id '+req.query.uid+' not found'});
|
||||
if (group.type == 'guild') {
|
||||
if (_.contains(group.members,uuid))
|
||||
return res.json(400,{err: "User already in that group"});
|
||||
if (invite.invitations && invite.invitations.guilds && _.find(invite.invitations.guilds, {id:group._id}))
|
||||
return res.json(400, {err:"User already invited to that group"});
|
||||
sendInvite();
|
||||
} else if (group.type == 'party') {
|
||||
if (invite.invitations && invite.invitations.party)
|
||||
return res.json(400,{err:"User already pending invitation."});
|
||||
Group.find({type:'party', members:{$in:[uuid]}}, function(err, groups){
|
||||
if (err) return res.json(500,{err:err});
|
||||
if (!_.isEmpty(groups))
|
||||
return res.json(400,{err:"User already in a party."})
|
||||
sendInvite();
|
||||
})
|
||||
}
|
||||
|
||||
function sendInvite (){
|
||||
//req.body.type in 'guild', 'party'
|
||||
invite.invitations.party = {id:group._id, name: group.name}
|
||||
invite.save();
|
||||
res.json(group);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -63,6 +63,7 @@ router.get('/groups', auth, groups.getGroups);
|
|||
|
||||
router.post('/groups/:gid/join', auth, groups.attachGroup, groups.join);
|
||||
router.post('/groups/:gid/leave', auth, groups.attachGroup, groups.leave);
|
||||
router.post('/groups/:gid/invite', auth, groups.attachGroup, groups.invite);
|
||||
|
||||
//GET /groups/:gid/chat
|
||||
router.post('/groups/:gid/chat', auth, groups.attachGroup, groups.postChat);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,11 @@ a.pull-right.gem-wallet(rel='popover', data-trigger='hover', data-title='Guild B
|
|||
a(target='_blank', ng-href='{{website}}') {{website}}
|
||||
|
||||
accordion-group(heading='Members')
|
||||
form.form-inline(ng-submit='invite(group, invitee)')
|
||||
.alert.alert-danger(ng-show='_groupError') {{_groupError}}
|
||||
.control-group
|
||||
input.input-medium(type='text', placeholder='User Id', ng-model='invitee')
|
||||
input.btn(type='submit', value='Invite')
|
||||
table.table.table-striped
|
||||
tr(ng-repeat='member in group.members')
|
||||
td
|
||||
|
|
@ -56,13 +61,6 @@ a.pull-right.gem-wallet(rel='popover', data-trigger='hover', data-title='Guild B
|
|||
| {{username(member.auth, member.profile.name)}}
|
||||
td
|
||||
| ({{member._id}})
|
||||
// {#with group as :group}
|
||||
form.form-inline(x-bind='submit:groupInvite', data-type='{{group.type}}')
|
||||
.alert.alert-danger(ng-show='_groupError') {{_groupError}}
|
||||
.control-group
|
||||
input.input-medium(type='text', placeholder='User Id', value='{{_groupInvitee}}')
|
||||
input.btn(type='submit', value='Invite')
|
||||
// {/}
|
||||
|
||||
//-accordion-group(heading='Challenges')
|
||||
span.label
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
div(ng-controller='GroupsCtrl')
|
||||
h4.alert.alert-warning Coming Soon! (Presently Incomplete & Read-Only)
|
||||
|
||||
// FIXME note, due to https://github.com/angular-ui/bootstrap/issues/783 we can't use nested angular-bootstrap tabs
|
||||
// Subscribe to that ticket & change this when they fix
|
||||
|
|
@ -10,16 +9,16 @@ div(ng-controller='GroupsCtrl')
|
|||
li
|
||||
a(data-target='#groups-guilds', data-toggle='tab', ng-click='fetchGuilds()') Guilds
|
||||
|
||||
.tab-content
|
||||
.tab-content(ng-controller='PartyCtrl')
|
||||
#groups-party.tab-pane.active Party
|
||||
div(ng-show='group._id', ng-controller='PartyCtrl')
|
||||
div(ng-show='group._id')
|
||||
include ./group
|
||||
div(ng-hide='group._id')
|
||||
div(ng-show='user.invitations.party')
|
||||
// #with required for the accept/reject buttons
|
||||
// {#with _user.invitations.party as :party}
|
||||
h2 You're Invited To {{party.name}}
|
||||
a.btn.btn-success(data-type='party', x-bind='click:acceptInvitation') Accept
|
||||
h2 You're Invited To {{user.invitations.party.name}}
|
||||
a.btn.btn-success(data-type='party', ng-click='join(user.invitations.party)') Accept
|
||||
a.btn.btn-danger(x-bind='click:rejectInvitation') Reject
|
||||
// {/}
|
||||
div(ng-hide='user.invitations.party', ng-controller='PartyCtrl')
|
||||
|
|
@ -42,7 +41,7 @@ div(ng-controller='GroupsCtrl')
|
|||
.tab-pane.active#groups-public-guilds
|
||||
div(ng-repeat='invitation in user.invitations.guilds')
|
||||
h3 You're Invited To {{invitation.name}}
|
||||
a.btn.btn-success(data-type='guild', x-bind='click:acceptInvitation') Accept
|
||||
a.btn.btn-success(data-type='guild', ng-click='join(group)') Accept
|
||||
a.btn.btn-danger(x-bind='click:rejectInvitation') Reject
|
||||
// Public Groups
|
||||
table.table.table-striped
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
h4.alert.alert-warning Coming Soon! (Presently Incomplete & Read-Only)
|
||||
.row-fluid(ng-controller='TavernCtrl')
|
||||
.span4
|
||||
.tavern-pane
|
||||
|
|
|
|||
Loading…
Reference in a new issue