Skip to content

Commit

Permalink
Fixed issue with server name for XML feed; Refractored count users
Browse files Browse the repository at this point in the history
  • Loading branch information
nunof07 committed Sep 8, 2015
1 parent b4cf41f commit 0779a87
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion assets/javascripts/discourse/components/mumble-icon.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default Ember.Component.extend({

Discourse.ajax('/mumble/list.json')
.then(function (data) {
_this.set('server', data);
_this.set('server', Mumble.getServer(data));
});

Ember.run.later(this, function() {
Expand Down
42 changes: 23 additions & 19 deletions assets/javascripts/mumble.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
;(function (Mumble) {
Mumble.getServer = function (data) {
if (data) {
if (data.server) {
return data.server;
} else {
return data;
}
}

return {};
};

Mumble.getRootChannel = function (data) {
if (data) {
if (data.root) {
return data.root;
} else if (data.server && data.server.channel) {
return data.server.channel;
} else if (data.channel) {
return data.channel;
}
}

Expand Down Expand Up @@ -43,26 +55,18 @@
return [];
};

Mumble.countUsers = function (root, recursive) {
var count = 0;
Mumble.countUsers = function (channel, recursive) {
var count = 0,
users = Mumble.getUsers(channel);

count += users.length;

if (recursive) {
var iterate = function (channel) {
var users = Mumble.getUsers(channel),
channels = Mumble.getChannels(channel);

count += users.length;

for (var i = 0; i < channels.length; i +=1) {
iterate(channels[i]);
}
};

iterate(root);
} else {
var users = Mumble.getUsers(root);
var channels = Mumble.getChannels(channel);

count += users.length;
for (var i = 0; i < channels.length; i +=1) {
count += Mumble.countUsers(channels[i], true);
}
}

return count;
Expand Down
4 changes: 2 additions & 2 deletions plugin.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# name: mumble
# name: Mumble
# about: Displays channel and user information from a Mumble server
# version: 0.1.1
# version: 0.1.2
# authors: Nuno Freitas ([email protected])
# url: https://github.com/nunof07/discourse-mumble

Expand Down

0 comments on commit 0779a87

Please sign in to comment.