Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #665 from blueseason/fix_channel_leave
Browse files Browse the repository at this point in the history
fix user amount when call Channel.leave
  • Loading branch information
py8765 committed Dec 17, 2014
2 parents f387114 + c11033e commit 759f51f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/common/service/channelService.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,13 @@ Channel.prototype.leave = function(uid, sid) {
if(!uid || !sid) {
return false;
}
delete this.records[uid];
this.userAmount =this.userAmount-1;
var res = deleteFrom(uid, sid, this.groups[sid]);
if(res){
delete this.records[uid];
this.userAmount = this.userAmount-1;
}
if(this.userAmount<0) this.userAmount=0;//robust
removeFromStore(this.__channelService__, genKey(this.__channelService__, this.name), genValue(sid, uid));
var res = deleteFrom(uid, sid, this.groups[sid]);
if(this.groups[sid] && this.groups[sid].length === 0) {
delete this.groups[sid];
}
Expand Down Expand Up @@ -356,8 +358,8 @@ var add = function(uid, sid, groups) {
* delete element from array
*/
var deleteFrom = function(uid, sid, group) {
if(!group) {
return true;
if(!uid || !sid || !group) {
return false;
}

for(var i=0, l=group.length; i<l; i++) {
Expand Down

0 comments on commit 759f51f

Please sign in to comment.