(function () {
var current_channel = null, private_manager = null, channel_manager = null;
- var bottom_callback, no_bottom_callback;
- bottom_callback = no_bottom_callback = function () {
+ var bottom_callback;
+ function no_bottom_callback() {
bottom_callback = no_bottom_callback;
};
+ bottom_callback = no_bottom_callback;
function xhr(method, url, callback, data) {
- var cb = callback
- ? function () { callback(JSON.parse(this.responseText)); }
- : null;
return _.xhr(
method,
url,
- cb,
+ callback
+ ? function () { callback(JSON.parse(this.responseText)); }
+ : null,
function (msg) { add_msg(null, "xhr_error", msg); },
function (msg) { add_msg(null, "xhr_abort", msg); },
data,
}
}
- function ws_receive_msg(data) {
- var messages = _.dgEBCN0("messages");
- if (data.op === "INSERT") {
- stick_to_bottom(messages);
+ var ws_receive_msg = {
+ INSERT: function (data) {
+ stick_to_bottom(_.dgEBCN0("messages"));
xhr(
"get",
current_channel.msg_url + data.obj.id + "/",
bottom_callback();
}
);
- } else if (data.op === "UPDATE") {
+ },
+ UPDATE: function (data) {
+ var messages = _.dgEBCN0("messages");
stick_to_bottom(messages);
find_existing_msg(
data.obj.id,
"get",
current_channel.msg_url + get_data_id(tag).toString() + "/",
function (msg) {
- set_msg(
- tag, msg[current_channel.msg_user_field], msg.text
- );
+ set_msg(tag, msg[current_channel.msg_user_field], msg.text);
bottom_callback();
}
);
},
);
- } else if (data.op === "DELETE") {
+ },
+ DELETE: function (data) {
find_existing_msg(
data.obj.id, function (tag) { tag.parentElement.removeChild(tag); }
);
- } else if (data.op === "TRUNCATE") {
- _.clear_children(messages);
- }
- }
+ },
+ TRUNCATE: function (data) {
+ _.clear_children(_.dgEBCN0("messages"));
+ },
+ };
function ws_receive(msg) {
var data = JSON.parse(msg.data);
private_manager.items_reload();
}
if (current_channel !== null && current_channel.match_channel(data)) {
- ws_receive_msg(data);
+ ws_receive_msg[data.op](data);
}
}