╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
3289 3290 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 3291 const attachment_id = self.session.data.current_page.threadAttachment(); 3292 if (attachment_id.len != 0) return self.removeEvent(allocator, .attach, evt.parseEventId(attachment_id) catch return); 3293 const comment = self.data.comment_id.len != 0; 3294 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 3295 const id = evt.parseEventId(event_id) catch return; 3296 try self.removeEvent(allocator, if (comment) .comment else kind, id); 3297 } 3298 3299 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 3300 if (comptime wasm) return; 3301 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3302 const author = actor.author; 3303 3304 if (comptime supports_drafts) { 3305 const selected = self.data.selectedThread() orelse return; 3306 if (event_kind == kind and entryDraft(selected.*)) { 3307 try Data.removeDraft(self.session, allocator, author, &id); 3308 const route = draftsRoute(self.data.identity) orelse return; 3309 try self.session.navigate(route); 3310 return; 3311 } 3312 } 3313 3314 const io = self.session.io orelse return; 3315 const src = self.data.repo_source orelse return; 3316 if (!try src.canModify(io, allocator, actor, event_kind, &id)) return; 3317 const thread_id = evt.parseEventId(self.data.selected_id) catch return; 3318 3319 switch (src.repo_kind) { 3320 inline else => |repo_kind| { 3321 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3322 defer any_repo.deinit(io, allocator); 3323 switch (any_repo) { 3324 inline else => |*repo| try evt.removeInThread(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, kind, &thread_id, event_kind, &id, author), 3325 } 3326 }, 3327 } 3328 3329 // back to the thread, or to its list when the thread itself was removed 3330 const selected = self.data.selectedThread() orelse return; 3331 const route = listRoute(self.data.identity, entryStatus(selected.*), if (event_kind == kind) "" else self.data.selected_id) orelse return; 3332 try self.session.navigate(route); 3333 } 3334 3335 // enter the detail pane, landing on the way back to the list when it shows 3336 fn focusDetail(self: *This, index: usize, root_focus: *Focus) void { 3337 if (widget.listBackId(self.detailFrame(index)) != null) return widget.focusListBack(self.detailFrame(index), root_focus); 3338 _ = self.detail(index).focusFirst(root_focus); 3339 } 3340 3341 // return to the list. 3342 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 3343 root_focus.setFocus(self.listScroll(index).getFocus().id); 3344 } 3345 3346 // cross to the header tabs above the stack. 3347 fn focusHeader(self: *This, root_focus: *Focus) void { 3348 root_focus.setFocus(self.box.children.keys()[header_index]); 3349 } 3350 3351 pub fn clearGrid(self: *This) void { 3352 self.box.clearGrid(); 3353 } 3354 3355 pub fn getGrid(self: This) ?Grid { 3356 return self.box.getGrid(); 3357 } 3358 3359 pub fn getFocus(self: *This) *Focus { 3360 return self.box.getFocus(); 3361 } 3362 3363 // for the parent's "scroll up at the top jumps to the header" check: at the 3364 // top only while the header tabs hold focus, so up from the split 3365 // crosses into the tabs first. 3366 pub fn atTop(self: *This) bool { 3367 return self.headerActive(); 3368 } 3369 }; 3370 } 3371