cosmic_applet_avestruz/guide/flows.rs
1// SPDX-License-Identifier: MIT
2
3//! What happens, step by step. Documentation only.
4//!
5//! Each flow here crosses several modules, and none of them is the place
6//! to tell it whole. The diagrams name the parts as
7//! [`crate::guide::architecture`] does; under each flow is where its code
8//! is.
9//!
10//! 1. [Signing in](#signing-in)
11//! 2. [Signing, and reading what is private](#signing-and-reading-what-is-private)
12//! 3. [Filling the feed](#filling-the-feed)
13//! 4. [New notes, and older ones](#new-notes-and-older-ones)
14//! 5. [Opening a thread](#opening-a-thread)
15//! 6. [Publishing](#publishing)
16//! 7. [Reacting and reposting](#reacting-and-reposting)
17//! 8. [Changing a list: follows, bookmarks, relays](#changing-a-list-follows-bookmarks-relays)
18//! 9. [Searching](#searching)
19//! 10. [Zapping](#zapping)
20//! 11. [Drafts](#drafts)
21//! 12. [Pictures and link previews](#pictures-and-link-previews)
22//! 13. [Playing a video](#playing-a-video)
23//! 14. [Notifications](#notifications)
24//! 15. [Sweeping the store](#sweeping-the-store)
25//!
26//! Two patterns come back in nearly all of them, and are worth knowing
27//! first:
28//!
29//! - **The store first, the relays after.** Whatever is asked is asked of
30//! the event store, which answers within the frame, and of the relays,
31//! which answer when they do. What the relays send goes into the store,
32//! so the second time the store has it. [`Source`] says which of the two
33//! an answer is from.
34//! - **Shown at once, sent behind.** What the reader does shows at once (a
35//! reaction, a bookmark, a follow), and goes out behind it. If it
36//! doesn't go out, it is taken back, and the reason is said.
37//!
38//! [`Source`]: crate::nostr::client::Source
39//!
40//! # Signing in
41//!
42//! One field takes whatever identifies an account, and what was typed
43//! decides how much the account can do.
44//!
45//! ```mermaid
46//! flowchart TD
47//! typed["What is typed in the sign-in field"] --> parse{"What is it?"}
48//! parse -->|"an nsec"| secret["The key goes to the keyring, under its npub"]
49//! parse -->|"an npub"| public["Nothing is kept"]
50//! parse -->|"a bunker address"| bunker["The remote signer is connected to, as the client key it knows"]
51//! parse -->|"none of these"| wrong["Said under the field, and nothing happens"]
52//! secret -->|"the keyring took it"| full["Signed in, with full access"]
53//! secret -->|"the keyring refused"| nobody["Nobody is signed in, and the key is kept nowhere"]
54//! public --> readonly["Signed in, read-only"]
55//! bunker -->|"the signer agrees"| address["Its address goes to the keyring, without its one-time secret"]
56//! bunker -->|"it refuses, or the wait is called off"| refused["Nobody is signed in. The client key is shown, to be authorized at the signer"]
57//! address --> full
58//! full --> named["The config names the account by its npub"]
59//! readonly --> named
60//! ```
61//!
62//! Waiting for a remote signer may be waiting for a person to press a
63//! button on a phone, so it can be called off, and the view says what is
64//! being waited for ([`LoginProgress`](crate::state::LoginProgress)).
65//!
66//! At the next start the config's `npub` is looked up in the keyring
67//! ([`restore`](crate::nostr::account::restore)): if something is kept
68//! for it the account has full access, and if not it is read-only.
69//! Nothing is connected to and nothing is decrypted to find that out.
70//!
71//! Where: [`crate::nostr::account`] (the three ways in, and the keyring),
72//! [`crate::handlers::auth`], [`crate::views::login`].
73//!
74//! # Signing, and reading what is private
75//!
76//! Everything that needs the account's secret key goes through one
77//! [`Signer`](crate::nostr::account::Signer): signing an event, encrypting
78//! to the account itself, decrypting what it encrypted. It goes one of two
79//! ways, and the caller doesn't know which.
80//!
81//! ```mermaid
82//! sequenceDiagram
83//! participant caller as A handler
84//! participant signer as Signer
85//! participant keyring as Keyring
86//! participant remote as Remote signer
87//! caller->>signer: sign this, as the account
88//! alt the account signed in with an nsec
89//! signer->>keyring: the key
90//! keyring-->>signer: the key
91//! signer->>signer: signs, and lets go of the key
92//! else it signed in with a bunker address
93//! opt not connected yet in this run
94//! signer->>keyring: the address, and this client's key for that signer
95//! signer->>remote: connect (NIP-46)
96//! end
97//! signer->>remote: sign this
98//! Note over remote: may ask a person
99//! remote-->>signer: the signed event, or no
100//! end
101//! signer-->>caller: the event, or why not
102//! ```
103//!
104//! With an `nsec` the key is in memory for the length of one signature.
105//! With a remote signer every request may reach a person, which is the
106//! reason for a rule that shows up all over this page: **what takes the
107//! key is not asked for before someone is looking, and not asked for
108//! twice.** The bookmarks, the private half of the relay lists and the
109//! drafts are read when the popup opens, not when the applet starts, and
110//! a list that was decrypted once is not decrypted again while it is the
111//! newest.
112//!
113//! # Filling the feed
114//!
115//! The feed is the notes of the people the account follows, so it starts
116//! with who that is: the account's contact list.
117//!
118//! ```mermaid
119//! sequenceDiagram
120//! participant model as AppModel
121//! participant store as Event store
122//! participant own as The account's relays
123//! participant theirs as Other people's relays
124//! model->>store: the account's contact list
125//! store-->>model: the one it has: who is followed
126//! model->>own: the account's contact list
127//! Note over model: a new answer to that starts the feed over, as a new list
128//! model->>store: the newest notes of those people
129//! store-->>model: shown at once
130//! par everyone, from the account's own relays
131//! model->>own: the newest notes of everyone followed
132//! own-->>model: notes
133//! and each, from where they write
134//! model->>theirs: the newest notes of those who write there
135//! theirs-->>model: notes
136//! end
137//! Note over model: merged, newest first. The feed has been filled, and is its reader's from here on
138//! model->>store: what was made of these notes? who wrote them?
139//! model->>own: the same
140//! ```
141//!
142//! Which of other people's relays are asked, and how few, is in
143//! [`crate::guide::relays`]. A page is
144//! [`FEED_PAGE`](crate::nostr::client::FEED_PAGE) notes. The notes a note
145//! quotes are looked for before the note is shown, so that a card doesn't
146//! turn up later in a row that is being read.
147//!
148//! A profile's notes are a list like the feed's, of one person, and are
149//! filled the same way by the same code: both are a
150//! [`FeedState`](crate::state::FeedState).
151//!
152//! Where: [`crate::handlers::feed`], [`crate::nostr::feed`],
153//! [`NostrService::cached_feed`](crate::nostr::client::NostrService::cached_feed)
154//! and [`fetch_feed`](crate::nostr::client::NostrService::fetch_feed).
155//!
156//! # New notes, and older ones
157//!
158//! Once a list has been filled, what it shows only changes when its
159//! reader says so. The feed is looked at again every minute while the
160//! popup is open and every five while it is closed, and once when the
161//! popup opens; what turned up waits beside the list
162//! ([`Pending`](crate::nostr::feed::Pending)) and is offered by a button
163//! over it.
164//!
165//! ```mermaid
166//! stateDiagram-v2
167//! [*] --> Filling: the list is new
168//! Filling --> Settled: the relays answered once, or failed to
169//! Settled --> Offering: a look found notes the list doesn't have
170//! Offering --> Offering: another look found more
171//! Offering --> Settled: the button, or Refresh. They are shown, and the list goes to its top
172//! Settled --> Settled: scrolled near its end. An older page goes in below
173//! ```
174//!
175//! Nothing is ever put in *above* what is being read without being asked
176//! for, and an older page goes in below, so the rows on screen stay where
177//! they are. That is one half of keeping a list still; the other half is
178//! in how rows are measured (see [`crate::guide::decisions`]).
179//!
180//! A list has no holes. If more turned up than one page holds, the notes
181//! that wait don't reach down to the list's newest, and showing them
182//! starts the list over from them rather than leave a gap nobody could
183//! see: what is older comes back as the list is scrolled to its end.
184//!
185//! A list is read with replies or without
186//! ([`FeedMode`](crate::nostr::feed::FeedMode)). Read without, an older
187//! page may bring only replies, which is nothing to show: the list then
188//! looks further back on its own, up to
189//! [`BARREN_PAGES_MAX`](crate::state::BARREN_PAGES_MAX) pages, and after
190//! that when asked.
191//!
192//! # Opening a thread
193//!
194//! A thread opens for one note, the *focused* one, from wherever the note
195//! was named: a row, a quoted card, a `nostr:` reference in a note's text,
196//! an address typed in a search.
197//!
198//! ```mermaid
199//! sequenceDiagram
200//! participant reader as Reader
201//! participant model as AppModel
202//! participant store as Event store
203//! participant relays as Relays
204//! reader->>model: opens a note
205//! model->>model: a new page, with the note itself if it came from a row
206//! par
207//! model->>store: the note, what it answers, what answers it
208//! store-->>model: within the frame
209//! and
210//! model->>relays: the same
211//! relays-->>model: when they answer
212//! end
213//! Note over model: each answer is merged in: every note under the one it answers
214//! ```
215//!
216//! The relays asked are the account's own, the relays the note's author
217//! writes to, the relay its address named if it named one, and the relays
218//! of the first few people the conversation involves
219//! ([`THREAD_PEOPLE`](crate::nostr::client::THREAD_PEOPLE)): a
220//! conversation is on the relays of those who had it.
221//!
222//! Where: [`crate::handlers::thread`], [`crate::nostr::thread`] (the
223//! ordering, which is pure), and
224//! [`NostrService::thread`](crate::nostr::client::NostrService::thread).
225//!
226//! # Publishing
227//!
228//! A note, a reply and a quote are written in the same composer and go
229//! out the same way. Before it goes out, what is written can be looked at
230//! as it would show: what would be sent is read as a note is, with no key
231//! asked for and nothing sent (see [`crate::handlers::compose`]).
232//!
233//! ```mermaid
234//! sequenceDiagram
235//! participant reader as Reader
236//! participant model as AppModel
237//! participant signer as Signer
238//! participant own as The account's relays
239//! participant theirs as The relays of those it names
240//! participant store as Event store
241//! reader->>model: Publish
242//! model->>model: the text, and what it answers, made into an unsigned event
243//! model->>signer: sign
244//! signer-->>model: the event
245//! par
246//! model->>own: the event
247//! own-->>model: took it, or why not
248//! and
249//! model->>theirs: the event
250//! theirs-->>model: took it, or didn't
251//! end
252//! alt at least one relay took it
253//! model->>store: kept
254//! model->>reader: it shows: at the top of the feed, or in its place in the thread
255//! model->>model: its draft is done with
256//! else none did
257//! model->>reader: the composer stays as it was, with the reason
258//! end
259//! ```
260//!
261//! What a reply is depends on what it answers: an answer to a text note
262//! is a text note (NIP-10), an answer to anything else is a comment
263//! (NIP-22). To build either, the note answered is needed whole, and it is
264//! taken from the store; if the store has let go of it since it was shown
265//! (see [sweeping](#sweeping-the-store)), the relays are asked for it
266//! again ([`NostrService::event`](crate::nostr::client::NostrService::event)).
267//!
268//! Where: [`crate::handlers::compose`], [`crate::nostr::compose`] (the
269//! event, which is pure), and
270//! [`NostrService::publish`](crate::nostr::client::NostrService::publish).
271//!
272//! # Reacting and reposting
273//!
274//! ```mermaid
275//! sequenceDiagram
276//! participant reader as Reader
277//! participant model as AppModel
278//! participant config as COSMIC config
279//! participant signer as Signer
280//! participant relays as Relays
281//! reader->>model: presses the heart under a note
282//! model->>reader: a row: a like, the emoji used most, and a way to all the others
283//! opt none of those
284//! reader->>model: asks for all the others
285//! model->>reader: every emoji, by group, and a field to find one by
286//! end
287//! reader->>model: presses one
288//! model->>config: if it is an emoji: used once more, and when
289//! model->>reader: it is in the heart's place, and the count goes up, at once
290//! model->>model: the reaction is remembered as on its way
291//! model->>signer: sign a reaction that says it
292//! signer-->>model: the event
293//! model->>relays: the event
294//! alt a relay took it
295//! model->>model: no longer on its way. The store has it, and counts it
296//! else none did, or it could not be signed
297//! model->>reader: the heart is empty again, and a banner says why
298//! end
299//! ```
300//!
301//! What is offered to react with is over the list, as a menu is
302//! ([`AppModel::reaction_menu`](crate::state::AppModel::reaction_menu)):
303//! nothing under it moves, a click beside it or Escape puts it away, and
304//! so does closing the popup. The emoji offered first are the ones used
305//! most, and of those used as often the ones used last
306//! ([`crate::emoji::suggested`]); which were used is one of the settings
307//! ([`Config::reaction_emojis`](crate::config::Config::reaction_emojis)),
308//! noted when an emoji is pressed, whatever comes of the reaction.
309//!
310//! While a reaction is on its way, a count that arrives from the relays
311//! without it would take it off the screen again; remembering it
312//! ([`AppModel::pending_marks`](crate::state::AppModel::pending_marks))
313//! is what keeps it there. A repost carries the note it reposts whole, as
314//! it was signed, and says which relay has it.
315//!
316//! Where: [`crate::handlers::engagement`], [`crate::nostr::engagement`],
317//! [`crate::emoji`],
318//! [`reaction_menu`](mod@crate::views::components::reaction_menu).
319//!
320//! # Changing a list: follows, bookmarks, relays
321//!
322//! Who an account follows, what it bookmarked and which relays are its
323//! own are each a list, and a list is *replaceable*: there is one for an
324//! account, and every new one replaces the last on every relay it
325//! reaches. So a change is never "add this": it is the newest list,
326//! written again whole with one thing different. Writing it from a copy
327//! that is behind would undo whatever another client did since, and
328//! writing a first one where one exists would lose everything in it. All
329//! three go the same careful way.
330//!
331//! ```mermaid
332//! flowchart TD
333//! change["A follow, a bookmark, or Save on the relays page"] --> ask["Each of the account's relays is asked for the list again"]
334//! ask --> found{"Is there a list?"}
335//! found -->|"yes"| read{"Can what it keeps to itself be read?"}
336//! found -->|"no, and every relay answered"| first{"Was the account told, and did it say again?"}
337//! found -->|"no, but a relay didn't answer"| stop1["Nothing is written: that relay may be the one that has it"]
338//! first -->|"not yet"| tell["Nothing is written. A banner says a first list would replace any kept elsewhere"]
339//! first -->|"yes"| write
340//! read -->|"yes, or it keeps nothing to itself"| write["The list is written again with the one change, everything else as it was"]
341//! read -->|"no"| stop2["Nothing is written: a list written without it would lose it"]
342//! write --> sign["Encrypted to the account if it is private, signed, and sent to the account's relays"]
343//! sign --> shown["The model takes the list that was sent as the newest"]
344//! ```
345//!
346//! "Everything else as it was" is meant strictly: tags this client
347//! doesn't know, the public half of a bookmark list (which is never read
348//! here), the content older clients kept their relays in, the order.
349//! Other clients keep things in these lists, and each finds what the
350//! other left.
351//!
352//! One change is made at a time: the next is made to the list the last
353//! one left.
354//!
355//! Where: [`crate::nostr::contacts`], [`crate::nostr::bookmarks`],
356//! [`crate::nostr::relay_lists`] (the lists, pure);
357//! [`NostrService::set_following`](crate::nostr::client::NostrService::set_following),
358//! [`set_bookmarked`](crate::nostr::client::NostrService::set_bookmarked),
359//! [`set_advertised_relays`](crate::nostr::client::NostrService::set_advertised_relays)
360//! and [`set_listed_relays`](crate::nostr::client::NostrService::set_listed_relays);
361//! and the handlers of [`crate::handlers::profile`],
362//! [`crate::handlers::bookmarks`] and [`crate::handlers::relays`].
363//!
364//! # Searching
365//!
366//! What is typed on the search page is looked at before anything is sent
367//! anywhere, because much of what can be typed there is not a search.
368//!
369//! ```mermaid
370//! flowchart TD
371//! typed["What is typed, and Enter"] --> what{"What is it?"}
372//! what -->|"an nsec, or a bunker address"| secret["Cleared from the field, and sent nowhere"]
373//! what -->|"an npub or nprofile"| person["That person's profile opens"]
374//! what -->|"a note or nevent"| note["That note's thread opens, looked for where the address says"]
375//! what -->|"name@domain"| name["The domain is asked whose it is, and their profile opens"]
376//! what -->|"wss://..."| relay["That relay's latest notes show, with what it says of itself"]
377//! what -->|"words"| words{"Has the account search relays?"}
378//! words -->|"no"| none["The page says where to set them"]
379//! words -->|"yes"| asked["Each is asked for people and for notes, at once"]
380//! asked --> ranked["Their answers are taken a rank at a time, and people followed come first"]
381//! ```
382//!
383//! Only the last row tells a relay anything, and the relays told are the
384//! account's own choice (its kind 10007 list): there are none built in.
385//! Nothing of a search is kept: no recent searches, and the words are not
386//! logged, which is why the relay library's wire logging is turned down in
387//! `main`.
388//!
389//! Where: [`crate::nostr::search`] (what was typed, and ranking; pure),
390//! [`crate::handlers::search`],
391//! [`NostrService::search`](crate::nostr::client::NostrService::search).
392//!
393//! # Zapping
394//!
395//! A zap is a Lightning payment that a wallet service announces on Nostr.
396//! Avestruz holds no money: it gets as far as an invoice, and shows it as
397//! a QR code for a wallet to pay.
398//!
399//! ```mermaid
400//! sequenceDiagram
401//! participant reader as Reader
402//! participant model as AppModel
403//! participant lnurl as The author's Lightning address
404//! participant wallet as A wallet, elsewhere
405//! participant relays as Relays
406//! reader->>model: zaps a note: how much, and a word
407//! model->>lnurl: what do you accept? (LNURL-pay)
408//! lnurl-->>model: how little, how much, and whether it does zaps
409//! model->>model: a zap request, signed by the account, or by a key made for it
410//! model->>lnurl: an invoice for this much, with the request
411//! lnurl-->>model: an invoice
412//! model->>model: only taken if it asks for the amount chosen
413//! model->>reader: the invoice, as a QR code
414//! reader->>wallet: scans and pays
415//! wallet-->>relays: a zap receipt (kind 9735)
416//! loop while the invoice is on show
417//! model->>relays: is there a receipt for this invoice?
418//! end
419//! relays-->>model: the receipt
420//! model->>reader: paid, and the note's count has it
421//! ```
422//!
423//! Anyone can zap: a read-only account has no key to sign the request
424//! with, so it is signed with a key made for the purpose and thrown away,
425//! and the zap is anonymous. An address that doesn't do zaps is asked for
426//! a plain invoice instead: the money arrives all the same.
427//!
428//! Where: [`crate::nostr::zap`], [`crate::handlers::zap`],
429//! [`crate::views::zap`], and
430//! [`NostrService::await_zap_receipt`](crate::nostr::client::NostrService::await_zap_receipt).
431//!
432//! # Drafts
433//!
434//! What is written and not published belongs to what it was written to: a
435//! note of its own, a reply to one note, a quote of another. Leaving the
436//! composer, or the popup closing over it, keeps it.
437//!
438//! ```mermaid
439//! sequenceDiagram
440//! participant model as AppModel
441//! participant signer as Signer
442//! participant relay as The relay Avestruz runs itself
443//! participant store as Event store
444//! participant file as draft.txt
445//! Note over model: the composer is left, or the popup closes
446//! model->>model: the text is that target's draft (for this run)
447//! model->>signer: encrypt the draft to the account, and sign its wrap
448//! alt signed
449//! model->>relay: the draft wrap (kind 31234), over a pipe inside the process
450//! relay->>store: kept, in place of the one before
451//! else it could not be, and it is the draft of a new note
452//! model->>file: the text
453//! end
454//! Note over model: later, the popup opens for the first time in a run
455//! model->>relay: the account's draft wraps
456//! relay-->>model: wraps
457//! model->>signer: decrypt each
458//! signer-->>model: the drafts, back where they were written
459//! ```
460//!
461//! A draft never leaves the machine: it is sent to the one relay nothing
462//! outside the process can reach, and to no other. A draft that was
463//! published or cleared is kept as an empty wrap, which replaces the full
464//! one.
465//!
466//! Where: [`crate::drafts`] (for the run), [`crate::nostr::kept_drafts`]
467//! (the event), [`crate::nostr::private_relay`] (the relay),
468//! [`crate::handlers::compose`].
469//!
470//! # Attaching a file
471//!
472//! A note links to a file that is somewhere: attaching one is putting it
473//! there first. Where is the account's media servers
474//! ([`crate::nostr::blossom`]), and the file goes as the picture and no
475//! more ([`crate::media`]).
476//!
477//! ```mermaid
478//! sequenceDiagram
479//! actor person as Someone
480//! participant model as AppModel
481//! participant chooser as The desktop's file chooser
482//! participant signer as Signer
483//! participant servers as The media servers
484//! person->>model: the paperclip, in the composer
485//! model->>model: the popup closes: the chooser is a window under it
486//! model->>chooser: open
487//! chooser-->>model: the files picked
488//! model->>model: the popup opens again, on the composer
489//! loop each file, all at once
490//! model->>model: read, a picture made bare, hashed
491//! model->>signer: sign an authorization for that hash
492//! model->>servers: the first that takes it is sent the file
493//! model->>servers: the others are asked to fetch it from there
494//! servers-->>model: where it is
495//! model->>model: its address goes at the end of the text
496//! end
497//! person->>model: Publish
498//! model->>model: the note says of each address still in its text what is at it
499//! ```
500//!
501//! Pasting does the same without the chooser: files copied in a file
502//! manager, or a picture copied as one. Text on the clipboard is pasted
503//! as text, as ever.
504//!
505//! A file that arrives after the composer was left goes at the end of
506//! the draft it was attached to. What the note says of a file is kept
507//! with the draft (see **Drafts**), so that it is still said after a
508//! restart.
509//!
510//! Where: [`crate::handlers::media`], [`crate::nostr::blossom`],
511//! [`crate::media`], [`crate::views::media`].
512//!
513//! # Pictures and link previews
514//!
515//! A view can't fetch anything: it is built from a model it can't change.
516//! What it finds missing, it asks for.
517//!
518//! ```mermaid
519//! sequenceDiagram
520//! participant view as A row, being built
521//! participant images as ImageStore
522//! participant channel as Requests
523//! participant update as app update
524//! participant web as A web server
525//! view->>images: the picture at this address
526//! alt it is there
527//! images-->>view: the picture
528//! else it is not
529//! images-->>view: loading: the row holds its room
530//! images->>channel: ask, once however often the row is built
531//! channel->>update: LoadImage
532//! update->>update: fetched now, if fewer than so many are on their way
533//! update->>web: the picture (https only, so many bytes at the most)
534//! web-->>update: bytes
535//! update->>update: decoded off the main thread, cut to its shape
536//! update->>images: kept, within the budget
537//! update-->>view: built again, with the picture
538//! end
539//! ```
540//!
541//! Only rows on screen are ever built
542//! ([`VirtualList`](crate::views::components::VirtualList)), so only what
543//! is on screen is ever asked for. Link previews go the same road with
544//! their own store. A picture's room is held before it arrives when the
545//! note says how large it is, so the row is the same height before and
546//! after.
547//!
548//! Where: [`crate::requests`], [`crate::images`], [`crate::previews`],
549//! [`crate::handlers::images`], [`crate::handlers::previews`],
550//! [`crate::views::components::media_placeholder`].
551//!
552//! # Playing a video
553//!
554//! A video is the one thing a row shows that is not fetched when the row
555//! comes into view. Its room is there from the start, with a play button
556//! in it; the rest waits to be pressed.
557//!
558//! ```mermaid
559//! sequenceDiagram
560//! participant row as The video's row
561//! participant update as app update
562//! participant videos as Videos, in the model
563//! participant gst as GStreamer: playbin
564//! participant web as The video's server
565//! row->>update: VideoPress(address)
566//! update->>videos: press
567//! videos->>gst: play this address (https only)
568//! gst->>web: the video, as much as it needs
569//! Note over update,videos: a timer runs while there is a video to look at
570//! loop thirty times a second while it plays
571//! update->>videos: VideoTick
572//! videos->>gst: the newest picture? how far in? ended, failed?
573//! gst-->>videos: an RGBA frame, the position
574//! update-->>row: built again: the frame, the bar
575//! row->>videos: shown (which keeps it playing)
576//! end
577//! row->>update: VideoSeeking, VideoSeek, VideoMute, VideoVolume, VideoSpeed, VideoPress again
578//! update->>videos: go there, mute, this loud, this fast, hold or let go
579//! ```
580//!
581//! The row saying it is shown is what holds a video that is not: a row
582//! scrolled out of view is not built, nor is the list while another view
583//! is in its place, and after a few builds of the popup without it, and a
584//! moment, the video is held. The popup closing holds it at once. Another
585//! video pressed takes its place: one plays at a time.
586//!
587//! Which links are videos is settled when the note is read: by how the
588//! address ends, or by what the note says of it (NIP-92). A link that
589//! gives nothing away is asked for its preview like any page, and if its
590//! server calls it a video, the card it gets offers to play it.
591//!
592//! A link to a YouTube video is a video by its address, and the one kind
593//! that can't be played from it: what is there is a page. Pressed, it is
594//! on its way while yt-dlp, a program of its own, is asked for a stream
595//! of it; then that is played as any video. The diagram of that is in
596//! [`crate::youtube`].
597//!
598//! Where: [`crate::video`], [`crate::youtube`],
599//! [`crate::handlers::video`], [`crate::nostr::content`],
600//! [`crate::views::components::video_box`](mod@crate::views::components::video_box),
601//! [`crate::views::components::link_preview`](mod@crate::views::components::link_preview).
602//!
603//! # Notifications
604//!
605//! What others did that concerns the account is every event that names
606//! it: found the way a feed is, and read for what it is.
607//!
608//! ```mermaid
609//! sequenceDiagram
610//! participant reader as Reader
611//! participant model as AppModel
612//! participant config as COSMIC config
613//! participant store as Event store
614//! participant relays as Its own relays, and the ones it reads
615//! participant wallet as Its Lightning address
616//! Note over model: the account is known
617//! model->>store: the newest events that name it
618//! store-->>model: a page, each read with the note it is about
619//! model->>relays: the same question
620//! relays-->>model: a page: what is new to the model is merged in
621//! model->>wallet: which key signs its zap receipts? Once
622//! wallet-->>model: the key: the zaps it signed show from now on
623//! loop each time the feed is looked at for new notes
624//! model->>relays: what was written since the newest known, and a while before
625//! relays-->>model: what there is
626//! end
627//! model->>reader: how many were written since the last look, on the bell, and a dot on the panel button
628//! reader->>model: opens the notifications
629//! model->>config: looked at: now
630//! model->>reader: the list, with what was new before this visit picked out
631//! reader->>model: leaves the page, or closes the popup
632//! model->>config: looked at: now, so that what arrived meanwhile is not new next time
633//! ```
634//!
635//! A reaction or a repost names its author's key whoever it is to, so
636//! the note it is about is fetched too: it is told of when that note is
637//! the account's, or could not be found. A page that is as long as was
638//! asked for and ends after everything known has a gap behind it: what
639//! is older is let go of, and comes back when the list is scrolled to
640//! its end, so that nothing is ever put in above what was read.
641//!
642//! Looking is having the page on show in an open popup, whatever made it
643//! so. That is watched in one place, after every message
644//! ([`AppModel::watch_notifications`](crate::state::AppModel::watch_notifications)),
645//! and not in each of the ways a page comes and goes.
646//!
647//! Where: [`crate::handlers::notifications`],
648//! [`crate::nostr::notifications`],
649//! [`NostrService::notifications`](crate::nostr::client::NostrService::notifications),
650//! [`crate::views::notifications`],
651//! [`notification_row`](mod@crate::views::components::notification_row).
652//!
653//! # Sweeping the store
654//!
655//! Everything a relay sends is kept. Once a day the store lets go of what
656//! is older than the settings say and can be asked for again.
657//!
658//! ```mermaid
659//! flowchart TD
660//! tick["Every hour, when the bookmarks become known, and when the setting changes"] --> due{"Swept within the day, or set to keep everything?"}
661//! due -->|"yes"| nothing["Nothing"]
662//! due -->|"no"| known{"Is it known what stays?"}
663//! known -->|"the bookmarks were read"| sweep
664//! known -->|"read-only: there are none here"| sweep
665//! known -->|"not read yet, or unreadable"| nothing
666//! sweep["What is older than the limit, a page at a time"] --> each{"For each event"}
667//! each -->|"the account wrote it"| stays["Stays"]
668//! each -->|"replaceable or addressable: a profile, a list"| stays
669//! each -->|"the account bookmarked it"| stays
670//! each -->|"anything else"| goes["Goes"]
671//! ```
672//!
673//! Nothing on show changes when the store is swept: the lists are in the
674//! model. A note that is still on screen after it was swept can still be
675//! answered or reposted, since the relays are asked for it again.
676//!
677//! Where: [`crate::nostr::sweep`], [`crate::handlers::store`].