synd-term 0.3.2

terminal feed viewer
Documentation
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
use std::{fmt::Display, sync::Arc};
use synd_auth::device_flow::DeviceAuthorizationResponse;
use synd_feed::types::{Category, FeedUrl};

use crate::{
    application::{Direction, Populate, RequestSequence},
    auth::{AuthenticationProvider, Credential, Verified},
    client::{
        github::{FetchNotificationsParams, GithubError},
        synd_api::{
            mutation::subscribe_feed::SubscribeFeedInput, payload,
            query::subscription::SubscriptionOutput, SyndApiError,
        },
    },
    types::{
        github::{
            IssueContext, IssueOrPullRequest, Notification, NotificationId, PullRequestContext,
            PullRequestState, Reason,
        },
        Feed,
    },
    ui::components::{filter::FilterLane, gh_notifications::GhNotificationFilterUpdater},
};

#[derive(Debug, Clone)]
pub(crate) enum ApiResponse {
    DeviceFlowAuthorization {
        provider: AuthenticationProvider,
        device_authorization: DeviceAuthorizationResponse,
    },
    DeviceFlowCredential {
        credential: Verified<Credential>,
    },
    SubscribeFeed {
        feed: Box<Feed>,
    },
    UnsubscribeFeed {
        url: FeedUrl,
    },
    FetchSubscription {
        populate: Populate,
        subscription: SubscriptionOutput,
    },
    FetchEntries {
        populate: Populate,
        payload: payload::FetchEntriesPayload,
    },
    FetchGithubNotifications {
        populate: Populate,
        notifications: Vec<Notification>,
    },
    FetchGithubIssue {
        notification_id: NotificationId,
        issue: IssueContext,
    },
    FetchGithubPullRequest {
        notification_id: NotificationId,
        pull_request: PullRequestContext,
    },
    MarkGithubNotificationAsDone {
        notification_id: NotificationId,
    },
    UnsubscribeGithubThread {},
}

impl Display for ApiResponse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ApiResponse::DeviceFlowCredential { .. } => f.write_str("DeviceFlowCredential"),
            ApiResponse::FetchSubscription { .. } => f.write_str("FetchSubscription"),
            ApiResponse::FetchEntries { .. } => f.write_str("FetchEntries"),
            ApiResponse::FetchGithubNotifications { .. } => f.write_str("FetchGithubNotifications"),
            ApiResponse::FetchGithubIssue { .. } => f.write_str("FetchGithubIssue"),
            ApiResponse::FetchGithubPullRequest { .. } => f.write_str("FetchGithubPullRequest"),
            cmd => write!(f, "{cmd:?}"),
        }
    }
}

#[derive(Debug, Clone)]
pub(crate) enum Command {
    Nop,
    Quit,
    ResizeTerminal {
        _columns: u16,
        _rows: u16,
    },
    RenderThrobber,
    Idle,

    Authenticate,
    MoveAuthenticationProvider(Direction),

    HandleApiResponse {
        request_seq: RequestSequence,
        response: ApiResponse,
    },

    RefreshCredential {
        credential: Verified<Credential>,
    },

    MoveTabSelection(Direction),

    // Subscription
    MoveSubscribedFeed(Direction),
    MoveSubscribedFeedFirst,
    MoveSubscribedFeedLast,
    PromptFeedSubscription,
    PromptFeedEdition,
    PromptFeedUnsubscription,
    MoveFeedUnsubscriptionPopupSelection(Direction),
    SelectFeedUnsubscriptionPopup,
    CancelFeedUnsubscriptionPopup,
    SubscribeFeed {
        input: SubscribeFeedInput,
    },
    FetchSubscription {
        after: Option<String>,
        first: i64,
    },
    ReloadSubscription,
    OpenFeed,

    // Entries
    FetchEntries {
        after: Option<String>,
        first: i64,
    },
    ReloadEntries,
    MoveEntry(Direction),
    MoveEntryFirst,
    MoveEntryLast,
    OpenEntry,
    BrowseEntry,

    // Filter
    MoveFilterRequirement(Direction),
    ActivateCategoryFilterling,
    ActivateSearchFiltering,
    PromptChanged,
    DeactivateFiltering,
    ToggleFilterCategory {
        lane: FilterLane,
        category: Category<'static>,
    },
    ActivateAllFilterCategories {
        lane: FilterLane,
    },
    DeactivateAllFilterCategories {
        lane: FilterLane,
    },

    // Theme
    RotateTheme,

    // Latest release check
    InformLatestRelease(update_informer::Version),

    // Github notifications
    FetchGhNotifications {
        populate: Populate,
        params: FetchNotificationsParams,
    },
    FetchGhNotificationDetails {
        contexts: Vec<IssueOrPullRequest>,
    },
    MoveGhNotification(Direction),
    MoveGhNotificationFirst,
    MoveGhNotificationLast,
    OpenGhNotification {
        with_mark_as_done: bool,
    },
    ReloadGhNotifications,
    MarkGhNotificationAsDone {
        all: bool,
    },
    UnsubscribeGhThread,
    OpenGhNotificationFilterPopup,
    CloseGhNotificationFilterPopup,
    UpdateGhnotificationFilterPopupOptions(GhNotificationFilterUpdater),

    // Error
    HandleError {
        message: String,
    },
    HandleApiError {
        // use Arc for impl Clone
        error: Arc<SyndApiError>,
        request_seq: RequestSequence,
    },
    HandleOauthApiError {
        // use Arc for impl Clone
        error: Arc<anyhow::Error>,
        request_seq: RequestSequence,
    },
    HandleGithubApiError {
        // use Arc for impl Clone
        error: Arc<GithubError>,
        request_seq: RequestSequence,
    },
}

impl Display for Command {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Command::HandleApiResponse { response, .. } => response.fmt(f),
            Command::FetchGhNotificationDetails { .. } => f
                .debug_struct("FetchGhNotificationDetails")
                .finish_non_exhaustive(),
            _ => write!(f, "{self:?}"),
        }
    }
}

impl Command {
    pub(crate) fn api_error(error: SyndApiError, request_seq: RequestSequence) -> Self {
        Command::HandleApiError {
            error: Arc::new(error),
            request_seq,
        }
    }
    pub(crate) fn oauth_api_error(error: anyhow::Error, request_seq: RequestSequence) -> Self {
        Command::HandleOauthApiError {
            error: Arc::new(error),
            request_seq,
        }
    }
}

impl Command {
    pub fn quit() -> Self {
        Command::Quit
    }
    pub fn authenticate() -> Self {
        Command::Authenticate
    }
    pub fn move_right_tab_selection() -> Self {
        Command::MoveTabSelection(Direction::Right)
    }
    pub fn move_left_tab_selection() -> Self {
        Command::MoveTabSelection(Direction::Left)
    }
    pub fn move_up_authentication_provider() -> Self {
        Command::MoveAuthenticationProvider(Direction::Up)
    }
    pub fn move_down_authentication_provider() -> Self {
        Command::MoveAuthenticationProvider(Direction::Down)
    }
    pub fn move_up_entry() -> Self {
        Command::MoveEntry(Direction::Up)
    }
    pub fn move_down_entry() -> Self {
        Command::MoveEntry(Direction::Down)
    }
    pub fn reload_entries() -> Self {
        Command::ReloadEntries
    }
    pub fn open_entry() -> Self {
        Command::OpenEntry
    }
    pub fn browse_entry() -> Self {
        Command::BrowseEntry
    }
    pub fn move_entry_first() -> Self {
        Command::MoveEntryFirst
    }
    pub fn move_entry_last() -> Self {
        Command::MoveEntryLast
    }
    pub fn prompt_feed_subscription() -> Self {
        Command::PromptFeedSubscription
    }
    pub fn prompt_feed_edition() -> Self {
        Command::PromptFeedEdition
    }
    pub fn prompt_feed_unsubscription() -> Self {
        Command::PromptFeedUnsubscription
    }
    pub fn move_feed_unsubscription_popup_selection_left() -> Self {
        Command::MoveFeedUnsubscriptionPopupSelection(Direction::Left)
    }
    pub fn move_feed_unsubscription_popup_selection_right() -> Self {
        Command::MoveFeedUnsubscriptionPopupSelection(Direction::Right)
    }
    pub fn select_feed_unsubscription_popup() -> Self {
        Command::SelectFeedUnsubscriptionPopup
    }
    pub fn cancel_feed_unsubscription_popup() -> Self {
        Command::CancelFeedUnsubscriptionPopup
    }
    pub fn move_up_subscribed_feed() -> Self {
        Command::MoveSubscribedFeed(Direction::Up)
    }
    pub fn move_down_subscribed_feed() -> Self {
        Command::MoveSubscribedFeed(Direction::Down)
    }
    pub fn reload_subscription() -> Self {
        Command::ReloadSubscription
    }
    pub fn open_feed() -> Self {
        Command::OpenFeed
    }
    pub fn move_subscribed_feed_first() -> Self {
        Command::MoveSubscribedFeedFirst
    }
    pub fn move_subscribed_feed_last() -> Self {
        Command::MoveSubscribedFeedLast
    }
    pub fn move_filter_requirement_left() -> Self {
        Command::MoveFilterRequirement(Direction::Left)
    }
    pub fn move_filter_requirement_right() -> Self {
        Command::MoveFilterRequirement(Direction::Right)
    }
    pub fn activate_category_filtering() -> Self {
        Command::ActivateCategoryFilterling
    }
    pub fn activate_search_filtering() -> Self {
        Command::ActivateSearchFiltering
    }
    pub fn deactivate_filtering() -> Self {
        Command::DeactivateFiltering
    }
    pub fn rotate_theme() -> Self {
        Command::RotateTheme
    }
    pub fn move_up_gh_notification() -> Self {
        Command::MoveGhNotification(Direction::Up)
    }
    pub fn move_down_gh_notification() -> Self {
        Command::MoveGhNotification(Direction::Down)
    }
    pub fn move_gh_notification_first() -> Self {
        Command::MoveGhNotificationFirst
    }
    pub fn move_gh_notification_last() -> Self {
        Command::MoveGhNotificationLast
    }
    pub fn open_gh_notification() -> Self {
        Command::OpenGhNotification {
            with_mark_as_done: false,
        }
    }
    pub fn open_gh_notification_with_done() -> Self {
        Command::OpenGhNotification {
            with_mark_as_done: true,
        }
    }
    pub fn reload_gh_notifications() -> Self {
        Command::ReloadGhNotifications
    }
    pub fn mark_gh_notification_as_done() -> Self {
        Command::MarkGhNotificationAsDone { all: false }
    }
    pub fn mark_gh_notification_as_done_all() -> Self {
        Command::MarkGhNotificationAsDone { all: true }
    }
    pub fn unsubscribe_gh_thread() -> Self {
        Command::UnsubscribeGhThread
    }
    pub fn open_gh_notification_filter_popup() -> Self {
        Command::OpenGhNotificationFilterPopup
    }
    pub fn close_gh_notification_filter_popup() -> Self {
        Command::CloseGhNotificationFilterPopup
    }
    pub fn toggle_gh_notification_filter_popup_include_unread() -> Self {
        Command::UpdateGhnotificationFilterPopupOptions(GhNotificationFilterUpdater {
            toggle_include: true,
            ..Default::default()
        })
    }
    pub fn toggle_gh_notification_filter_popup_participating() -> Self {
        Command::UpdateGhnotificationFilterPopupOptions(GhNotificationFilterUpdater {
            toggle_participating: true,
            ..Default::default()
        })
    }
    pub fn toggle_gh_notification_filter_popup_visibility_public() -> Self {
        Command::UpdateGhnotificationFilterPopupOptions(GhNotificationFilterUpdater {
            toggle_visilibty_public: true,
            ..Default::default()
        })
    }
    pub fn toggle_gh_notification_filter_popup_visibility_private() -> Self {
        Command::UpdateGhnotificationFilterPopupOptions(GhNotificationFilterUpdater {
            toggle_visilibty_private: true,
            ..Default::default()
        })
    }
    pub fn toggle_gh_notification_filter_popup_pr_open() -> Self {
        Command::UpdateGhnotificationFilterPopupOptions(GhNotificationFilterUpdater {
            toggle_pull_request_condition: Some(PullRequestState::Open),
            ..Default::default()
        })
    }
    pub fn toggle_gh_notification_filter_popup_pr_closed() -> Self {
        Command::UpdateGhnotificationFilterPopupOptions(GhNotificationFilterUpdater {
            toggle_pull_request_condition: Some(PullRequestState::Closed),
            ..Default::default()
        })
    }
    pub fn toggle_gh_notification_filter_popup_pr_merged() -> Self {
        Command::UpdateGhnotificationFilterPopupOptions(GhNotificationFilterUpdater {
            toggle_pull_request_condition: Some(PullRequestState::Merged),
            ..Default::default()
        })
    }
    pub fn toggle_gh_notification_filter_popup_reason_mentioned() -> Self {
        Command::UpdateGhnotificationFilterPopupOptions(GhNotificationFilterUpdater {
            toggle_reason: Some(Reason::Mention),
            ..Default::default()
        })
    }
    pub fn toggle_gh_notification_filter_popup_reason_review() -> Self {
        Command::UpdateGhnotificationFilterPopupOptions(GhNotificationFilterUpdater {
            toggle_reason: Some(Reason::ReviewRequested),
            ..Default::default()
        })
    }
}