Follow requests asked again, and followed accounts found by name
A server can take a Follow with 202 and drop it afterwards, as Pleroma does while it cannot fetch our actor; the request then stayed pending for good. Following again now sends an unanswered request once more, the same activity, at most once an hour (a delivery's `again` key). accounts/search takes following=true: only accounts the persona follows, by the start of their name, display name or server, never resolved; a client fills a list with it. "already take" becomes "already taken". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
This commit is contained in:
1 parent
02a05d7a9a
commit
ce473f2741
12 files changed
+80
-12
No files matched your search
@@ -21,6 +21,30 @@ namespace PrivaPub.Api.Mastodon.Mappers
|
||||
|
||||
public async Task<List<Account>> Find(string q, bool resolve, int limit, CancellationToken token) => await Find(q, resolve, limit, 0, token);
|
||||
|
||||
// following=true: only accounts the persona follows, matched by the start of their name, display name or server
|
||||
// (what a client offers when adding to a list), read from what PrivaPub holds and never resolved
|
||||
public async Task<List<Account>> Followed(string viewerId, string q, int limit, CancellationToken token)
|
||||
{
|
||||
q = q?.Trim().TrimStart('@') ?? string.Empty;
|
||||
var ids = (await _dbEntities.Followings.Match(f => f.AvatarId == viewerId && f.State == Models.Social.FollowState.Accepted).ExecuteAsync(token))
|
||||
.Select(f => f.TargetAccountId).Where(id => !string.IsNullOrEmpty(id)).ToList();
|
||||
if (ids.Count == 0)
|
||||
return new List<Account>();
|
||||
var parts = q.Split('@');
|
||||
var localDomain = new Uri(_localActors.BaseAddress).Authority;
|
||||
bool Matches(string userName, string name, string domain) =>
|
||||
userName?.StartsWith(parts[0], StringComparison.OrdinalIgnoreCase) == true
|
||||
&& (parts.Length < 2 || domain?.StartsWith(parts[1], StringComparison.OrdinalIgnoreCase) == true)
|
||||
|| parts.Length == 1 && name?.Contains(q, StringComparison.OrdinalIgnoreCase) == true;
|
||||
var found = (await _dbEntities.Avatars.Match(a => ids.Contains(a.ID) && !a.DeletionAt.HasValue).ExecuteAsync(token))
|
||||
.Where(a => Matches(a.UserName, a.Name, localDomain)).Select(a => (a.UserName, a.ID))
|
||||
.Concat((await _dbEntities.ForeignAvatars.Match(f => ids.Contains(f.ID) && !f.DeletionAt.HasValue).ExecuteAsync(token))
|
||||
.Where(f => Matches(f.UserName, f.Name, f.Domain)).Select(f => (f.UserName, f.ID)))
|
||||
.OrderBy(a => a.UserName, StringComparer.OrdinalIgnoreCase).Take(limit).Select(a => a.ID).ToList();
|
||||
var accounts = await _mapper.Accounts(found, token);
|
||||
return found.Where(accounts.ContainsKey).Select(id => accounts[id]).ToList();
|
||||
}
|
||||
|
||||
// gone accounts (remote ones that deleted themselves, personas of banned or deleted roots) are never found
|
||||
public async Task<List<Account>> Find(string q, bool resolve, int limit, int offset, CancellationToken token)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user