Files
Febe/src/Febe.Core/Collection/Search/SearchModels.cs
T
Alby96andClaude Opus 5.5 9941a2fa1f
verifica / controlli (push) Successful in 20s
verifica / prove (push) Failing after 19m40s
verifica / installatore (push) Skipped
verifica / immagine (push) Skipped
Ricerca dei profili con suggerimenti e foto (#37)
«Aggiungi account» ha una sola casella: mentre Alberto scrive compaiono
subito i suggerimenti locali, poi i profili di Instagram con la foto, come
chiesto in #37. Il browser di Febe scrive nella casella «Cerca» di Instagram
con tasti veri da una mappa chiusa (mai Invio, Tab o Esc), controlla prima
il fuoco, legge la risposta della pagina e non clicca mai un risultato.

La ricerca ha una categoria propria nel Governatore, con tetti larghi che
non consumano quelli della raccolta, e si dà il turno con il motore
sull'unica pagina; a fine sessione la pagina torna comunque al riposo. Le
foto passano dal CDN con un permesso ciascuna e restano solo in memoria.

Le risposte di Alberto del 15 novembre (controllo del fuoco, turni, evento
requestWillBeSent, niente foto dei seguiti per ora) sono in §6.1 e in
docs/decisioni.md. Su Instagram vero la ricerca parte quando i bersagli
search-open e search-box saranno raccolti dal vivo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:30:03 +01:00

129 lines
4.8 KiB
C#

using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace Febe.Core.Collection.Search;
/// <summary>What the profile search is doing for the wanted text (issue #37). The interface shows it in Italian.</summary>
public enum SearchState
{
/// <summary>Nothing wanted (empty box, dialog closed).</summary>
Idle,
/// <summary>The text is not one Febe types on the site (several names, too short, other characters): local suggestions only.</summary>
LocalOnly,
/// <summary>Waiting for the page: a collection step holds it, or the search spacing.</summary>
Waiting,
/// <summary>Febe is typing on the site or waiting for its answer.</summary>
Searching,
/// <summary>The site answered with profiles.</summary>
Ready,
/// <summary>The site answered with no profile.</summary>
Empty,
/// <summary>No answer of the site came for this text (it may have answered from its own memory).</summary>
NoAnswer,
/// <summary>Alberto is using Febe's browser: the search on the site waits.</summary>
NotPossible,
/// <summary>Outside the active window Febe does not open the site.</summary>
OutsideWindow,
/// <summary>The breaker is open (spec §7.6), or the search's own budget is used up.</summary>
Stopped,
/// <summary>The browser or the engine is not up.</summary>
Unavailable,
/// <summary>The map of the site lacks the search targets, or the readers lack the search answer (H11).</summary>
NotConfigured,
/// <summary>The text holds a character Febe never types (a control character).</summary>
Refused,
/// <summary>A step went wrong; the next text tries again.</summary>
Failed,
}
/// <summary>Closed list of how one search step ended: diagnostics count these names, never a text (issue #37).</summary>
public enum SearchOutcome
{
Ready,
Empty,
NoAnswer,
Cached,
Refused,
Stopped,
NotConfigured,
NotConnected,
OutsideWindow,
TargetMissing,
FocusLost,
KeysNotReceived,
PageNotLoaded,
BrowserNotResponding,
Interrupted,
NotPossible,
Denied,
}
/// <summary>
/// One profile the search found or knows. Never printed with its values: the record prints only counts and flags.
/// </summary>
/// <param name="Position">Order in the site's answer, from 0.</param>
/// <param name="InstagramId">The site's identifier of the profile.</param>
/// <param name="Username">User name, lowercase.</param>
/// <param name="DisplayName">Full name, when the site gives one.</param>
/// <param name="IsVerified">Verified mark, when the site says.</param>
/// <param name="PhotoKey">Key of the photo in Febe's memory cache (32 hex characters), when it is there.</param>
/// <param name="PhotoReady">True once the photo is in the cache.</param>
public sealed record SearchHit(int Position, string InstagramId, string Username, string? DisplayName, bool? IsVerified, string? PhotoKey, bool PhotoReady)
{
private bool PrintMembers(StringBuilder builder)
{
builder.Append($"Position = {Position}, HasDisplayName = {DisplayName is not null}, IsVerified = {IsVerified}, PhotoReady = {PhotoReady}");
return true;
}
}
/// <summary>
/// What the search shows now. <paramref name="Owner"/> is the random id of the window that wrote the text last;
/// <paramref name="Text"/> is the text Febe typed (or would type), as the interface labels results «per "testo"».
/// </summary>
public sealed record SearchView(long Version, string Owner, string Text, SearchState State, string? Message, IReadOnlyList<SearchHit> Hits, DateTimeOffset? RetryAfter)
{
public static SearchView Initial { get; } = new(0, string.Empty, string.Empty, SearchState.Idle, null, [], null);
private bool PrintMembers(StringBuilder builder)
{
builder.Append($"Version = {Version}, State = {State}, Hits = {Hits.Count}, TextLength = {Text.Length}");
return true;
}
}
/// <summary>
/// The profile search as the interface sees it (issue #37): one wanted text at a time (the last window that writes
/// wins), the latest view for polling, and the photos of the results from Febe's memory.
/// </summary>
public interface IProfileSearch
{
/// <summary>Sets the wanted text of window <paramref name="client"/> and returns at once.</summary>
SearchView Update(string client, string text);
/// <summary>The latest view.</summary>
SearchView Current { get; }
/// <summary>The dialog of window <paramref name="client"/> closed; ignored when another window wrote last.</summary>
void End(string client);
/// <summary>The last result seen with this user name (for adding it with its identifier), server side only.</summary>
SearchHit? Known(string username);
/// <summary>A photo of the memory cache by its key.</summary>
bool TryOpenPhoto(string key, [NotNullWhen(true)] out Stream? stream);
}