2013-08-29 02:08:59 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Services that persists and retrieves user from localStorage.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
angular.module('groupServices', ['ngResource']).
|
2013-11-02 03:15:04 +00:00
|
|
|
factory('Groups', ['API_URL', '$resource', '$q',
|
|
|
|
|
function(API_URL, $resource, $q) {
|
2013-08-29 02:08:59 +00:00
|
|
|
var Group = $resource(API_URL + '/api/v1/groups/:gid',
|
2013-09-08 15:22:03 +00:00
|
|
|
{gid:'@_id', messageId: '@_messageId'},
|
2013-08-31 23:14:58 +00:00
|
|
|
{
|
2013-10-30 21:34:59 +00:00
|
|
|
//query: {method: "GET", isArray:false},
|
2013-09-01 02:59:35 +00:00
|
|
|
postChat: {method: "POST", url: API_URL + '/api/v1/groups/:gid/chat'},
|
2013-09-08 15:22:03 +00:00
|
|
|
deleteChatMessage: {method: "DELETE", url: API_URL + '/api/v1/groups/:gid/chat/:messageId'},
|
2013-09-01 02:59:35 +00:00
|
|
|
join: {method: "POST", url: API_URL + '/api/v1/groups/:gid/join'},
|
2013-09-01 15:33:39 +00:00
|
|
|
leave: {method: "POST", url: API_URL + '/api/v1/groups/:gid/leave'},
|
2013-10-28 16:10:29 +00:00
|
|
|
invite: {method: "POST", url: API_URL + '/api/v1/groups/:gid/invite'},
|
|
|
|
|
removeMember: {method: "POST", url: API_URL + '/api/v1/groups/:gid/removeMember'}
|
2013-08-31 23:14:58 +00:00
|
|
|
});
|
|
|
|
|
|
2013-11-02 03:15:04 +00:00
|
|
|
// Defer loading everything until they're requested
|
|
|
|
|
var party, myGuilds, publicGuilds, tavern;
|
2013-09-02 02:08:01 +00:00
|
|
|
|
|
|
|
|
// But we don't defer triggering Party, since we always need it for the header if nothing else
|
2013-11-02 03:15:04 +00:00
|
|
|
party = Group.get({gid: 'party'});
|
2013-09-02 02:08:01 +00:00
|
|
|
|
|
|
|
|
return {
|
2013-11-02 03:15:04 +00:00
|
|
|
party: function(){
|
|
|
|
|
return party;
|
|
|
|
|
},
|
|
|
|
|
publicGuilds: function(){
|
2013-10-30 22:14:08 +00:00
|
|
|
//TODO combine these as {type:'guilds,public'} and create a $filter() to separate them
|
2013-11-02 03:15:04 +00:00
|
|
|
if (!publicGuilds) publicGuilds = Group.query({type:'public'});
|
|
|
|
|
return publicGuilds;
|
|
|
|
|
},
|
|
|
|
|
myGuilds: function(){
|
|
|
|
|
if (!myGuilds) myGuilds = Group.query({type:'guilds'});
|
|
|
|
|
return myGuilds;
|
|
|
|
|
},
|
|
|
|
|
tavern: function(){
|
|
|
|
|
if (!tavern) tavern = Group.get({gid:'habitrpg'});
|
|
|
|
|
return tavern;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Group: Group
|
2013-09-02 02:08:01 +00:00
|
|
|
}
|
2013-08-29 02:08:59 +00:00
|
|
|
}
|
|
|
|
|
]);
|