From ef9aecf5317597e65afde99c0c89c9b1b211cf67 Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Sun, 6 Sep 2015 20:08:31 +0200 Subject: [PATCH] disable firebase syncing for tavern --- migrations/20150906_groups_fix_leaders.js | 2 +- migrations/20150906_groups_remove_deleted_users.js | 2 +- migrations/20150906_sync_groups_with_firebase.js | 1 + website/src/libs/firebase.js | 7 ++++++- website/src/models/group.js | 9 +++++---- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/migrations/20150906_groups_fix_leaders.js b/migrations/20150906_groups_fix_leaders.js index 988a630955..f167e0b2fa 100644 --- a/migrations/20150906_groups_fix_leaders.js +++ b/migrations/20150906_groups_fix_leaders.js @@ -29,7 +29,7 @@ dbGroups.findEach({}, {_id: 1, members: 1, leader: 1}, {batchSize: 500}, functio if(err) throw err; // If leader has deleted account - if(count < 1) { + if(count < 1 && (group._id !== 'habitrpg')) { dbGroups.update({ _id: group._id }, { diff --git a/migrations/20150906_groups_remove_deleted_users.js b/migrations/20150906_groups_remove_deleted_users.js index 2644ade895..f156e1b362 100644 --- a/migrations/20150906_groups_remove_deleted_users.js +++ b/migrations/20150906_groups_remove_deleted_users.js @@ -29,7 +29,7 @@ dbGroups.findEach({}, {_id: 1, members: 1}, {batchSize: 500}, function(err, grou dbUsers.count({_id: member}, function(err, count){ if(err) throw err; - if(count < 1) { + if(count < 1 && (group._id !== 'habitrpg')) { countUsers++; console.log('User: ', countUsers); diff --git a/migrations/20150906_sync_groups_with_firebase.js b/migrations/20150906_sync_groups_with_firebase.js index 47bf1a9ce8..d7b4f12174 100644 --- a/migrations/20150906_sync_groups_with_firebase.js +++ b/migrations/20150906_sync_groups_with_firebase.js @@ -22,6 +22,7 @@ firebaseRef.authWithCustomToken('firebase-secret', function(err, authData){ dbGroups.findEach({}, {_id: 1, members: 1}, {batchSize: 100}, function(err, group){ if(err) throw err; + if(group._id !== 'habitrpg') return; countGroups++; console.log('Group: ', countGroups); diff --git a/website/src/libs/firebase.js b/website/src/libs/firebase.js index 52dab3f482..ecd6f4cb31 100644 --- a/website/src/libs/firebase.js +++ b/website/src/libs/firebase.js @@ -19,6 +19,8 @@ var api = module.exports = {}; api.updateGroupData = function(group){ if(!isProd) return; 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) .set({ @@ -30,6 +32,7 @@ api.addUserToGroup = function(groupId, userId){ if(!isProd) return; // TODO is throw ok? we don't have callbacks if(!userId || !groupId) throw new Error('groupId, userId are required.'); + if(groupId === 'habitrpg') return; firebaseRef.child('members/' + groupId + '/' + userId) .set(true); @@ -41,6 +44,7 @@ api.addUserToGroup = function(groupId, userId){ api.removeUserFromGroup = function(groupId, userId){ if(!isProd) return; if(!userId || !groupId) throw new Error('groupId, userId are required.'); + if(groupId === 'habitrpg') return; firebaseRef.child('members/' + groupId + '/' + userId) .remove(); @@ -51,7 +55,8 @@ api.removeUserFromGroup = function(groupId, userId){ api.deleteGroup = function(groupId){ 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) .remove(); diff --git a/website/src/models/group.js b/website/src/models/group.js index c89f83b2b4..2a246357c8 100644 --- a/website/src/models/group.js +++ b/website/src/models/group.js @@ -444,7 +444,7 @@ GroupSchema.methods.leave = function(user, keep, mainCb){ } update['$inc'] = {memberCount: -1}; - Group.update({_id:group._id}, update, cb); + Group.update({_id: group._id}, update, cb); } } ], function(err){ @@ -473,14 +473,15 @@ module.exports.schema = GroupSchema; var Group = module.exports.model = mongoose.model("Group", GroupSchema); // initialize tavern if !exists (fresh installs) -Group.count({_id:'habitrpg'},function(err,ct){ +Group.count({_id: 'habitrpg'}, function(err, ct){ if (ct > 0) return; + new Group({ _id: 'habitrpg', chat: [], leader: '9', name: 'HabitRPG', type: 'guild', - privacy:'public' + privacy: 'public' }).save(); -}); +}); \ No newline at end of file