disable firebase syncing for tavern

This commit is contained in:
Matteo Pagliazzi
2015-09-06 20:08:31 +02:00
parent 6e2b3a805e
commit ef9aecf531
5 changed files with 14 additions and 7 deletions

View File

@@ -29,7 +29,7 @@ dbGroups.findEach({}, {_id: 1, members: 1, leader: 1}, {batchSize: 500}, functio
if(err) throw err; if(err) throw err;
// If leader has deleted account // If leader has deleted account
if(count < 1) { if(count < 1 && (group._id !== 'habitrpg')) {
dbGroups.update({ dbGroups.update({
_id: group._id _id: group._id
}, { }, {

View File

@@ -29,7 +29,7 @@ dbGroups.findEach({}, {_id: 1, members: 1}, {batchSize: 500}, function(err, grou
dbUsers.count({_id: member}, function(err, count){ dbUsers.count({_id: member}, function(err, count){
if(err) throw err; if(err) throw err;
if(count < 1) { if(count < 1 && (group._id !== 'habitrpg')) {
countUsers++; countUsers++;
console.log('User: ', countUsers); console.log('User: ', countUsers);

View File

@@ -22,6 +22,7 @@ firebaseRef.authWithCustomToken('firebase-secret', function(err, authData){
dbGroups.findEach({}, {_id: 1, members: 1}, {batchSize: 100}, function(err, group){ dbGroups.findEach({}, {_id: 1, members: 1}, {batchSize: 100}, function(err, group){
if(err) throw err; if(err) throw err;
if(group._id !== 'habitrpg') return;
countGroups++; countGroups++;
console.log('Group: ', countGroups); console.log('Group: ', countGroups);

View File

@@ -19,6 +19,8 @@ var api = module.exports = {};
api.updateGroupData = function(group){ api.updateGroupData = function(group){
if(!isProd) return; if(!isProd) return;
if(!group) throw new Error('group is required.'); if(!group) throw new Error('group is required.');
// Return in case of tavern (comparison working because we use string for _id)
if(group._id === 'habitrpg') return;
firebaseRef.child('rooms/' + group._id) firebaseRef.child('rooms/' + group._id)
.set({ .set({
@@ -30,6 +32,7 @@ api.addUserToGroup = function(groupId, userId){
if(!isProd) return; if(!isProd) return;
// TODO is throw ok? we don't have callbacks // TODO is throw ok? we don't have callbacks
if(!userId || !groupId) throw new Error('groupId, userId are required.'); if(!userId || !groupId) throw new Error('groupId, userId are required.');
if(groupId === 'habitrpg') return;
firebaseRef.child('members/' + groupId + '/' + userId) firebaseRef.child('members/' + groupId + '/' + userId)
.set(true); .set(true);
@@ -41,6 +44,7 @@ api.addUserToGroup = function(groupId, userId){
api.removeUserFromGroup = function(groupId, userId){ api.removeUserFromGroup = function(groupId, userId){
if(!isProd) return; if(!isProd) return;
if(!userId || !groupId) throw new Error('groupId, userId are required.'); if(!userId || !groupId) throw new Error('groupId, userId are required.');
if(groupId === 'habitrpg') return;
firebaseRef.child('members/' + groupId + '/' + userId) firebaseRef.child('members/' + groupId + '/' + userId)
.remove(); .remove();
@@ -51,7 +55,8 @@ api.removeUserFromGroup = function(groupId, userId){
api.deleteGroup = function(groupId){ api.deleteGroup = function(groupId){
if(!isProd) return; if(!isProd) return;
if(!groupId) throw new Error('groupId is required.');7 if(!groupId) throw new Error('groupId is required.');
if(groupId === 'habitrpg') return;
firebaseRef.child('rooms/' + groupId) firebaseRef.child('rooms/' + groupId)
.remove(); .remove();

View File

@@ -444,7 +444,7 @@ GroupSchema.methods.leave = function(user, keep, mainCb){
} }
update['$inc'] = {memberCount: -1}; update['$inc'] = {memberCount: -1};
Group.update({_id:group._id}, update, cb); Group.update({_id: group._id}, update, cb);
} }
} }
], function(err){ ], function(err){
@@ -473,14 +473,15 @@ module.exports.schema = GroupSchema;
var Group = module.exports.model = mongoose.model("Group", GroupSchema); var Group = module.exports.model = mongoose.model("Group", GroupSchema);
// initialize tavern if !exists (fresh installs) // initialize tavern if !exists (fresh installs)
Group.count({_id:'habitrpg'},function(err,ct){ Group.count({_id: 'habitrpg'}, function(err, ct){
if (ct > 0) return; if (ct > 0) return;
new Group({ new Group({
_id: 'habitrpg', _id: 'habitrpg',
chat: [], chat: [],
leader: '9', leader: '9',
name: 'HabitRPG', name: 'HabitRPG',
type: 'guild', type: 'guild',
privacy:'public' privacy: 'public'
}).save(); }).save();
}); });