╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2877 const cid = form.getFocus().child_id orelse return; 2878 const cur = form.children.getIndex(cid) orelse return; 2879 const child = &form.children.values()[cur]; 2880 2881 if (child.widget == .text_input) { 2882 const ti = &child.widget.text_input; 2883 if (ti.options.multiline and try multilineKeepsKey(ti, allocator, key)) 2884 return child.widget.input(allocator, key, root_focus); 2885 } 2886 2887 const on_submit = child.widget == .submit_button; 2888 2889 switch (key) { 2890 .arrow_up, .back_tab => if (formStep(form, cur, false)) |i| self.focusResolveChild(form, i, root_focus) else self.focusHeader(root_focus), 2891 .arrow_down, .tab => if (formStep(form, cur, true)) |i| self.focusResolveChild(form, i, root_focus), 2892 .arrow_left, .arrow_right => switch (child.widget) { 2893 .box => |*row| _ = widget.moveInRow(row, root_focus, key == .arrow_right), 2894 else => try child.widget.input(allocator, key, root_focus), 2895 }, 2896 .enter => if (on_submit) try self.submitResolution(allocator), 2897 .mouse => |mouse| if (on_submit) { 2898 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) try self.submitResolution(allocator); 2899 }, 2900 else => try child.widget.input(allocator, key, root_focus), 2901 } 2902 } 2903 2904 // a multiline input keeps enter and any up/down that has a row to move to 2905 fn multilineKeepsKey(text_input: *wgt.TextInput, allocator: std.mem.Allocator, key: Key) !bool { 2906 return switch (key) { 2907 .enter => true, 2908 .arrow_up => !try text_input.cursorOnFirstRow(allocator), 2909 .arrow_down => !try text_input.cursorOnLastRow(allocator), 2910 else => false, 2911 }; 2912 } 2913 2914 // the neighboring form control, skipping spacers and blank rows 2915 fn formStep(form: *wgt.Box(Widget), cur: usize, down: bool) ?usize { 2916 var i = cur; 2917 while (true) { 2918 if (down) { 2919 i += 1; 2920 if (i >= form.children.count()) return null; 2921 } else { 2922 if (i == 0) return null; 2923 i -= 1; 2924 } 2925 const child = &form.children.values()[i]; 2926 if (child.hidden) continue; 2927 switch (child.widget) { 2928 .spacer, .text => continue, 2929 else => return i, 2930 } 2931 } 2932 } 2933 2934 // focus the resolve-form child at `i` (a version row focuses its selected 2935 // child) and keep it visible on the terminal 2936 fn focusResolveChild(self: *This, form: *wgt.Box(Widget), i: usize, root_focus: *Focus) void { 2937 const child = &form.children.values()[i]; 2938 switch (child.widget) { 2939 .box => |*row| root_focus.setFocus(row.getFocus().child_id orelse form.children.keys()[i]), 2940 else => root_focus.setFocus(form.children.keys()[i]), 2941 } 2942 if (self.session.is_terminal) { 2943 if (self.resolveScroll()) |sc| { 2944 if (child.rect) |rect| sc.scrollToRect(rect); 2945 } 2946 } 2947 } 2948 2949 // re-emit the conflicted thread's event with the resolved content; any 2950 // event on the thread settles its conflict entry. this is the terminal 2951 // path; the web posts the form to the resolve route. 2952 fn submitResolution(self: *This, allocator: std.mem.Allocator) !void { 2953 if (comptime wasm) return; 2954 const io = self.session.io orelse return; 2955 const src = self.data.repo_source orelse return; 2956 const entry = self.data.selectedThread() orelse return; 2957 const author = ((try self.session.authorize(self.data.identity, .write, kind)) orelse return).author; 2958 const form = self.formBox() orelse return; 2959 2960 // gather the inputs by name; the d<n> hunk inputs appear in chunk order 2961 var title: ?[]u8 = null; 2962 var labels: ?[]u8 = null; 2963 var hunks: std.ArrayList([]const u8) = .empty; 2964 defer { 2965 if (title) |t| allocator.free(t); 2966 if (labels) |t| allocator.free(t); 2967 for (hunks.items) |h| allocator.free(h); 2968 hunks.deinit(allocator); 2969 } 2970 for (form.children.values()) |*child| switch (child.widget) { 2971 .text_input => |*ti| { 2972 const text = try ti.text(allocator); 2973 errdefer allocator.free(text); 2974 if (std.mem.eql(u8, ti.options.name, "title")) { 2975 title = text; 2976 } else if (std.mem.eql(u8, ti.options.name, "labels")) { 2977 labels = text; 2978 } else { 2979 try hunks.append(allocator, text); 2980 } 2981 }, 2982 else => {}, 2983 }; 2984 2985 const id_bytes = try evt.parseEventId(entry.id); 2986 2987 switch (src.repo_kind) { 2988 inline else => |repo_kind| { 2989 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2990 defer any_repo.deinit(io, allocator); 2991 switch (any_repo) { 2992 inline else => |*repo| { 2993 var resolution: Event.Resolve = .{ 2994 .title = title, 2995 .labels = labels, 2996 .hunks = hunks.items, 2997 }; 2998 if (comptime @hasField(Event.Resolve, "theirs")) resolution.theirs = self.data.theirs_picks; 2999 const change = Event.Update{ .resolve = resolution }; 3000 Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, change, author) catch |err| switch (err) { 3001 // leave the form up for correction 3002 error.InvalidFields => return, 3003 else => |e| return e, 3004 }; 3005 }, 3006 } 3007 }, 3008 } 3009 3010 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3011 try self.session.navigate(route); 3012 } 3013 3014 // commit a new or edited comment and navigate to its permalink. this is the 3015 // terminal path; the web posts the form to its comment route. 3016 fn submitComment(self: *This, allocator: std.mem.Allocator) !void { 3017 if (comptime wasm) return; 3018 const io = self.session.io orelse return; 3019 const src = self.data.repo_source orelse return; 3020 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3021 const author = actor.author; 3022 const form = self.formBox() orelse return; 3023 const body_input = try formField(form, "body"); 3024 const body = try body_input.text(allocator); 3025 defer allocator.free(body); 3026 if (!evt.Comment.fieldsValid(body)) return; 3027 3028 var thread_id: [evt.event_id_size * 2]u8 = undefined; 3029 @memcpy(&thread_id, self.data.selected_id); 3030 const parent_id = if (self.data.comment_id.len == 0) thread_id else blk: { 3031 var parent: [evt.event_id_size * 2]u8 = undefined; 3032 @memcpy(&parent, self.data.comment_id); 3033 break :blk parent; 3034 }; 3035 var event_id_hex: [evt.event_id_size * 2]u8 = undefined; 3036 const editing = self.data.view == .edit_comment; 3037 if (editing) { 3038 const comment_id = evt.parseEventId(self.data.comment_id) catch return; 3039 if (!try src.canModify(io, allocator, actor, .comment, &comment_id)) return; 3040 } 3041 switch (src.repo_kind) { 3042 inline else => |repo_kind| { 3043 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3044 defer any_repo.deinit(io, allocator); 3045 switch (any_repo) { 3046 inline else => |*repo| if (editing) { 3047 const comment_id = evt.parseEventId(self.data.comment_id) catch return; 3048 try evt.Comment.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, kind, &thread_id, &comment_id, body, author); 3049 event_id_hex = std.fmt.bytesToHex(comment_id, .lower); 3050 } else { 3051 event_id_hex = try evt.Comment.create(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, kind, &thread_id, &parent_id, body, author); 3052 }, 3053 } 3054 }, 3055 } 3056 3057 body_input.clear(allocator); 3058 const route = ui.RoutablePage.repoThreadCommentRoute(kind, self.data.identity, &thread_id, &event_id_hex, 0) orelse return; 3059 try self.session.navigate(route); 3060 } 3061 3062 // terminal form submissions; the web posts to the forms' routes instead 3063 fn submitForm(self: *This, allocator: std.mem.Allocator) !void { 3064 switch (self.data.view) { 3065 .new_comment, .edit_comment => try self.submitComment(allocator), 3066 .edit => try self.submitEditedThread(allocator), 3067 else => try self.submitNewThread(allocator), 3068 } 3069 } 3070 3071 // commit the new thread to the repo's events branch and navigate to it. 3072 // this is the terminal path; the web posts the form to the thread route, 3073 // so the wasm side never runs (or compiles) the repo access below. 3074 fn submitNewThread(self: *This, allocator: std.mem.Allocator) !void { 3075 if (comptime wasm) return; 3076 const io = self.session.io orelse return; 3077 const src = self.data.repo_source orelse return; 3078 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3079 3080 const form = self.threadForm() orelse return; 3081 const title_input = try formField(form, "title"); 3082 const labels_input = try formField(form, "labels"); 3083 const description_input = try formField(form, "description"); 3084 3085 const title = try title_input.text(allocator); 3086 defer allocator.free(title); 3087 const labels = try labels_input.text(allocator); 3088 defer allocator.free(labels); 3089 const description = try description_input.text(allocator); 3090 defer allocator.free(description); 3091 const target_branch = if (comptime supports_drafts) try (try formField(form, "target_branch")).text(allocator) else ""; 3092 defer if (comptime supports_drafts) allocator.free(target_branch); 3093 3094 if (!Event.fieldsValid(title, labels)) { 3095 if (!evt.titleValid(title)) try self.rememberThreadFeedback(.required_title, title, labels, description, target_branch); 3096 return; 3097 } 3098 3099 if (comptime supports_drafts) { 3100 const source = formWidget(form, .patch_source) orelse return error.MissingFormField; 3101 const source_branch = switch (source.selectedKind()) { 3102 .fork => null, 3103 .branch => try source.field().text(allocator), 3104 }; 3105 defer if (source_branch) |branch| allocator.free(branch); 3106 const event_id_hex = Data.create(self.data, self.session, allocator, actor, title, labels, description, target_branch, source_branch) catch |err| { 3107 const failure = FeedbackFailure.fromError(err) orelse return err; 3108 try self.rememberThreadFeedback(failure, title, labels, description, target_branch); 3109 return; 3110 }; 3111 title_input.clear(allocator); 3112 labels_input.clear(allocator); 3113 description_input.clear(allocator); 3114 (try formField(form, "target_branch")).clear(allocator); 3115 const route = ui.RoutablePage.repoThreadCommentsRoute(kind, self.data.identity, &event_id_hex, 0) orelse return; 3116 try self.session.navigate(route); 3117 return; 3118 } 3119 3120 var id_bytes: [evt.event_id_size]u8 = undefined; 3121 io.random(&id_bytes); 3122 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); 3123 3124 const event = evt.EventWithId{ 3125 .id = event_id_hex, 3126 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 3127 .author = actor.author, 3128 .event = @unionInit(evt.Event, @tagName(kind), Event{ 3129 .title = title, 3130 .description = description, 3131 .labels = labels, 3132 }), 3133 }; 3134 3135 switch (src.repo_kind) { 3136 inline else => |repo_kind| { 3137 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3138 defer any_repo.deinit(io, allocator); 3139 switch (any_repo) { 3140 inline else => |*repo| try evt.consume(self.session.eventHost(), .repo, repo_kind, repo.self_repo_opts, io, allocator, repo, evt.events_ref, &.{event}), 3141 } 3142 }, 3143 } 3144 3145 // wipe the form so a return visit starts fresh 3146 title_input.clear(allocator); 3147 labels_input.clear(allocator); 3148 description_input.clear(allocator); 3149 3150 const route = listRoute(self.data.identity, @fromBackingInt(@intCast(0)), &event_id_hex) orelse return; 3151 try self.session.navigate(route); 3152 } 3153 3154 // re-emit the selected thread's event with the form's content (status 3155 // preserved), then reload the thread's page. this is the terminal path; 3156 // the web posts the form to the edit route. 3157 fn submitEditedThread(self: *This, allocator: std.mem.Allocator) !void { 3158 if (comptime wasm) return; 3159 const io = self.session.io orelse return; 3160 const entry = self.data.selectedThread() orelse return; 3161 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3162 const author = actor.author; 3163 3164 const form = self.threadForm() orelse return; 3165 const title_input = try formField(form, "title"); 3166 const labels_input = try formField(form, "labels"); 3167 const description_input = try formField(form, "description"); 3168 3169 const title = try title_input.text(allocator); 3170 defer allocator.free(title); 3171 const labels = try labels_input.text(allocator); 3172 defer allocator.free(labels); 3173 const description = try description_input.text(allocator); 3174 defer allocator.free(description); 3175 const target_branch = if (comptime supports_drafts) try (try formField(form, "target_branch")).text(allocator) else ""; 3176 defer if (comptime supports_drafts) allocator.free(target_branch); 3177 3178 if (!Event.fieldsValid(title, labels)) { 3179 if (!evt.titleValid(title)) try self.rememberThreadFeedback(.required_title, title, labels, description, target_branch); 3180 return; 3181 } 3182 const src = self.data.repo_source orelse return; 3183 3184 if (comptime supports_drafts) { 3185 if (entryDraft(entry.*)) { 3186 self.data.editDraft(self.session, allocator, author, entry.id, title, labels, description, target_branch) catch |err| { 3187 const failure = FeedbackFailure.fromError(err) orelse return err; 3188 try self.rememberThreadFeedback(failure, title, labels, description, target_branch); 3189 return; 3190 }; 3191 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3192 try self.session.navigate(route); 3193 return; 3194 } 3195 } 3196 3197 const id_bytes = try evt.parseEventId(entry.id); 3198 if (!try src.canModify(io, allocator, actor, kind, &id_bytes)) return; 3199 3200 switch (src.repo_kind) { 3201 inline else => |repo_kind| { 3202 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3203 defer any_repo.deinit(io, allocator); 3204 switch (any_repo) { 3205 inline else => |*repo| if (supports_drafts) { 3206 Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 3207 .title = title, 3208 .labels = labels, 3209 .description = description, 3210 .target_branch = target_branch, 3211 } }, author) catch |err| { 3212 const failure = FeedbackFailure.fromError(err) orelse return err; 3213 try self.rememberThreadFeedback(failure, title, labels, description, target_branch); 3214 return; 3215 }; 3216 } else if (has_status) 3217 try Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 3218 .title = title, 3219 .labels = labels, 3220 .description = description, 3221 } }, author) 3222 else 3223 try Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, title, labels, description, author), 3224 } 3225 }, 3226 } 3227 3228 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3229 try self.session.navigate(route); 3230 } 3231 3232 fn rememberThreadFeedback(self: *This, failure: FeedbackFailure, title: []const u8, labels: []const u8, description: []const u8, target_branch: []const u8) !void { 3233 const aa = self.session.arena.allocator(); 3234 const source = if (supports_drafts) blk: { 3235 const form = self.threadForm() orelse break :blk null; 3236 break :blk formWidget(form, .patch_source); 3237 } else null; 3238 self.session.data.form_feedback = @unionInit(ui.Session.FormFeedback, @tagName(feedback_tag), .{ 3239 .failure = failure, 3240 .fields = if (comptime supports_drafts) .{ 3241 .title = try aa.dupe(u8, title), 3242 .labels = try aa.dupe(u8, labels), 3243 .description = try aa.dupe(u8, description), 3244 .target_branch = try aa.dupe(u8, target_branch), 3245 .source_branch = if (source) |value| try value.field().text(aa) else "", 3246 .source_kind = if (source) |value| value.selectedKind() else .fork, 3247 } else .{ 3248 .title = try aa.dupe(u8, title), 3249 .labels = try aa.dupe(u8, labels), 3250 .description = try aa.dupe(u8, description), 3251 }, 3252 }); 3253 } 3254 3255 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 3256 switch (confirmation(self.data.view) orelse return) { 3257 .publish => if (comptime supports_drafts) { 3258 if (comptime wasm) return; 3259 const entry = self.data.selectedThread() orelse return; 3260 if (!entryDraft(entry.*)) return; 3261 const author = ((try self.session.authorize(self.data.identity, .read, kind)) orelse return).author; 3262 try self.data.publishDraft(self.session, allocator, author, entry.id); 3263 const route = listRoute(self.data.identity, @fromBackingInt(@intCast(0)), entry.id) orelse return; 3264 try self.session.navigate(route); 3265 } else unreachable, 3266 .merge => if (comptime supports_merge) { 3267 if (comptime wasm) return; 3268 const entry = self.data.selectedThread() orelse return; 3269 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 3270 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 3271 const author = ((try self.session.authorize(self.data.identity, .write, kind)) orelse return).author; 3272 self.data.mergePatch(self.session, allocator, author, entry.id, revision) catch |err| switch (err) { 3273 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 3274 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3275 try self.session.navigate(route); 3276 return; 3277 }, 3278 else => return err, 3279 }; 3280 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 3281 const route = listRoute(self.data.identity, merged, entry.id) orelse return; 3282 try self.session.navigate(route); 3283 } else unreachable, 3284 .remove => try self.submitRemove(allocator), 3285 } 3286 } 3287 3288 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 3289 const comment = self.data.comment_id.len != 0; 3290 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 3291 const id = evt.parseEventId(event_id) catch return; 3292 try self.removeEvent(allocator, if (comment) .comment else kind, id); 3293 } 3294 3295 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 3296 if (comptime wasm) return; 3297 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3298 const author = actor.author; 3299 3300 if (comptime supports_drafts) { 3301 const selected = self.data.selectedThread() orelse return; 3302 if (event_kind == kind and entryDraft(selected.*)) { 3303 try Data.removeDraft(self.session, allocator, author, &id); 3304 const route = draftsRoute(self.data.identity) orelse return; 3305 try self.session.navigate(route); 3306 return; 3307 } 3308 } 3309 3310 const io = self.session.io orelse return; 3311 const src = self.data.repo_source orelse return; 3312 if (!try src.canModify(io, allocator, actor, event_kind, &id)) return; 3313 const thread_id = evt.parseEventId(self.data.selected_id) catch return; 3314 3315 switch (src.repo_kind) { 3316 inline else => |repo_kind| { 3317 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3318 defer any_repo.deinit(io, allocator); 3319 switch (any_repo) { 3320 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), 3321 } 3322 }, 3323 } 3324 3325 // back to the thread, or to its list when the thread itself was removed 3326 const selected = self.data.selectedThread() orelse return; 3327 const route = listRoute(self.data.identity, entryStatus(selected.*), if (event_kind == kind) "" else self.data.selected_id) orelse return; 3328 try self.session.navigate(route); 3329 } 3330 3331 // enter the detail pane, landing on the way back to the list when it shows 3332 fn focusDetail(self: *This, index: usize, root_focus: *Focus) void { 3333 if (widget.listBackId(self.detailFrame(index)) != null) return widget.focusListBack(self.detailFrame(index), root_focus); 3334 _ = self.detail(index).focusFirst(root_focus); 3335 } 3336 3337 // return to the list. 3338 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 3339 root_focus.setFocus(self.listScroll(index).getFocus().id); 3340 } 3341 3342 // cross to the header tabs above the stack. 3343 fn focusHeader(self: *This, root_focus: *Focus) void { 3344 root_focus.setFocus(self.box.children.keys()[header_index]); 3345 } 3346 3347 pub fn clearGrid(self: *This) void { 3348 self.box.clearGrid(); 3349 } 3350 3351 pub fn getGrid(self: This) ?Grid { 3352 return self.box.getGrid(); 3353 } 3354 3355 pub fn getFocus(self: *This) *Focus { 3356 return self.box.getFocus(); 3357 } 3358 3359 // for the parent's "scroll up at the top jumps to the header" check: at the 3360 // top only while the header tabs hold focus, so up from the split 3361 // crosses into the tabs first. 3362 pub fn atTop(self: *This) bool { 3363 return self.headerActive(); 3364 } 3365 }; 3366 } 3367