an experimental irc client

irc: respect server chathistory limit

rockorager.dev c822adff b6a77117

verified
Changed files
+12 -6
src
+12 -6
src/irc.zig
··· 1745 1745 pub const ISupport = struct { 1746 1746 whox: bool = false, 1747 1747 prefix: []const u8 = "", 1748 + chathistory: ?u16 = null, 1748 1749 }; 1749 1750 1750 1751 pub const Status = enum(u8) { ··· 2258 2259 break :blk try self.alloc.dupe(u8, token[idx + 1 ..]); 2259 2260 }; 2260 2261 client.supports.prefix = prefix; 2262 + } else if (mem.startsWith(u8, token, "CHATHISTORY")) { 2263 + const idx = mem.indexOfScalar(u8, token, '=') orelse continue; 2264 + const limit_str = token[idx + 1 ..]; 2265 + client.supports.chathistory = std.fmt.parseUnsigned(u16, limit_str, 10) catch 50; 2261 2266 } 2262 2267 } 2263 2268 }, ··· 2940 2945 ) Allocator.Error!void { 2941 2946 if (!self.caps.@"draft/chathistory") return; 2942 2947 if (channel.history_requested) return; 2948 + const max = self.supports.chathistory orelse return; 2943 2949 2944 2950 channel.history_requested = true; 2945 2951 2946 2952 if (channel.messages.items.len == 0) { 2947 2953 try self.print( 2948 - "CHATHISTORY LATEST {s} * 50\r\n", 2949 - .{channel.name}, 2954 + "CHATHISTORY LATEST {s} * {d}\r\n", 2955 + .{ channel.name, @min(50, max) }, 2950 2956 ); 2951 2957 channel.history_requested = true; 2952 2958 return; ··· 2961 2967 return; 2962 2968 }; 2963 2969 try self.print( 2964 - "CHATHISTORY BEFORE {s} timestamp={s} 50\r\n", 2965 - .{ channel.name, time }, 2970 + "CHATHISTORY BEFORE {s} timestamp={s} {d}\r\n", 2971 + .{ channel.name, time, @min(50, max) }, 2966 2972 ); 2967 2973 channel.history_requested = true; 2968 2974 }, ··· 2976 2982 try self.print( 2977 2983 // we request 500 because we have no 2978 2984 // idea how long we've been offline 2979 - "CHATHISTORY AFTER {s} timestamp={s} 500\r\n", 2980 - .{ channel.name, time }, 2985 + "CHATHISTORY AFTER {s} timestamp={s} {d}\r\n", 2986 + .{ channel.name, time, @min(50, max) }, 2981 2987 ); 2982 2988 channel.history_requested = true; 2983 2989 },