tangled
alpha
login
or
join now
rockorager.dev
/
comlink
2
fork
atom
an experimental irc client
2
fork
atom
overview
issues
pulls
pipelines
irc: request history when needed
rockorager.dev
1 year ago
ec2fb6ec
81555bd7
+33
-21
1 changed file
expand all
collapse all
unified
split
src
irc.zig
+33
-21
src/irc.zig
···
900
}
901
}
902
0
0
0
0
0
903
return .{
904
.size = max,
905
.widget = self.messageViewWidget(),
···
1786
// from the batch start. We also never notify from a
1787
// batched message. Batched messages also require
1788
// sorting
1789
-
var tag_iter = msg2.tagIterator();
1790
-
while (tag_iter.next()) |tag| {
1791
-
if (mem.eql(u8, tag.key, "batch")) {
1792
-
const entry = client.batches.getEntry(tag.value) orelse @panic("TODO");
1793
-
var channel = entry.value_ptr.*;
1794
-
try channel.messages.append(msg2);
1795
-
std.sort.insertion(Message, channel.messages.items, {}, Message.compareTime);
1796
-
channel.at_oldest = false;
1797
-
const time = msg2.time() orelse continue;
1798
-
if (time.unixTimestamp() > channel.last_read) {
1799
-
channel.has_unread = true;
1800
-
const content = iter.next() orelse continue;
1801
-
if (std.mem.indexOf(u8, content, client.nickname())) |_| {
1802
-
channel.has_unread_highlight = true;
1803
-
}
1804
}
1805
-
break;
1806
}
1807
} else {
1808
// standard handling
···
2099
}
2100
2101
/// fetch the history for the provided channel.
2102
-
pub fn requestHistory(self: *Client, cmd: ChatHistoryCommand, channel: *Channel) !void {
0
0
0
0
2103
if (!self.caps.@"draft/chathistory") return;
2104
if (channel.history_requested) return;
2105
···
2118
.before => {
2119
assert(channel.messages.items.len > 0);
2120
const first = channel.messages.items[0];
2121
-
const time = first.getTag("time") orelse
2122
-
return error.NoTimeTag;
0
0
2123
try self.print(
2124
"CHATHISTORY BEFORE {s} timestamp={s} 50\r\n",
2125
.{ channel.name, time },
···
2129
.after => {
2130
assert(channel.messages.items.len > 0);
2131
const last = channel.messages.getLast();
2132
-
const time = last.getTag("time") orelse
2133
-
return error.NoTimeTag;
0
0
2134
try self.print(
2135
// we request 500 because we have no
2136
// idea how long we've been offline
···
900
}
901
}
902
903
+
// Request more history when we are within 5 messages of the top of the screen
904
+
if (iter.index < 5 and !self.at_oldest) {
905
+
try self.client.requestHistory(.before, self);
906
+
}
907
+
908
return .{
909
.size = max,
910
.widget = self.messageViewWidget(),
···
1791
// from the batch start. We also never notify from a
1792
// batched message. Batched messages also require
1793
// sorting
1794
+
if (msg2.getTag("batch")) |tag| {
1795
+
const entry = client.batches.getEntry(tag) orelse @panic("TODO");
1796
+
var channel = entry.value_ptr.*;
1797
+
try channel.messages.append(msg2);
1798
+
std.sort.insertion(Message, channel.messages.items, {}, Message.compareTime);
1799
+
if (channel.scroll.msg_offset) |offset| {
1800
+
channel.scroll.msg_offset = offset + 1;
1801
+
}
1802
+
channel.at_oldest = false;
1803
+
const time = msg2.time() orelse return;
1804
+
if (time.unixTimestamp() > channel.last_read) {
1805
+
channel.has_unread = true;
1806
+
const content = iter.next() orelse return;
1807
+
if (std.mem.indexOf(u8, content, client.nickname())) |_| {
1808
+
channel.has_unread_highlight = true;
1809
}
0
1810
}
1811
} else {
1812
// standard handling
···
2103
}
2104
2105
/// fetch the history for the provided channel.
2106
+
pub fn requestHistory(
2107
+
self: *Client,
2108
+
cmd: ChatHistoryCommand,
2109
+
channel: *Channel,
2110
+
) Allocator.Error!void {
2111
if (!self.caps.@"draft/chathistory") return;
2112
if (channel.history_requested) return;
2113
···
2126
.before => {
2127
assert(channel.messages.items.len > 0);
2128
const first = channel.messages.items[0];
2129
+
const time = first.getTag("time") orelse {
2130
+
log.warn("can't request history: no time tag", .{});
2131
+
return;
2132
+
};
2133
try self.print(
2134
"CHATHISTORY BEFORE {s} timestamp={s} 50\r\n",
2135
.{ channel.name, time },
···
2139
.after => {
2140
assert(channel.messages.items.len > 0);
2141
const last = channel.messages.getLast();
2142
+
const time = last.getTag("time") orelse {
2143
+
log.warn("can't request history: no time tag", .{});
2144
+
return;
2145
+
};
2146
try self.print(
2147
// we request 500 because we have no
2148
// idea how long we've been offline