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>
This commit is contained in:
1 parent
5e417c666d
commit
9941a2fa1f
98 files changed
+8021
-229
No files matched your search
@@ -44,6 +44,22 @@ public sealed class ShapeReader
|
||||
|
||||
var profiles = walk.Profiles.Values.ToList();
|
||||
var viewer = profiles.FirstOrDefault(p => p.IsViewer);
|
||||
if (walk.Search is not null)
|
||||
{
|
||||
// A search answer, even with no profile in it: never an empty page and never an unknown shape (issue #37).
|
||||
return new ReadResult
|
||||
{
|
||||
Shape = ReadShape.Recognized,
|
||||
Search = walk.Search,
|
||||
Contents = walk.Contents,
|
||||
Profiles = profiles,
|
||||
Highlights = walk.Highlights,
|
||||
Page = walk.Page,
|
||||
Viewer = viewer,
|
||||
ViewerId = viewer?.Id ?? walk.ViewerId,
|
||||
};
|
||||
}
|
||||
|
||||
if (walk.Contents.Count > 0 || walk.Highlights.Count > 0 || profiles.Count > 0)
|
||||
{
|
||||
return new ReadResult
|
||||
@@ -173,6 +189,13 @@ public sealed class ShapeReader
|
||||
|
||||
foreach (var property in node.EnumerateObject())
|
||||
{
|
||||
if (IsSearchRoot(property, out var items))
|
||||
{
|
||||
// The search answer: read with its own keys, and its subtree is not walked for generic profiles.
|
||||
walk.Search ??= ReadSearch(items);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (property.Value.ValueKind is JsonValueKind.Object or JsonValueKind.Array)
|
||||
{
|
||||
Visit(property.Value, walk, inherited, highlightId, depth + 1);
|
||||
@@ -180,6 +203,60 @@ public sealed class ShapeReader
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A member named like the search root, whose value holds the list of results (issue #37).</summary>
|
||||
private bool IsSearchRoot(JsonProperty property, out JsonElement items)
|
||||
{
|
||||
items = default;
|
||||
var search = _v.Search;
|
||||
return search.IsSet
|
||||
&& property.Value.ValueKind == JsonValueKind.Object
|
||||
&& search.Root.Paths.Contains(property.Name, StringComparer.Ordinal)
|
||||
&& search.Items.TryGet(property.Value, out items)
|
||||
&& items.ValueKind == JsonValueKind.Array;
|
||||
}
|
||||
|
||||
/// <summary>The profiles of a search answer in their order; hashtags and places are never read.</summary>
|
||||
private SearchAnswer ReadSearch(JsonElement items)
|
||||
{
|
||||
var search = _v.Search;
|
||||
var hits = new List<SearchProfile>();
|
||||
var index = 0;
|
||||
foreach (var item in items.EnumerateArray())
|
||||
{
|
||||
var order = index++;
|
||||
if (item.ValueKind != JsonValueKind.Object)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var node = search.Profile.TryGet(item, out var inner) && inner.ValueKind == JsonValueKind.Object ? inner : item;
|
||||
var id = AsText(Get(search.Id, node));
|
||||
var username = AsText(Get(search.Username, node));
|
||||
if (id is null || string.IsNullOrWhiteSpace(username))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
FileVersion? picture = null;
|
||||
if (search.Picture.TryGet(node, out var pictureNode))
|
||||
{
|
||||
picture = ReadVersions(pictureNode).MaxBy(x => x.Version.Area)?.Version;
|
||||
}
|
||||
|
||||
var profile = new ProfileInfo
|
||||
{
|
||||
Id = id,
|
||||
Username = username.Trim(),
|
||||
DisplayName = AsText(Get(search.DisplayName, node)),
|
||||
Picture = picture,
|
||||
};
|
||||
var position = AsInt(Get(search.Position, item)) ?? order;
|
||||
hits.Add(new SearchProfile(position, profile, search.Verified.TryGet(node, out var verified) ? AsBool(verified) : null));
|
||||
}
|
||||
|
||||
return new SearchAnswer([.. hits.OrderBy(h => h.Position)]);
|
||||
}
|
||||
|
||||
private bool IsContent(JsonElement node) =>
|
||||
_v.Content.Id.Has(node) && _v.Content.TakenAt.Has(node)
|
||||
&& (_v.Content.Images.Has(node) || _v.Content.Videos.Has(node) || _v.Content.Children.Has(node));
|
||||
@@ -544,6 +621,9 @@ public sealed class ShapeReader
|
||||
/// <summary>Identifier of the connected account when the answer gives no more than that.</summary>
|
||||
public string? ViewerId { get; set; }
|
||||
|
||||
/// <summary>The search box answer, when the response holds one (issue #37).</summary>
|
||||
public SearchAnswer? Search { get; set; }
|
||||
|
||||
/// <summary>Merges what different parts of a response say about the same profile.</summary>
|
||||
public void AddProfile(ProfileInfo profile)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user