Skip to main content

cosmic_applet_avestruz/handlers/
feed.rs

1// SPDX-License-Identifier: MIT
2
3//! Feed message handlers for Avestruz.
4//!
5//! The feed is the notes of the people the account follows. A profile has a
6//! list of its own, the notes of one person, and both are kept and filled
7//! the same way, as a [`FeedState`]. What the event store already holds of a
8//! list shows at once; the relays are then asked for the newest page, and
9//! for an older page each time the list is scrolled near its end. Nothing
10//! is fetched unasked after that: Refresh pulls the feed's latest.
11//!
12//! What a list shows is its reader's: it only changes when they say so.
13//! The feed is looked at again every so often, and notes that turned up
14//! since wait beside it ([`Pending`](crate::nostr::feed::Pending)), offered
15//! by a button over the list; pressing it, or Refresh, shows them and goes
16//! to the top. Until then nothing is put in above what is being read, and
17//! nothing moves.
18//!
19//! A list is read with replies or without ([`FeedMode`]), by a choice made
20//! above it and kept in the config. Read without, a page may bring nothing
21//! to show: the list then looks further back on its own, a few pages at
22//! most, and after that when asked.
23//!
24//! Every list has an id of its own, and whatever is asked for it comes back
25//! with that id. An answer whose list is gone by then is dropped: a profile
26//! that was closed, a feed that started over.
27//!
28//! Who the account follows is its contact list (kind 3), read from the store
29//! first and then asked of the relays. Whenever that answer changes — another
30//! account, or a newer list — the feed starts over, as a new list.
31
32use std::time::{Duration, Instant};
33
34use cosmic::prelude::*;
35use cosmic::widget::segmented_button;
36use nostr_sdk::prelude::{EventId, PublicKey};
37
38use crate::fl;
39use crate::handlers::navigation::scroll_list_to;
40use crate::handlers::relays::ALWAYS_READ;
41use crate::messages::Message;
42use crate::nostr::client::{FEED_PAGE, FetchError, NostrService, Source};
43use crate::nostr::feed::{Feed, FeedMode, FeedPage};
44use crate::nostr::models::{Note, Profile};
45use crate::state::{AppModel, FeedState, Page, ViewState};
46use crate::views::components::RowHeights;
47
48/// How long after the feed was looked at for new notes it is not looked at
49/// again for the popup opening.
50const NEW_NOTES_FRESH: Duration = Duration::from_secs(30);
51
52/// Ask the relays for the profiles of `people`: the account's own, and,
53/// for those these don't have, the relays those people write to, which
54/// take longer. Each answers when it has one.
55pub(crate) fn fetch_profiles(service: NostrService, people: Vec<PublicKey>) -> Task<cosmic::Action<Message>> {
56    let arrived = |found| cosmic::Action::App(Message::ProfilesFetched(found));
57    let own = {
58        let (service, people) = (service.clone(), people.clone());
59        Task::perform(async move { service.fetch_profiles(people).await }, arrived)
60    };
61    let theirs = Task::perform(async move { service.fetch_profiles_where_written(people).await }, arrived);
62    Task::batch([own, theirs])
63}
64
65impl AppModel {
66    /// A new, empty list of notes, with an id no list had before.
67    pub(crate) fn new_feed(&mut self) -> FeedState {
68        self.feeds_made += 1;
69        FeedState::new(self.feeds_made)
70    }
71
72    /// The list of notes `id`, if it is still there: the feed, or the notes
73    /// of an open profile.
74    fn feed_mut(&mut self, id: u64) -> Option<&mut FeedState> {
75        if self.following.id == id {
76            return Some(&mut self.following);
77        }
78        self.pages.iter_mut().find_map(|page| match page {
79            Page::Profile(profile) if profile.notes.id == id => Some(&mut profile.notes),
80            _ => None,
81        })
82    }
83
84    /// Whose notes the list `id` is made of. `None` if the list is gone,
85    /// and for the feed while who is followed isn't known.
86    fn feed_authors(&self, id: u64) -> Option<Vec<PublicKey>> {
87        if self.following.id == id {
88            return self.follows.clone();
89        }
90        self.pages.iter().find_map(|page| match page {
91            Page::Profile(profile) if profile.notes.id == id => Some(vec![profile.public_key]),
92            _ => None,
93        })
94    }
95
96    /// The event store opened (or didn't). Find out about the account, if
97    /// someone is signed in already: who they follow fills the feed.
98    pub fn handle_nostr_ready(&mut self, result: Result<NostrService, String>) -> Task<cosmic::Action<Message>> {
99        match result {
100            Ok(service) => {
101                self.nostr = Some(service);
102                self.load_account()
103            }
104            Err(e) => {
105                tracing::error!("event store could not be opened: {e}");
106                self.error_message = Some(fl!("error-storage", error = e));
107                Task::none()
108            }
109        }
110    }
111
112    /// Fill the list `id`: what the store holds of it now, and the newest
113    /// page from the relays after.
114    pub(crate) fn load_feed(&mut self, id: u64) -> Task<cosmic::Action<Message>> {
115        let (Some(service), Some(authors)) = (self.nostr.clone(), self.feed_authors(id)) else {
116            return Task::none();
117        };
118        let cached = Task::perform(async move { service.cached_feed(&authors, FEED_PAGE).await }, move |result| {
119            cosmic::Action::App(Message::FeedCached(id, result))
120        });
121        Task::batch([cached, self.fetch_feed(id, FeedPage::Newest)])
122    }
123
124    /// Ask the relays for a page of the list `id`, unless that page is
125    /// already on its way (or, for an older page, there is nothing older).
126    pub(crate) fn fetch_feed(&mut self, id: u64, page: FeedPage) -> Task<cosmic::Action<Message>> {
127        let (Some(service), Some(authors)) = (self.nostr.clone(), self.feed_authors(id)) else {
128            return Task::none();
129        };
130        let Some(state) = self.feed_mut(id) else {
131            return Task::none();
132        };
133        let until = match page {
134            FeedPage::Newest => {
135                if state.refreshing {
136                    return Task::none();
137                }
138                state.refreshing = true;
139                None
140            }
141            FeedPage::Older => {
142                if state.loading_older || state.end_reached {
143                    return Task::none();
144                }
145                let Some(oldest) = state.feed.oldest() else {
146                    return Task::none();
147                };
148                state.loading_older = true;
149                // `until` includes its own second, so notes sharing the
150                // oldest note's second come again and are skipped as known.
151                Some(oldest)
152            }
153        };
154        Task::perform(async move { service.fetch_feed(&authors, until, FEED_PAGE).await }, move |result| {
155            cosmic::Action::App(Message::FeedFetched { list: id, page, until, result })
156        })
157    }
158
159    /// The notes of the list `id` already in the event store were read:
160    /// what it shows until the relays answer. Once they have, the list is
161    /// what it is, and the store has nothing to add to it, unless they
162    /// answered with nothing.
163    pub fn handle_feed_cached(&mut self, id: u64, result: Result<Vec<Note>, String>) -> Task<cosmic::Action<Message>> {
164        match result {
165            Ok(notes) => {
166                tracing::info!("list {id}: {} note(s) from the event store", notes.len());
167                match self.feed_mut(id) {
168                    Some(state) if !state.settled || state.feed.is_empty() => self.merge_notes(id, notes),
169                    _ => Task::none(),
170                }
171            }
172            Err(e) => {
173                tracing::warn!("list {id} could not be read from the event store: {e}");
174                Task::none()
175            }
176        }
177    }
178
179    /// A page of the list `id` arrived from the relays (or didn't): the
180    /// newest there is, or the page before the note written at `until`.
181    pub fn handle_feed_fetched(
182        &mut self,
183        id: u64,
184        page: FeedPage,
185        until: Option<u64>,
186        result: Result<Vec<Note>, FetchError>,
187    ) -> Task<cosmic::Action<Message>> {
188        match page {
189            FeedPage::Newest => self.handle_newest_fetched(id, result),
190            FeedPage::Older => self.handle_older_fetched(id, until, result),
191        }
192    }
193
194    /// The newest notes of the list `id` arrived from the relays (or
195    /// didn't).
196    ///
197    /// They go into the list itself only while nobody can have been
198    /// reading it: when it is empty, or being filled for the first time and
199    /// still at its top. After that they wait to be asked for, and what is
200    /// on show stays as it is, unless this page was asked for by hand.
201    fn handle_newest_fetched(&mut self, id: u64, result: Result<Vec<Note>, FetchError>) -> Task<cosmic::Action<Message>> {
202        let mode = self.config.feed_mode;
203        let Some(state) = self.feed_mut(id) else {
204            return Task::none();
205        };
206        state.refreshing = false;
207        let asked_for = std::mem::take(&mut state.show_when_fetched);
208        let first = !std::mem::replace(&mut state.settled, true);
209        match result {
210            Ok(notes) => {
211                let received = notes.len();
212                let unread = state.feed.is_empty() || (first && state.position.get() <= 0.0);
213                // What the store had to show came without the quoted notes
214                // only the relays have: while nobody can have been
215                // reading, it is shown with them.
216                let mut people = if unread { state.feed.take_quotes_from(&notes) } else { Vec::new() };
217                people.extend(state.pending.offer(&state.feed, notes, received >= FEED_PAGE));
218                tracing::info!(
219                    "list {id}: {received} note(s) from the relays for Newest, {} not shown yet",
220                    state.pending.notes(mode).len()
221                );
222                // The relays answered: they may have older notes again, if
223                // they had none before.
224                state.end_reached = false;
225                let looked_up = self.look_up_people(people);
226                let shown = if asked_for || unread { self.show_new_notes(id) } else { Task::none() };
227                Task::batch([looked_up, shown, self.look_back_if_nothing_to_show(id)])
228            }
229            Err(e) => {
230                // A look in passing that came to nothing is not worth a
231                // banner: the next one is a minute away.
232                if asked_for || first {
233                    tracing::error!("list {id} could not be fetched for Newest: {e:?}");
234                    self.error_message = Some(fetch_error_text(e));
235                } else {
236                    tracing::warn!("list {id}: no new notes could be looked for: {e:?}");
237                }
238                Task::none()
239            }
240        }
241    }
242
243    /// The page of the list `id` before the note written at `until`
244    /// arrived from the relays (or didn't).
245    fn handle_older_fetched(
246        &mut self,
247        id: u64,
248        until: Option<u64>,
249        result: Result<Vec<Note>, FetchError>,
250    ) -> Task<cosmic::Action<Message>> {
251        let mode = self.config.feed_mode;
252        let Some(state) = self.feed_mut(id) else {
253            return Task::none();
254        };
255        state.loading_older = false;
256        // The list started over since this was asked for: the page is from
257        // before where it now ends, and would leave a hole.
258        if state.feed.oldest() != until {
259            return Task::none();
260        }
261        let (before, shown_before) = (state.feed.len(), state.feed.notes(mode).len());
262        match result {
263            Ok(notes) => {
264                let received = notes.len();
265                let task = self.merge_notes(id, notes);
266                let Some(state) = self.feed_mut(id) else {
267                    return task;
268                };
269                let added = state.feed.len() - before;
270                let shown = state.feed.notes(mode).len() - shown_before;
271                tracing::info!("list {id}: {received} note(s) from the relays for Older, {added} new, {shown} to show");
272                state.end_reached = added == 0;
273                // Nothing to show in the page: whoever scrolled here has
274                // nothing new under them to scroll to, so the list goes on
275                // by itself, for a while.
276                let further = if shown > 0 || added == 0 {
277                    state.barren_pages = 0;
278                    Task::none()
279                } else {
280                    state.barren_pages = state.barren_pages.saturating_add(1);
281                    if state.paused() { Task::none() } else { self.fetch_feed(id, FeedPage::Older) }
282                };
283                Task::batch([task, further])
284            }
285            Err(e) => {
286                tracing::error!("list {id} could not be fetched for Older: {e:?}");
287                self.error_message = Some(fetch_error_text(e));
288                Task::none()
289            }
290        }
291    }
292
293    /// Whether the list `id` is what the popup shows, or would if it were
294    /// open.
295    fn list_on_show(&self, id: u64) -> bool {
296        match self.view_state {
297            ViewState::Feed => self.following.id == id,
298            ViewState::Page => self.profile_on_top().is_some_and(|profile| profile.notes.id == id),
299            _ => false,
300        }
301    }
302
303    /// Show the notes that wait for the list `id`, which its reader asked
304    /// for, and bring the list to its top, where they are.
305    ///
306    /// Notes that reach down to the list's newest go in above it. Notes
307    /// that may not start the list over: it is then those, and what is
308    /// older comes back as the list is scrolled to its end.
309    pub fn show_new_notes(&mut self, id: u64) -> Task<cosmic::Action<Message>> {
310        let Some(state) = self.feed_mut(id) else {
311            return Task::none();
312        };
313        let (notes, detached) = state.pending.take();
314        if notes.is_empty() {
315            return Task::none();
316        }
317        if detached {
318            state.feed = Feed::default();
319            state.heights = RowHeights::default();
320            state.end_reached = false;
321            state.barren_pages = 0;
322        }
323        // Where it is read from when it next shows, if it isn't showing.
324        state.position.set(0.0);
325        let to_top = if self.list_on_show(id) { scroll_list_to(0.0) } else { Task::none() };
326        Task::batch([self.merge_notes(id, notes), to_top, self.look_back_if_nothing_to_show(id)])
327    }
328
329    /// It is time to look for new notes for the feed. Whatever there is
330    /// waits to be asked for.
331    pub fn handle_check_for_new_notes(&mut self) -> Task<cosmic::Action<Message>> {
332        // Not before the feed was filled once: that is under way, or has
333        // nobody to fill it for.
334        if !self.following.settled {
335            return Task::none();
336        }
337        self.feed_checked_at = Some(Instant::now());
338        // What is new for the account is looked for at the same time.
339        Task::batch([self.fetch_feed(self.following.id, FeedPage::Newest), self.check_notifications()])
340    }
341
342    /// Look for new notes for the feed now, if that was not done just
343    /// now: the popup opened, and whoever opened it is about to look.
344    pub(crate) fn check_for_new_notes_if_stale(&mut self) -> Task<cosmic::Action<Message>> {
345        match self.feed_checked_at {
346            Some(checked) if checked.elapsed() < NEW_NOTES_FRESH => Task::none(),
347            _ => self.handle_check_for_new_notes(),
348        }
349    }
350
351    /// The list `id` was scrolled near its end, or asked to look further
352    /// back: the page before its oldest note, however many pages before
353    /// brought nothing to show.
354    pub fn handle_load_older_notes(&mut self, id: u64) -> Task<cosmic::Action<Message>> {
355        if let Some(state) = self.feed_mut(id) {
356            state.barren_pages = 0;
357        }
358        self.fetch_feed(id, FeedPage::Older)
359    }
360
361    /// Look further back for the list `id` if it has notes and none of
362    /// them to show: nothing is there to scroll to the end of, which is
363    /// what otherwise asks for the next page.
364    fn look_back_if_nothing_to_show(&mut self, id: u64) -> Task<cosmic::Action<Message>> {
365        let mode = self.config.feed_mode;
366        match self.feed_mut(id) {
367            Some(state) if state.feed.notes(mode).is_empty() && !state.feed.is_empty() && !state.paused() => {
368                self.fetch_feed(id, FeedPage::Older)
369            }
370            _ => Task::none(),
371        }
372    }
373
374    /// Which notes the lists show was chosen, above one of them: `chosen`
375    /// is that choice in the control. Kept, and shown from now on.
376    pub fn handle_select_feed_mode(&mut self, chosen: segmented_button::Entity) -> Task<cosmic::Action<Message>> {
377        let Some(mode) = self.feed_modes.data::<FeedMode>(chosen).copied() else {
378            return Task::none();
379        };
380        self.feed_modes.activate(chosen);
381        if mode == self.config.feed_mode {
382            return Task::none();
383        }
384        self.config.feed_mode = mode;
385        self.save_config("feed mode");
386        self.show_feed_mode()
387    }
388
389    /// Show every list as [`crate::config::Config::feed_mode`] has it,
390    /// which just changed: the control says so, and each list starts
391    /// counting pages with nothing to show over again, looking back at
392    /// once if it has nothing. The feed, if it is on show, is read from
393    /// its top.
394    pub(crate) fn show_feed_mode(&mut self) -> Task<cosmic::Action<Message>> {
395        let mode = self.config.feed_mode;
396        if let Some(position) = FeedMode::ALL.iter().position(|offered| *offered == mode) {
397            self.feed_modes.activate_position(position as u16);
398        }
399        let mut lists = vec![self.following.id];
400        lists.extend(self.profiles_mut().map(|profile| profile.notes.id));
401        let mut tasks = Vec::new();
402        for id in lists {
403            if let Some(state) = self.feed_mut(id) {
404                state.barren_pages = 0;
405            }
406            tasks.push(self.look_back_if_nothing_to_show(id));
407        }
408        if self.view_state == ViewState::Feed {
409            tasks.push(scroll_list_to(0.0));
410        }
411        Task::batch(tasks)
412    }
413
414    /// Refresh was pressed: the newest notes of the feed, shown as soon as
415    /// they are here, with whatever waited already. While who is followed
416    /// isn't known, that is asked first.
417    pub fn handle_refresh_feed(&mut self) -> Task<cosmic::Action<Message>> {
418        if self.follows.is_none() {
419            return self.load_contacts();
420        }
421        self.following.show_when_fetched = true;
422        self.feed_checked_at = Some(Instant::now());
423        // One may be on its way already, asked for in passing: it will do.
424        self.fetch_feed(self.following.id, FeedPage::Newest)
425    }
426
427    /// Scroll the feed to where it was left: the scroller has the place of
428    /// whatever list it showed last.
429    pub(crate) fn restore_feed_position(&self) -> Task<cosmic::Action<Message>> {
430        scroll_list_to(self.following.position.get())
431    }
432
433    /// Add `notes` to the list `id`, if it is still there, and look up the
434    /// people they are shown with (authors, and those mentioned) and what
435    /// was made of them.
436    pub(crate) fn merge_notes(&mut self, id: u64, notes: Vec<Note>) -> Task<cosmic::Action<Message>> {
437        let Some(state) = self.feed_mut(id) else {
438            return Task::none();
439        };
440        let ids: Vec<EventId> = notes.iter().map(|note| note.id).collect();
441        let people = state.feed.merge(notes);
442        Task::batch([self.look_up_people(people), self.look_up_engagement(ids)])
443    }
444
445    /// Look up the profiles of those of `people` who were not asked about
446    /// yet: first in the event store, which answers at once.
447    pub(crate) fn look_up_people(&mut self, people: Vec<PublicKey>) -> Task<cosmic::Action<Message>> {
448        // Without the store nobody is asked about, and nobody counts as
449        // asked about either.
450        let Some(service) = self.nostr.clone() else {
451            return Task::none();
452        };
453        let people: Vec<PublicKey> = people.into_iter().filter(|person| self.profiles_requested.insert(*person)).collect();
454        if people.is_empty() {
455            return Task::none();
456        }
457        Task::perform(
458            async move {
459                let found = service.cached_profiles(people.clone()).await;
460                (people, found)
461            },
462            |(requested, found)| cosmic::Action::App(Message::ProfilesCached { requested, found }),
463        )
464    }
465
466    /// Profiles were read from the event store. Ask the relays for the
467    /// authors it didn't know.
468    pub fn handle_profiles_cached(
469        &mut self,
470        requested: Vec<PublicKey>,
471        found: Vec<(PublicKey, Profile)>,
472    ) -> Task<cosmic::Action<Message>> {
473        let checked = self.keep_profiles(found);
474        let missing: Vec<PublicKey> = requested.into_iter().filter(|author| !self.profiles.contains_key(author)).collect();
475        let Some(service) = self.nostr.clone() else {
476            return checked;
477        };
478        if missing.is_empty() {
479            return checked;
480        }
481        Task::batch([checked, fetch_profiles(service, missing)])
482    }
483
484    /// Profiles arrived, as they stand now.
485    pub fn handle_profiles_fetched(&mut self, found: Vec<(PublicKey, Profile)>) -> Task<cosmic::Action<Message>> {
486        tracing::debug!("profiles: {} arrived", found.len());
487        self.keep_profiles(found)
488    }
489
490    /// Keep `found` as what is known of those people. Those of them whose
491    /// profile is open may have a name to check that they hadn't before.
492    fn keep_profiles(&mut self, found: Vec<(PublicKey, Profile)>) -> Task<cosmic::Action<Message>> {
493        let people: Vec<PublicKey> = found.iter().map(|(person, _)| *person).collect();
494        self.profiles.extend(found);
495        Task::batch(people.into_iter().map(|person| self.check_nip05(person)))
496    }
497
498    // =========================================================================
499    // Who the account follows
500    // =========================================================================
501
502    /// Forget who is followed and the feed made of their notes: the account
503    /// changed. Anything still on its way for the old one is dropped.
504    pub(crate) fn reset_following(&mut self) {
505        self.follows = None;
506        self.following = self.new_feed();
507    }
508
509    /// Find out about the account: who it follows, which fills the feed,
510    /// what it says of itself, which is its picture above the feed, and,
511    /// if the popup is open, what it has bookmarked. Does nothing until
512    /// both the account and the store are there; it is called when either
513    /// arrives.
514    pub(crate) fn load_account(&mut self) -> Task<cosmic::Action<Message>> {
515        let Some(account) = self.account.as_ref().map(|account| account.public_key) else {
516            return Task::none();
517        };
518        Task::batch([
519            self.use_account_relays(),
520            self.load_contacts(),
521            self.look_up_people(vec![account]),
522            self.load_bookmarks(),
523            self.load_relay_lists(&ALWAYS_READ),
524            self.load_drafts(),
525            self.load_notifications(),
526        ])
527    }
528
529    /// Have the relays the account's relay list says it writes to join
530    /// its own: where its lists are, and where what it writes goes. Nothing
531    /// waits for it: until they have joined, the relays the config names
532    /// are the account's own.
533    fn use_account_relays(&self) -> Task<cosmic::Action<Message>> {
534        let (Some(service), Some(account)) = (self.nostr.clone(), self.account.as_ref().map(|account| account.public_key)) else {
535            return Task::none();
536        };
537        Task::future(async move {
538            service.use_relays_of(Some(account)).await;
539        })
540        .discard()
541    }
542
543    /// Find out who the account follows: from the store now, from the relays
544    /// after.
545    fn load_contacts(&mut self) -> Task<cosmic::Action<Message>> {
546        let (Some(service), Some(account)) = (self.nostr.clone(), self.account.as_ref().map(|account| account.public_key)) else {
547            return Task::none();
548        };
549        let feed = self.following.id;
550        Task::perform(async move { service.cached_contacts(account).await }, move |follows| {
551            cosmic::Action::App(Message::ContactsLoaded { feed, source: Source::Store, result: Ok(follows) })
552        })
553    }
554
555    /// The account's contact list was read from the store, or came back
556    /// from the relays, asked for the feed `feed`: if that is not the feed
557    /// any more, neither is the answer.
558    pub fn handle_contacts_loaded(
559        &mut self,
560        feed: u64,
561        source: Source,
562        result: Result<Option<Vec<PublicKey>>, FetchError>,
563    ) -> Task<cosmic::Action<Message>> {
564        if feed != self.following.id {
565            return Task::none();
566        }
567        match (source, result) {
568            // What the store knows shows at once; the relays are asked
569            // whether there is a newer list either way.
570            (Source::Store, result) => {
571                let shown = match result {
572                    Ok(Some(follows)) => self.set_follows(follows),
573                    _ => Task::none(),
574                };
575                let (Some(service), Some(account)) =
576                    (self.nostr.clone(), self.account.as_ref().map(|account| account.public_key))
577                else {
578                    return shown;
579                };
580                let feed = self.following.id;
581                let asked = Task::perform(async move { service.fetch_contacts(account).await }, move |result| {
582                    cosmic::Action::App(Message::ContactsLoaded { feed, source: Source::Relays, result })
583                });
584                Task::batch([shown, asked])
585            }
586            (Source::Relays, Ok(Some(follows))) => self.set_follows(follows),
587            // No list anywhere: the account follows nobody.
588            (Source::Relays, Ok(None)) => match self.follows {
589                None => self.set_follows(Vec::new()),
590                Some(_) => Task::none(),
591            },
592            (Source::Relays, Err(e)) => {
593                tracing::error!("the contact list could not be fetched: {e:?}");
594                // With a list from the store there is still a feed to show.
595                if self.follows.is_none() {
596                    self.error_message = Some(fetch_error_text(e));
597                }
598                Task::none()
599            }
600        }
601    }
602
603    /// The account follows `follows`. If that is news, the feed starts over
604    /// with them.
605    pub(crate) fn set_follows(&mut self, follows: Vec<PublicKey>) -> Task<cosmic::Action<Message>> {
606        if self.follows.as_ref() == Some(&follows) {
607            return Task::none();
608        }
609        tracing::info!("following {} account(s)", follows.len());
610        self.following = self.new_feed();
611        self.follows = Some(follows);
612        self.load_feed(self.following.id)
613    }
614}
615
616/// Why a request to the relays failed, in the user's language.
617pub(crate) fn fetch_error_text(error: FetchError) -> String {
618    match error {
619        FetchError::NoRelayReachable => fl!("error-no-relay"),
620        FetchError::Failed(error) => fl!("error-feed", error = error),
621        FetchError::Incomplete => fl!("error-feed", error = fl!("error-relays-incomplete")),
622    }
623}