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

View file

@ -1,7 +1,7 @@
{ {
"name": "shout", "name": "shout",
"description": "A web IRC client", "description": "A web IRC client",
"version": "0.21.3", "version": "0.21.4",
"author": "Mattias Erming", "author": "Mattias Erming",
"preferGlobal": true, "preferGlobal": true,
"bin": { "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() { Client.prototype.quit = function() {
this.networks.forEach(function(network) { this.networks.forEach(function(network) {
var irc = network.irc; var irc = network.irc;

View file

@ -65,9 +65,9 @@ function init(socket, client) {
} }
); );
socket.on( socket.on(
"showMore", "more",
function(data) { function(data) {
showMore(client, data); client.more(data);
} }
); );
socket.on( 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
});
}