Permalink
Browse files

stores the channels operator list client side (wip)

  • Loading branch information...
1 parent 1339d4e commit 9eede9a12c3f83b8ecabf693af4b2021b931ca9c @kerphi committed Jan 9, 2013
@@ -0,0 +1,30 @@
+/*jslint node: true, maxlen: 150, maxerr: 50, indent: 2 */
+'use strict';
+
+/**
+ * phpfreechat's channel related functions
+ */
+var phpFreeChat = (function (pfc, $, window, undefined) {
+
+// pfc.channels = {};
+
+// /**
+// * Returns the channel name of the given channel id
+// */
+// pfc.getChannelFromCid = function (cid) {
+// return pfc.channels[cid];
+// };
+//
+// /**
+// * Returns the channel id of the given channel name
+// */
+// pfc.getCidFromChannel = function (channel) {
+// $.each(pfc.channels, function (cid, chan) {
+// if (channel == chan) {
+// return cid;
+// }
+// });
+// };
+
+ return pfc;
+}(phpFreeChat || {}, jQuery, window));
@@ -61,15 +61,23 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
type: pfc.options.use_post_wrapper ? 'POST' : 'PUT',
url: pfc.options.serverUrl + '/channels/' + cid + '/users/' + pfc.uid,
data: pfc.options.use_post_wrapper ? { _METHOD: 'PUT' } : null
- }).done(function (users) {
+ }).done(function (cinfo) {
+
+ pfc.channels[cid] = {
+ users: [],
+ op: []
+ };
// store userdata in the cache
// refresh the interface
pfc.clearUserList();
- $.each(users, function (uid) {
- pfc.users[uid] = users[uid];
- pfc.appendUser(users[uid]);
+ $.each(cinfo.users, function (uid) {
+ pfc.channels[cid].users.push(uid);
+ pfc.users[uid] = cinfo.users[uid];
+ pfc.appendUser(cinfo.users[uid]);
});
+ // store channel operators
+ pfc.channels[cid].op = cinfo.op;
// display a join message for him
pfc.appendMessage({
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -22,6 +22,7 @@
<script src="../client/jquery.phpfreechat.core.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.auth.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.commands.js" type="text/javascript"></script>
+ <script src="../client/jquery.phpfreechat.channels.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.utils.js" type="text/javascript"></script>
<!-- /pfc-debug -->
@@ -22,6 +22,7 @@
<script src="../client/jquery.phpfreechat.core.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.auth.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.commands.js" type="text/javascript"></script>
+ <script src="../client/jquery.phpfreechat.channels.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.utils.js" type="text/javascript"></script>
<!-- /pfc-debug -->
@@ -22,6 +22,7 @@
<script src="../client/jquery.phpfreechat.core.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.auth.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.commands.js" type="text/javascript"></script>
+ <script src="../client/jquery.phpfreechat.channels.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.utils.js" type="text/javascript"></script>
<!-- /pfc-debug -->
@@ -22,6 +22,7 @@
<script src="../client/jquery.phpfreechat.core.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.auth.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.commands.js" type="text/javascript"></script>
+ <script src="../client/jquery.phpfreechat.channels.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.utils.js" type="text/javascript"></script>
<!-- /pfc-debug -->
@@ -22,6 +22,7 @@
<script src="../client/jquery.phpfreechat.core.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.auth.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.commands.js" type="text/javascript"></script>
+ <script src="../client/jquery.phpfreechat.channels.js" type="text/javascript"></script>
<script src="../client/jquery.phpfreechat.utils.js" type="text/javascript"></script>
<!-- /pfc-debug -->
@@ -50,7 +50,6 @@ static public function getChannelUsers($cid, $withudata = false) {
if ($uid === '.' || $uid === '..') continue;
if ($withudata) {
$subscribers[$uid] = Container_users::getUserData($uid);
- $subscribers[$uid]->op = Container_channels_op::isOp($cid, $uid);
} else {
$subscribers[] = $uid;
}
@@ -75,7 +75,10 @@
$res->status(201); // User joined the channel
$res['Content-Type'] = 'application/json; charset=utf-8';
- $res->body(json_encode(Container_channels::getChannelUsers($cid, true)));
+ $res->body(json_encode(array(
+ 'users' => Container_channels::getChannelUsers($cid, true),
+ 'op' => Container_channels_op::getOpList($cid),
+ )));
return;
}
View
@@ -49,7 +49,7 @@ vows.describe('Channels route').addBatch({
'server returns the user list': function (error, res, body) {
var userlist = {};
try {
- userlist = JSON.parse(body);
+ userlist = JSON.parse(body).users;
} catch (err) {
assert.isNull(err, 'response body should be JSON formated');
}
@@ -87,7 +87,7 @@ vows.describe('Channels route').addBatch({
'server returns the user list': function (error, res, body) {
var userlist = {};
try {
- userlist = JSON.parse(body);
+ userlist = JSON.parse(body).users;
} catch (err) {
assert.isNull(err, 'response body should be JSON formated');
}
@@ -99,7 +99,7 @@ vows.describe('Channels route').addBatch({
'the user list contains full userdata': function (error, res, body) {
var userlist;
try {
- userlist = JSON.parse(body);
+ userlist = JSON.parse(body).users;
} catch (err) {
assert.isNull(err, 'response body should be JSON formated');
}

0 comments on commit 9eede9a

Please sign in to comment.