Fix the 'Show More' button

This commit is contained in:
Mattias Erming 2014-09-10 12:23:56 -07:00
parent 37b68b7bc4
commit 05a51f74a7
5 changed files with 33 additions and 28 deletions

File diff suppressed because one or more lines are too long

View File

@ -152,15 +152,18 @@ $(function() {
]);
});
socket.on("showMore", function(data) {
socket.on("more", function(data) {
var target = data.chan;
chat.find("#chan-" + target)
.find(".show-more")
.remove()
.end()
var chan = chat
.find("#chan-" + target)
.find(".messages")
.prepend(render("msg", {messages: data.messages}))
.end();
if (data.messages.length != 100) {
var more = chan
.find(".show-more")
.remove();
}
});
socket.on("network", function(data) {
@ -412,7 +415,7 @@ $(function() {
var self = $(this);
var id = self.data("id");
var count = self.next(".messages").children().length;
socket.emit("showMore", {
socket.emit("more", {
target: id,
count: count
});

View File

@ -1,7 +1,7 @@
{
"name": "shout",
"description": "A web IRC client",
"version": "0.21.3",
"version": "0.21.4",
"author": "Mattias Erming",
"preferGlobal": true,
"bin": {

View File

@ -193,6 +193,21 @@ Client.prototype.input = function(data) {
});
}
Client.prototype.more = function(data) {
var client = this;
var target = client.find(data.target);
if (!target) {
return;
}
var chan = target.chan;
var count = chan.messages.length - (data.count || 0);
var messages = chan.messages.slice(Math.max(0, count - 100), count);
client.emit("more", {
chan: chan.id,
messages: messages
});
}
Client.prototype.quit = function() {
this.networks.forEach(function(network) {
var irc = network.irc;

View File

@ -65,9 +65,9 @@ function init(socket, client) {
}
);
socket.on(
"showMore",
"more",
function(data) {
showMore(client, data);
client.more(data);
}
);
socket.on(
@ -106,16 +106,3 @@ function auth(data) {
}
}
}
function showMore(client, data) {
var target = client.find(data.target);
if (!target) {
return;
}
var chan = target.chan;
var messages = chan.messages.slice(0, chan.messages.length - (data.count || 0));
client.emit("showMore", {
chan: chan.id,
messages: messages
});
}