╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
3121 }); 3122 } 3123 3124 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 3125 switch (confirmation(self.data.view) orelse return) { 3126 .publish => if (comptime supports_drafts) { 3127 if (comptime wasm) return; 3128 const entry = self.data.selectedThread() orelse return; 3129 if (!entryDraft(entry.*)) return; 3130 const author = ((try self.session.authorize(self.data.identity, .read, kind)) orelse return).author; 3131 try self.data.publishDraft(self.session, allocator, author, entry.id); 3132 const route = listRoute(self.data.identity, @fromBackingInt(@intCast(0)), "", entry.id) orelse return; 3133 try self.session.navigate(route); 3134 } else unreachable, 3135 .merge => if (comptime supports_merge) { 3136 if (comptime wasm) return; 3137 const entry = self.data.selectedThread() orelse return; 3138 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 3139 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 3140 const author = ((try self.session.authorize(self.data.identity, .write, kind)) orelse return).author; 3141 self.data.mergePatch(self.session, allocator, author, entry.id, revision) catch |err| switch (err) { 3142 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 3143 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 3144 try self.session.navigate(route); 3145 return; 3146 }, 3147 else => return err, 3148 }; 3149 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 3150 const route = listRoute(self.data.identity, merged, "", entry.id) orelse return; 3151 try self.session.navigate(route); 3152 } else unreachable, 3153 .remove => try self.submitRemove(allocator), 3154 } 3155 } 3156 3157 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 3158 const comment = self.data.comment_id.len != 0; 3159 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 3160 const id = evt.parseEventId(event_id) catch return; 3161 try self.removeEvent(allocator, if (comment) .comment else kind, id); 3162 } 3163 3164 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 3165 if (comptime wasm) return; 3166 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3167 const author = actor.author; 3168 3169 if (comptime supports_drafts) { 3170 const selected = self.data.selectedThread() orelse return; 3171 if (event_kind == kind and entryDraft(selected.*)) { 3172 try Data.removeDraft(self.session, allocator, author, &id); 3173 const route = draftsRoute(self.data.identity) orelse return; 3174 try self.session.navigate(route); 3175 return; 3176 } 3177 } 3178 3179 const io = self.session.io orelse return; 3180 const src = self.data.repo_source orelse return; 3181 if (!try src.canModify(io, allocator, actor, event_kind, &id)) return; 3182 const thread_id = evt.parseEventId(self.data.selected_id) catch return; 3183 3184 switch (src.repo_kind) { 3185 inline else => |repo_kind| { 3186 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3187 defer any_repo.deinit(io, allocator); 3188 switch (any_repo) { 3189 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), 3190 } 3191 }, 3192 } 3193 3194 const id_hex = std.fmt.bytesToHex(id, .lower); 3195 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex, null) orelse return; 3196 try self.session.navigate(route); 3197 } 3198 3199 // return to the list. 3200 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 3201 root_focus.setFocus(self.listScroll(index).getFocus().id); 3202 } 3203 3204 // cross to the header tabs above the stack. 3205 fn focusHeader(self: *This, root_focus: *Focus) void { 3206 root_focus.setFocus(self.box.children.keys()[header_index]); 3207 } 3208 3209 pub fn clearGrid(self: *This) void { 3210 self.box.clearGrid(); 3211 } 3212 3213 pub fn getGrid(self: This) ?Grid { 3214 return self.box.getGrid(); 3215 } 3216 3217 pub fn getFocus(self: *This) *Focus { 3218 return self.box.getFocus(); 3219 } 3220 3221 // for the parent's "scroll up at the top jumps to the header" check: at the 3222 // top only while the header tabs hold focus, so up from the split 3223 // crosses into the tabs first. 3224 pub fn atTop(self: *This) bool { 3225 return self.headerActive(); 3226 } 3227 }; 3228 } 3229