╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2904 const entry = self.data.selectedThread() orelse return; 2905 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 2906 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 2907 const author = ((try self.session.authorize(self.data.identity, .write)) orelse return).author; 2908 self.data.mergePatch(self.session, allocator, author, entry.id, revision) catch |err| switch (err) { 2909 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 2910 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2911 try self.session.navigate(route); 2912 return; 2913 }, 2914 else => return err, 2915 }; 2916 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 2917 const route = listRoute(self.data.identity, merged, "", entry.id) orelse return; 2918 try self.session.navigate(route); 2919 } else unreachable, 2920 .remove => try self.submitRemove(allocator), 2921 } 2922 } 2923 2924 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 2925 const comment = self.data.comment_id.len != 0; 2926 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 2927 const id = evt.parseEventId(event_id) catch return; 2928 try self.removeEvent(allocator, if (comment) .comment else kind, id); 2929 } 2930 2931 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2932 if (comptime wasm) return; 2933 const actor = (try self.session.authorize(self.data.identity, .read)) orelse return; 2934 const author = actor.author; 2935 2936 if (comptime supports_drafts) { 2937 const selected = self.data.selectedThread() orelse return; 2938 if (event_kind == kind and entryDraft(selected.*)) { 2939 try Data.removeDraft(self.session, allocator, author, &id); 2940 const route = draftsRoute(self.data.identity) orelse return; 2941 try self.session.navigate(route); 2942 return; 2943 } 2944 } 2945 2946 const io = self.session.io orelse return; 2947 const src = self.data.repo_source orelse return; 2948 if (!try src.canModify(io, allocator, actor, event_kind, &id)) return; 2949 2950 switch (src.repo_kind) { 2951 inline else => |repo_kind| { 2952 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2953 defer any_repo.deinit(io, allocator); 2954 switch (any_repo) { 2955 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), 2956 } 2957 }, 2958 } 2959 2960 const id_hex = std.fmt.bytesToHex(id, .lower); 2961 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex, null) orelse return; 2962 try self.session.navigate(route); 2963 } 2964 2965 // return to the list. 2966 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 2967 root_focus.setFocus(self.listScroll(index).getFocus().id); 2968 } 2969 2970 // cross to the header tabs above the stack. 2971 fn focusHeader(self: *This, root_focus: *Focus) void { 2972 root_focus.setFocus(self.box.children.keys()[header_index]); 2973 } 2974 2975 pub fn clearGrid(self: *This) void { 2976 self.box.clearGrid(); 2977 } 2978 2979 pub fn getGrid(self: This) ?Grid { 2980 return self.box.getGrid(); 2981 } 2982 2983 pub fn getFocus(self: *This) *Focus { 2984 return self.box.getFocus(); 2985 } 2986 2987 // for the parent's "scroll up at the top jumps to the header" check: at the 2988 // top only while the header tabs hold focus, so up from the split 2989 // crosses into the tabs first. 2990 pub fn atTop(self: *This) bool { 2991 return self.headerActive(); 2992 } 2993 }; 2994 } 2995