╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2689 const route = listRoute(self.data.identity, @enumFromInt(0), "", entry.id) orelse return; 2690 try self.session.navigate(route); 2691 } else unreachable, 2692 .merge => if (comptime supports_merge) { 2693 if (comptime wasm) return; 2694 const entry = self.data.selectedThread() orelse return; 2695 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 2696 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 2697 const author = ((try self.session.authorize(self.data.identity, .write)) orelse return).author; 2698 self.data.mergePatch(self.session, allocator, author, entry.id, revision) catch |err| switch (err) { 2699 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 2700 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2701 try self.session.navigate(route); 2702 return; 2703 }, 2704 else => return err, 2705 }; 2706 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 2707 const route = listRoute(self.data.identity, merged, "", entry.id) orelse return; 2708 try self.session.navigate(route); 2709 } else unreachable, 2710 .remove => try self.submitRemove(allocator), 2711 } 2712 } 2713 2714 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 2715 const comment = self.data.comment_id.len != 0; 2716 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 2717 const id = evt.parseEventId(event_id) catch return; 2718 try self.removeEvent(allocator, if (comment) .comment else kind, id); 2719 } 2720 2721 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2722 if (comptime wasm) return; 2723 const actor = (try self.session.authorize(self.data.identity, .read)) orelse return; 2724 const author = actor.author; 2725 2726 if (comptime supports_drafts) { 2727 const selected = self.data.selectedThread() orelse return; 2728 if (event_kind == kind and entryDraft(selected.*)) { 2729 try Data.removeDraft(self.session, allocator, author, &id); 2730 const route = draftsRoute(self.data.identity) orelse return; 2731 try self.session.navigate(route); 2732 return; 2733 } 2734 } 2735 2736 const io = self.session.io orelse return; 2737 const src = self.data.repo_source orelse return; 2738 if (!try src.canModify(io, allocator, actor, event_kind, &id)) return; 2739 2740 switch (src.repo_kind) { 2741 inline else => |repo_kind| { 2742 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2743 defer any_repo.deinit(io, allocator); 2744 switch (any_repo) { 2745 inline else => |*repo| try evt.remove(self.session.data.host_kind, .repo, repo_kind, repo.self_repo_opts, io, allocator, repo, &id, event_kind, author), 2746 } 2747 }, 2748 } 2749 2750 const id_hex = std.fmt.bytesToHex(id, .lower); 2751 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex) orelse return; 2752 try self.session.navigate(route); 2753 } 2754 2755 // return to the list. 2756 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 2757 root_focus.setFocus(self.listScroll(index).getFocus().id); 2758 } 2759 2760 // cross to the header tabs above the stack. 2761 fn focusHeader(self: *This, root_focus: *Focus) void { 2762 root_focus.setFocus(self.box.children.keys()[header_index]); 2763 } 2764 2765 pub fn clearGrid(self: *This) void { 2766 self.box.clearGrid(); 2767 } 2768 2769 pub fn getGrid(self: This) ?Grid { 2770 return self.box.getGrid(); 2771 } 2772 2773 pub fn getFocus(self: *This) *Focus { 2774 return self.box.getFocus(); 2775 } 2776 2777 // for the parent's "scroll up at the top jumps to the header" check: at the 2778 // top only while the header tabs hold focus, so up from the split 2779 // crosses into the tabs first. 2780 pub fn atTop(self: *This) bool { 2781 return self.headerActive(); 2782 } 2783 }; 2784 } 2785