1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#[allow(clippy::wildcard_imports)]
use super::*;
impl App {
/// The mention store for this repository, or `None` when `[mentions] enabled =
/// false`.
///
/// Delegated rather than re-derived: the store owns one constructor, so the TUI,
/// the CLI and the write seam cannot disagree about which directory the feature
/// reads and writes.
pub(in crate::app) fn mention_store(&self) -> Option<crate::mentions::store::MentionStore> {
self.store.mention_store()
}
/// Recompute the local user's mention candidates and unread count.
///
/// Read-only, and cheap by construction: the candidates are one `git config`
/// read and the count is the unread records in the one or two files those
/// candidates name — never a scan of the issue tree (design D7).
pub fn refresh_mentions(&mut self) {
self.mention_candidates = crate::mentions::identity::local_candidates();
self.unread_mentions = match self.mention_store() {
Some(store) => store.unread_count(&self.mention_candidates),
None => 0,
};
}
/// Open the all-issues mentions view, or say there is nothing to show.
pub(in crate::app) fn open_mentions(&mut self) {
// A disabled feature says so rather than reporting an empty queue: "no pending
// mentions" for `enabled = false` would tell the user their mentions were handled
// when the feature is simply not running, which is the same distinction the CLI's
// `tix mentions` refusal draws.
let Some(store) = self.mention_store() else {
self.status_msg =
Some("mentions are disabled (`[mentions] enabled = false`)".to_string());
return;
};
let rows = store.pending_for(&self.mention_candidates);
if rows.is_empty() {
self.status_msg = Some("no pending mentions".to_string());
return;
}
self.mentions_view = Some(crate::ui::mentions::MentionsView::new(rows, None));
self.mode = Mode::Mentions;
}
/// Show the notice when `number` has unread mentions for the local user.
pub(in crate::app) fn notice_mentions_for(&mut self, number: u32) {
let rows = self
.mention_store()
.map(|store| store.pending_for_issue(&self.mention_candidates, number))
.unwrap_or_default();
if rows.is_empty() {
return;
}
self.mentions = Some(crate::ui::mentions::MentionsView::new(rows, Some(number)));
self.mode = Mode::MentionNotice;
}
/// Mark one mention read and drop it from the surface that showed it.
///
/// The one **mutating** answer of the three; the other two change nothing, which
/// is the property that makes "ignore" mean "show me this again".
pub(in crate::app) fn mark_mention_read(&mut self, id: &str) {
if let Some(store) = self.mention_store() {
if let Err(e) = store.mark_read(&self.mention_candidates, id) {
self.status_msg = Some(format!("mentions: {e}"));
}
}
self.refresh_mentions();
}
/// Scroll the detail pane so the mention with `key` is in view.
///
/// The location is recomputed from the stored issue, not remembered: the
/// fingerprint is the identity, so a line number recorded at reconciliation time
/// would be stale the moment anything above the mention was edited.
pub(in crate::app) fn jump_to_mention(&mut self, key: &str) {
let Some(detail) = self.detail.as_ref() else {
return;
};
let issue = detail.issue.clone();
let Some(line) = Self::mention_line_of(&issue, key) else {
return;
};
if let Some(detail) = self.detail.as_mut() {
detail.focus_body_line(line);
}
}
/// The body line the mention with `key` sits on, if it is still there.
pub(in crate::app) fn mention_line_of(issue: &Issue, key: &str) -> Option<usize> {
let id = issue.id.clone().unwrap_or_else(|| issue.filename.clone());
let located = crate::mentions::locate(
crate::mentions::IssueContent {
id: &id,
number: issue.number,
file: &issue.filename,
title: &issue.title,
body: &issue.body,
},
key,
)?;
located.line
}
/// The raw keys of the per-issue notice.
///
/// Raw rather than bound, so `j`/`k` stay navigation and `i` means "ignore" here
/// whatever the board binds it to. `Esc` (and `i`) close without writing; only
/// `r` reaches the store.
pub(in crate::app) fn handle_mention_notice_key(&mut self, key: KeyEvent) -> Result<Action> {
if self.mentions.is_none() {
self.mode = Mode::Detail;
return Ok(Action::None);
}
match key.code {
KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('i') => {
self.mentions = None;
self.mode = Mode::Detail;
}
KeyCode::Down | KeyCode::Char('j') => {
if let Some(view) = self.mentions.as_mut() {
view.move_by(1);
}
}
KeyCode::Up | KeyCode::Char('k') => {
if let Some(view) = self.mentions.as_mut() {
view.move_by(-1);
}
}
KeyCode::Enter => {
let key = self
.mentions
.as_ref()
.and_then(|view| view.current())
.map(|mention| mention.key.clone());
self.mentions = None;
self.mode = Mode::Detail;
if let Some(key) = key {
self.jump_to_mention(&key);
}
}
KeyCode::Char('r') => {
let id = self
.mentions
.as_ref()
.and_then(|view| view.current())
.map(|mention| mention.id.clone());
if let Some(id) = id {
self.mark_mention_read(&id);
if let Some(view) = self.mentions.as_mut() {
view.drop_current();
}
if self
.mentions
.as_ref()
.is_some_and(crate::ui::mentions::MentionsView::is_empty)
{
self.mentions = None;
self.mode = Mode::Detail;
}
}
}
_ => {}
}
Ok(Action::None)
}
/// The raw keys of the all-issues mentions view.
///
/// `i` closes the view without writing — the same "ignore for now" the notice
/// offers, spelled the way the `tix mentions ignore` surface spells it.
pub(in crate::app) fn handle_mentions_view_key(&mut self, key: KeyEvent) -> Result<Action> {
if self.mentions_view.is_none() {
self.mode = Mode::Board;
return Ok(Action::None);
}
match key.code {
KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('i') => {
self.mentions_view = None;
self.mode = Mode::Board;
}
KeyCode::Down | KeyCode::Char('j') => {
if let Some(view) = self.mentions_view.as_mut() {
view.move_by(1);
}
}
KeyCode::Up | KeyCode::Char('k') => {
if let Some(view) = self.mentions_view.as_mut() {
view.move_by(-1);
}
}
KeyCode::Enter => {
let selected = self
.mentions_view
.as_ref()
.and_then(|view| view.current())
.cloned();
let Some(mention) = selected else {
return Ok(Action::None);
};
self.mentions_view = None;
self.open_issue_by_number(mention.issue_number)?;
// The row the user chose is the one they meant to see, so the issue's
// own notice does not preempt the jump it was opened for — and the mode
// it may have entered is the pane the jump acts on.
self.mentions = None;
self.mode = Mode::Detail;
self.jump_to_mention(&mention.key);
}
KeyCode::Char('r') => {
let id = self
.mentions_view
.as_ref()
.and_then(|view| view.current())
.map(|mention| mention.id.clone());
if let Some(id) = id {
self.mark_mention_read(&id);
if let Some(view) = self.mentions_view.as_mut() {
view.drop_current();
}
if self
.mentions_view
.as_ref()
.is_some_and(crate::ui::mentions::MentionsView::is_empty)
{
self.mentions_view = None;
self.mode = Mode::Board;
}
}
}
_ => {}
}
Ok(Action::None)
}
}