Everything on, phase 4b: ids that resolve, a hashtag page, grouped notifications, remote accounts' real counts
- A community's announces resolve, as FEDERATION.md and ROADMAP always said Announce ids do. GroupDistributor keeps
each one it sends (GroupAnnouncement, unique by id). /grunts serves it while the post it carries is shown and 410
after, and also serves the announce-{postId} ids the group outbox lists, which now keep a stable `published`
instead of the time of the fetch.
- A persona's boost points at the boosted post: its `url` in the Mastodon API is the boosted post's page, and a browser
following the boost's id is redirected there instead of getting JSON.
- /tags/{tag}, where every Hashtag link we send points, is now a public page of this server's public posts with that
tag, with the same strict CSP and noindex as the profile pages.
- Grouped notifications (/api/v2/notifications, its unread count, a group, its accounts and dismiss). We advertise
api_versions.mastodon = 7 so clients show quotes, and clients that trust it call these; they answered 404. Likes and
boosts of one post group together, as do follows within an hour. The version string stays 4.2.0 until streaming
and Web Push exist.
- A remote account's follower, following and post counts are what its server publishes. AccountCountsJob reads its
collections' totalItems from its own origin, signed by the instance actor, at most daily and only after the account
was fetched, never when someone looks. They used to be 0.
- The other ids that do not resolve are documented as such: Update, Delete, EmojiReact, QuoteRequest and its answers,
Flag, Ignore and poll votes.
676 tests pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ELjqpznMFMNrJoJUj6K5p2
This commit is contained in:
1 parent
8f25bf056d
commit
e2f61ede56
18 files changed
+452
-17
No files matched your search
@@ -177,8 +177,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
_dbEntities = dbEntities;
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/notifications"), Scope("read:notifications")]
|
||||
public async Task<IActionResult> List(CancellationToken token)
|
||||
Find<NotificationEntity, NotificationEntity> Filtered()
|
||||
{
|
||||
var types = Params.List("types").Select(Parse).Where(t => t.HasValue).Select(t => t.Value).ToList();
|
||||
var excluded = Params.List("exclude_types").Select(Parse).Where(t => t.HasValue).Select(t => t.Value).ToList();
|
||||
@@ -189,11 +188,132 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
query.Match(n => !excluded.Contains(n.Type));
|
||||
if (Params.Get("account_id") is { } accountId)
|
||||
query.Match(n => n.FromAccountId == accountId);
|
||||
var notifications = await Page.From(Params, Limit(15, 30)).Fetch(query, n => n.ID, token);
|
||||
return query;
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/notifications"), Scope("read:notifications")]
|
||||
public async Task<IActionResult> List(CancellationToken token)
|
||||
{
|
||||
var notifications = await Page.From(Params, Limit(15, 30)).Fetch(Filtered(), n => n.ID, token);
|
||||
Link("/api/v1/notifications", notifications.LastOrDefault()?.ID, notifications.FirstOrDefault()?.ID);
|
||||
return Json(await Map(notifications, token));
|
||||
}
|
||||
|
||||
// Grouped notifications (Mastodon 4.3): api_versions.mastodon says we speak that API, so clients call it. Likes and
|
||||
// boosts of one post group together, as do follows within an hour; everything else stands alone.
|
||||
static readonly HashSet<string> DefaultGrouped = new() { "favourite", "reblog", "follow" };
|
||||
|
||||
HashSet<string> Grouped() => Params.List("grouped_types") is { Count: > 0 } chosen ? chosen.ToHashSet() : DefaultGrouped;
|
||||
|
||||
static string GroupKey(NotificationEntity n, ISet<string> grouped) =>
|
||||
!grouped.Contains(Names[n.Type]) ? $"ungrouped-{n.ID}"
|
||||
: n.Type == NotificationType.Follow ? $"grouped-follow-{n.CreatedAt:yyyyMMddHH}"
|
||||
: string.IsNullOrEmpty(n.PostId) ? $"ungrouped-{n.ID}"
|
||||
: $"grouped-{Names[n.Type]}-{n.PostId}";
|
||||
|
||||
// the notifications a group key stands for
|
||||
System.Linq.Expressions.Expression<Func<NotificationEntity, bool>> InGroup(string key)
|
||||
{
|
||||
var me = MyId;
|
||||
if (key.StartsWith("ungrouped-", StringComparison.Ordinal))
|
||||
{
|
||||
var id = key["ungrouped-".Length..];
|
||||
return n => n.AvatarId == me && n.ID == id;
|
||||
}
|
||||
if (key.StartsWith("grouped-follow-", StringComparison.Ordinal)
|
||||
&& DateTime.TryParseExact(key["grouped-follow-".Length..], "yyyyMMddHH", System.Globalization.CultureInfo.InvariantCulture,
|
||||
System.Globalization.DateTimeStyles.AdjustToUniversal | System.Globalization.DateTimeStyles.AssumeUniversal, out var hour))
|
||||
{
|
||||
var end = hour.AddHours(1);
|
||||
return n => n.AvatarId == me && n.Type == NotificationType.Follow && n.CreatedAt >= hour && n.CreatedAt < end;
|
||||
}
|
||||
if (key.Split('-') is ["grouped", var name, var postId] && Parse(name) is { } type)
|
||||
return n => n.AvatarId == me && n.Type == type && n.PostId == postId;
|
||||
return default;
|
||||
}
|
||||
|
||||
async Task<List<NotificationEntity>> Members(string key, CancellationToken token) =>
|
||||
InGroup(key) is { } filter
|
||||
? await _dbEntities.Notifications.Match(filter).Sort(n => n.ID, Order.Descending).Limit(80).ExecuteAsync(token)
|
||||
: new List<NotificationEntity>();
|
||||
|
||||
async Task<object> Groups(List<NotificationEntity> page, ISet<string> grouped, CancellationToken token)
|
||||
{
|
||||
var mapped = (await Map(page, token)).ToDictionary(n => n.Id);
|
||||
var shown = page.Where(n => mapped.ContainsKey(n.ID)).ToList();
|
||||
var groups = new List<object>();
|
||||
foreach (var group in shown.GroupBy(n => GroupKey(n, grouped)))
|
||||
{
|
||||
var newest = mapped[group.First().ID];
|
||||
var total = group.Key.StartsWith("ungrouped-", StringComparison.Ordinal) ? 1 : await DB.Default.CountAsync(InGroup(group.Key), token);
|
||||
groups.Add(new
|
||||
{
|
||||
group_key = group.Key,
|
||||
notifications_count = Math.Max(total, group.Count()),
|
||||
type = newest.Type,
|
||||
most_recent_notification_id = newest.Id,
|
||||
page_min_id = group.Last().ID,
|
||||
page_max_id = group.First().ID,
|
||||
latest_page_notification_at = newest.CreatedAt,
|
||||
sample_account_ids = group.Select(n => mapped[n.ID].Account.Id).Distinct().Take(8).ToList(),
|
||||
status_id = newest.Status?.Id,
|
||||
emoji = newest.Emoji,
|
||||
emoji_url = newest.EmojiUrl
|
||||
});
|
||||
}
|
||||
return new
|
||||
{
|
||||
accounts = mapped.Values.Select(n => n.Account).DistinctBy(a => a.Id).ToList(),
|
||||
statuses = mapped.Values.Where(n => n.Status != default).Select(n => n.Status).DistinctBy(s => s.Id).ToList(),
|
||||
notification_groups = groups
|
||||
};
|
||||
}
|
||||
|
||||
[HttpGet("/api/v2/notifications"), Scope("read:notifications")]
|
||||
public async Task<IActionResult> GroupedList(CancellationToken token)
|
||||
{
|
||||
var notifications = await Page.From(Params, Limit(40, 80)).Fetch(Filtered(), n => n.ID, token);
|
||||
Link("/api/v2/notifications", notifications.LastOrDefault()?.ID, notifications.FirstOrDefault()?.ID);
|
||||
return Json(await Groups(notifications, Grouped(), token));
|
||||
}
|
||||
|
||||
[HttpGet("/api/v2/notifications/unread_count"), Scope("read:notifications")]
|
||||
public async Task<IActionResult> GroupedUnreadCount(CancellationToken token)
|
||||
{
|
||||
var unread = await Filtered().Match(n => !n.IsRead).Sort(n => n.ID, Order.Descending)
|
||||
.Limit(Math.Clamp(Params.Int("limit") ?? 100, 1, 1000)).ExecuteAsync(token);
|
||||
var shown = (await Map(unread, token)).Select(n => n.Id).ToHashSet();
|
||||
var grouped = Grouped();
|
||||
return Json(new { count = unread.Where(n => shown.Contains(n.ID)).Select(n => GroupKey(n, grouped)).Distinct().Count() });
|
||||
}
|
||||
|
||||
[HttpGet("/api/v2/notifications/{groupKey}"), Scope("read:notifications")]
|
||||
public async Task<IActionResult> Group(string groupKey, CancellationToken token)
|
||||
{
|
||||
var members = await Members(groupKey, token);
|
||||
if (members.Count == 0)
|
||||
return NotFoundError();
|
||||
return Json(await Groups(members, new HashSet<string>(DefaultGrouped.Append(Names[members[0].Type])), token));
|
||||
}
|
||||
|
||||
[HttpGet("/api/v2/notifications/{groupKey}/accounts"), Scope("read:notifications")]
|
||||
public async Task<IActionResult> GroupAccounts(string groupKey, CancellationToken token)
|
||||
{
|
||||
var members = await Members(groupKey, token);
|
||||
if (members.Count == 0)
|
||||
return NotFoundError();
|
||||
return Json((await Map(members, token)).Select(n => n.Account).DistinctBy(a => a.Id).ToList());
|
||||
}
|
||||
|
||||
[HttpPost("/api/v2/notifications/{groupKey}/dismiss"), Scope("write:notifications")]
|
||||
public async Task<IActionResult> DismissGroup(string groupKey, CancellationToken token)
|
||||
{
|
||||
if (InGroup(groupKey) is not { } filter)
|
||||
return NotFoundError();
|
||||
await DB.Default.DeleteAsync(filter);
|
||||
return Json(new { });
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/notifications/{id}"), Scope("read:notifications")]
|
||||
public async Task<IActionResult> Get(string id, CancellationToken token)
|
||||
{
|
||||
|
||||
@@ -120,7 +120,10 @@ namespace PrivaPub.Api.Mastodon.Mappers
|
||||
Avatar = Proxied(foreign.PictureURL) ?? MissingAvatar,
|
||||
AvatarStatic = Proxied(foreign.PictureURL) ?? MissingAvatar,
|
||||
Header = Proxied(foreign.ThumbnailURL) ?? MissingHeader,
|
||||
HeaderStatic = Proxied(foreign.ThumbnailURL) ?? MissingHeader
|
||||
HeaderStatic = Proxied(foreign.ThumbnailURL) ?? MissingHeader,
|
||||
FollowersCount = foreign.FollowersCount ?? 0,//as its server publishes them (AccountCountsJob); 0 while unknown
|
||||
FollowingCount = foreign.FollowingCount ?? 0,
|
||||
StatusesCount = foreign.StatusesCount ?? 0
|
||||
};
|
||||
|
||||
public async Task<Account> Account(string id, CancellationToken token) =>
|
||||
@@ -279,6 +282,7 @@ namespace PrivaPub.Api.Mastodon.Mappers
|
||||
continue;
|
||||
Quote(inner, original);
|
||||
status.Reblog = inner;
|
||||
status.Url = inner.Url;//a boost has no page of its own; /grunts would answer JSON to a browser
|
||||
status.Content = string.Empty;
|
||||
status.Reblogged = reblogged.Contains(original.ID);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
using MongoDB.Entities;
|
||||
|
||||
using PrivaPub.Federation.Objects;
|
||||
using PrivaPub.Infrastructure.Http;
|
||||
using PrivaPub.Infrastructure.Jobs;
|
||||
using PrivaPub.Models.Jobs;
|
||||
using PrivaPub.Models.User;
|
||||
using PrivaPub.StaticServices;
|
||||
|
||||
namespace PrivaPub.Federation.Actors
|
||||
{
|
||||
// A remote account's follower, following and post counts, as its own server publishes them (the totalItems of its
|
||||
// followers, following and outbox collections). Read when the account is fetched, at most once a day, never when
|
||||
// someone looks at it; a hidden or missing collection leaves its count unknown. Mastodon and GoToSocial do the same.
|
||||
public class AccountCountsJob : IJobHandler
|
||||
{
|
||||
readonly IRemoteActorService _remoteActors;
|
||||
readonly DbEntities _dbEntities;
|
||||
|
||||
public AccountCountsJob(IRemoteActorService remoteActors, DbEntities dbEntities)
|
||||
{
|
||||
_remoteActors = remoteActors;
|
||||
_dbEntities = dbEntities;
|
||||
}
|
||||
|
||||
public JobKind Kind => JobKind.CountAccount;
|
||||
public int Concurrency => 2;
|
||||
public int MaxAttempts => 2;
|
||||
public int PerHostLimit => 1;
|
||||
|
||||
public static string DedupeKey(string actorUri, DateTime day) => $"count|{actorUri}|{day:yyyyMMdd}";
|
||||
|
||||
public async Task<JobOutcome> Handle(Job job, CancellationToken token)
|
||||
{
|
||||
var actor = await _dbEntities.ForeignAvatars.Match(a => a.ActorURI == job.Payload && !a.DeletionAt.HasValue).ExecuteFirstAsync(token);
|
||||
if (actor == default)
|
||||
return JobOutcome.Done;
|
||||
await DB.Default.Update<ForeignAvatar>().MatchID(actor.ID)
|
||||
.Modify(a => a.FollowersCount, await Total(actor, actor.FollowersURL, token))
|
||||
.Modify(a => a.FollowingCount, await Total(actor, actor.FollowingURL, token))
|
||||
.Modify(a => a.StatusesCount, await Total(actor, actor.OutboxURL, token))
|
||||
.Modify(a => a.CountedAt, DateTime.UtcNow)
|
||||
.ExecuteAsync(token);
|
||||
return JobOutcome.Done;
|
||||
}
|
||||
|
||||
// only from the actor's own server, as everything we believe about it
|
||||
async Task<int?> Total(ForeignAvatar actor, string collection, CancellationToken token)
|
||||
{
|
||||
if (string.IsNullOrEmpty(collection) || !Origin.Same(collection, actor.ActorURI))
|
||||
return default;
|
||||
using var scope = HttpScope.For("collection");
|
||||
using var fetched = await _remoteActors.FetchObject(collection, token);
|
||||
return fetched != default && fetched.Root.ValueKind == System.Text.Json.JsonValueKind.Object
|
||||
&& fetched.Root.TryGetProperty("totalItems", out var total) && total.TryGetInt32(out var count) && count >= 0
|
||||
? count
|
||||
: default;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,9 +36,12 @@ namespace PrivaPub.Federation.Actors
|
||||
readonly DbEntities _dbEntities;
|
||||
readonly IOptionsMonitor<FederationOptions> _options;
|
||||
|
||||
readonly Infrastructure.Jobs.IJobQueue _jobs;
|
||||
|
||||
public RemoteActorService(IFederationHttp http, ILocalActorService localActors, IMemoryCache cache, DbEntities dbEntities,
|
||||
IOptionsMonitor<FederationOptions> options = default)
|
||||
IOptionsMonitor<FederationOptions> options = default, Infrastructure.Jobs.IJobQueue jobs = default)
|
||||
{
|
||||
_jobs = jobs;
|
||||
_http = http;
|
||||
_localActors = localActors;
|
||||
_cache = cache;
|
||||
@@ -89,7 +92,16 @@ namespace PrivaPub.Federation.Actors
|
||||
return cached;
|
||||
|
||||
var key = cached == default ? default : actor.Key(cached.PublicKeyId);
|
||||
return await Upsert(actor, key ?? actor.Keys.FirstOrDefault(), token);
|
||||
return await Counted(await Upsert(actor, key ?? actor.Keys.FirstOrDefault(), token), token);
|
||||
}
|
||||
|
||||
// its counts are read once a day, after it was fetched (AccountCountsJob)
|
||||
async Task<ForeignAvatar> Counted(ForeignAvatar stored, CancellationToken token)
|
||||
{
|
||||
if (_jobs != default && stored is { DeletionAt: null } && Uri.TryCreate(stored.ActorURI, UriKind.Absolute, out var uri))
|
||||
await _jobs.Enqueue(Models.Jobs.JobKind.CountAccount, stored.ActorURI, uri.Host.ToLowerInvariant(),
|
||||
AccountCountsJob.DedupeKey(stored.ActorURI, DateTime.UtcNow), token);
|
||||
return stored;
|
||||
}
|
||||
|
||||
public async Task<ForeignAvatar> GetActorByKeyId(string keyId, bool refresh, CancellationToken token)
|
||||
@@ -121,7 +133,7 @@ namespace PrivaPub.Federation.Actors
|
||||
var key = actor?.Key(keyId);
|
||||
if (key == default)
|
||||
return default;
|
||||
return await Upsert(actor, key, token);
|
||||
return await Counted(await Upsert(actor, key, token), token);
|
||||
}
|
||||
|
||||
public bool KeyTemporarilyUnavailable(string keyId) => Origin.Of(keyId) != default && _http.FailedTemporarily(StripFragment(keyId));
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace PrivaPub.Federation.Controllers
|
||||
{
|
||||
if (local.Kind == LocalActorKind.Group)
|
||||
{
|
||||
items.Add(ActivityPubRenderer.Announce(local, post.ObjectURI, $"announce-{post.ID}"));
|
||||
items.Add(ActivityPubRenderer.Announce(local, post.ObjectURI, $"announce-{post.ID}", post.CreationDate));
|
||||
continue;
|
||||
}
|
||||
if (post.ReblogOfPostId != default)
|
||||
@@ -258,8 +258,12 @@ namespace PrivaPub.Federation.Controllers
|
||||
{
|
||||
var booster = await _localActors.FindByUserName(actor, token);
|
||||
var uri = booster?.ActivityUri(activityId);
|
||||
if (booster is { Kind: LocalActorKind.Group, IsCircle: false })
|
||||
return await GroupAnnounce(booster, activityId, uri, token);
|
||||
var reblog = uri == default ? default : await _dbEntities.Posts.Match(p => p.ObjectURI == uri && !p.DeletedAt.HasValue).ExecuteFirstAsync(token);
|
||||
var rendered = reblog == default ? default : await AnnounceFor(reblog, token);
|
||||
if (rendered != default && WantsHtml() && await _dbEntities.Posts.MatchID(reblog.ReblogOfPostId).ExecuteFirstAsync(token) is { } boosted)
|
||||
return Redirect(boosted.Url ?? boosted.ObjectURI);//a boost has no page of its own: the boosted post's
|
||||
return rendered == default ? NotFound() : Activity(rendered);
|
||||
}
|
||||
if (!activityId.StartsWith("create-", StringComparison.Ordinal))
|
||||
@@ -386,6 +390,24 @@ namespace PrivaPub.Federation.Controllers
|
||||
return new ContentResult { Content = tombstone.ToJsonString(), ContentType = ActivityContentType, StatusCode = StatusCodes.Status410Gone };
|
||||
}
|
||||
|
||||
// A community's announce: one GroupDistributor sent (kept as sent), or one its outbox lists (announce-{postId}),
|
||||
// while the post it is about is still shown; 410 once that post is gone.
|
||||
async Task<IActionResult> GroupAnnounce(LocalActor group, string activityId, string uri, CancellationToken token)
|
||||
{
|
||||
if (await DB.Default.Find<GroupAnnouncement>().Match(a => a.ActivityURI == uri && a.GroupId == group.Id).ExecuteFirstAsync(token) is { } kept)
|
||||
{
|
||||
var about = await _dbEntities.Posts.Match(p => p.ObjectURI == kept.ObjectURI).ExecuteFirstAsync(token);
|
||||
if (!VisibilityPolicy.Shown(about) || about.Visibility is not (PostVisibility.Public or PostVisibility.Unlisted))
|
||||
return StatusCode(StatusCodes.Status410Gone);
|
||||
var body = JsonNode.Parse(kept.Body)!.AsObject();
|
||||
body["@context"] = ActivityPubRenderer.Context();
|
||||
return Activity(body);
|
||||
}
|
||||
var postId = activityId["announce-".Length..];
|
||||
var post = await _dbEntities.Posts.Match(p => p.ID == postId && p.GroupId == group.Id).Match(VisibilityPolicy.IsPublic).ExecuteFirstAsync(token);
|
||||
return post == default ? NotFound() : Activity(ActivityPubRenderer.Announce(group, post.ObjectURI, activityId, post.CreationDate));
|
||||
}
|
||||
|
||||
async Task<JsonObject> AnnounceFor(PostEntity reblog, CancellationToken token)
|
||||
{
|
||||
var original = await _dbEntities.Posts.MatchID(reblog.ReblogOfPostId).ExecuteFirstAsync(token);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using MongoDB.Entities;
|
||||
|
||||
using PrivaPub.Federation.Actors;
|
||||
using PrivaPub.Federation.Rendering;
|
||||
using PrivaPub.Models.Federation;
|
||||
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
@@ -14,6 +17,26 @@ namespace PrivaPub.Federation.Outbox
|
||||
|
||||
public class GroupDistributor : IGroupDistributor
|
||||
{
|
||||
// so the announce's id resolves (PeasantsController.Grunt); a repeat of the same announce keeps the first
|
||||
static async Task Keep(LocalActor group, JsonObject announce, string objectUri, CancellationToken token)
|
||||
{
|
||||
var body = (JsonObject)announce.DeepClone();
|
||||
body.Remove("@context");
|
||||
try
|
||||
{
|
||||
await DB.Default.SaveAsync(new GroupAnnouncement
|
||||
{
|
||||
GroupId = group.Id,
|
||||
ActivityURI = body["id"]!.GetValue<string>(),
|
||||
ObjectURI = objectUri,
|
||||
Body = body.ToJsonString()
|
||||
}, token);
|
||||
}
|
||||
catch (MongoDB.Driver.MongoWriteException ex) when (ex.WriteError?.Category == MongoDB.Driver.ServerErrorCategory.DuplicateKey)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
readonly IDeliveryService _delivery;
|
||||
|
||||
public GroupDistributor(IDeliveryService delivery)
|
||||
@@ -43,8 +66,13 @@ namespace PrivaPub.Federation.Outbox
|
||||
// Every follower, the author's own server included: Lemmy 1.0 keeps its user's post pending until the community
|
||||
// announces it back, and clears that before it answers the echo 400 ("Object is not remote").
|
||||
await _delivery.EnqueueToFollowers(group, announce, token);
|
||||
await Keep(group, announce, objectUri, token);
|
||||
if (isNewPost && !string.IsNullOrEmpty(objectUri))
|
||||
await _delivery.EnqueueToFollowers(group, ActivityPubRenderer.Announce(group, objectUri, $"announce-object-{key}"), token);
|
||||
{
|
||||
var boost = ActivityPubRenderer.Announce(group, objectUri, $"announce-object-{key}");
|
||||
await _delivery.EnqueueToFollowers(group, boost, token);
|
||||
await Keep(group, boost, objectUri, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,13 +357,13 @@ namespace PrivaPub.Federation.Rendering
|
||||
["object"] = note
|
||||
};
|
||||
|
||||
public static JsonObject Announce(LocalActor group, string objectUri, string activityId) => new()
|
||||
public static JsonObject Announce(LocalActor group, string objectUri, string activityId, DateTime? published = default) => new()
|
||||
{
|
||||
["@context"] = ActivityStreams,
|
||||
["id"] = group.ActivityUri(activityId),
|
||||
["type"] = "Announce",
|
||||
["actor"] = group.Uri,
|
||||
["published"] = Timestamp(DateTime.UtcNow),
|
||||
["published"] = Timestamp(published ?? DateTime.UtcNow),
|
||||
["to"] = new JsonArray(Public),
|
||||
["cc"] = new JsonArray(group.Followers),
|
||||
["object"] = objectUri
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace PrivaPub.Infrastructure.Data
|
||||
await Plain<Group>(token, g => g.InvitationCode);
|
||||
|
||||
await Plain<DmGroup>(token, g => g.ParticipantsKey);
|
||||
await Unique<GroupAnnouncement>(a => a.ActivityURI, Builders<GroupAnnouncement>.Filter.Type(a => a.ActivityURI, BsonType.String), token);
|
||||
|
||||
await Plain<Delivery>(token, d => d.DeliveredAt, d => d.AbandonedAt, d => d.NextAttemptAt);
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ namespace PrivaPub.Middleware
|
||||
.AddSingleton<IQuoteService, QuoteService>()
|
||||
.AddSingleton<IJobHandler, PollRefreshJob>()
|
||||
.AddSingleton<IJobHandler, RecoveryJob>()
|
||||
.AddSingleton<IJobHandler, Federation.Actors.AccountCountsJob>()
|
||||
.AddSingleton<IJobHandler, PollCloseJob>()
|
||||
.AddSingleton<InstanceDescriber>()
|
||||
.AddSingleton<IJobHandler>(services => services.GetRequiredService<InstanceDescriber>())
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using MongoDB.Entities;
|
||||
|
||||
namespace PrivaPub.Models.Federation
|
||||
{
|
||||
// An Announce a community sent (GroupDistributor), kept so its id resolves as both docs promise: announces are public,
|
||||
// unlike follows, likes and blocks. Served only while the post it is about is still shown.
|
||||
public class GroupAnnouncement : Entity
|
||||
{
|
||||
public string GroupId { get; set; }
|
||||
public string ActivityURI { get; set; }
|
||||
public string ObjectURI { get; set; }//the post it is about
|
||||
public string Body { get; set; }//the Announce as sent, without @context
|
||||
public DateTime PublishedAt { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,8 @@ namespace PrivaPub.Models.Jobs
|
||||
RollupDay,
|
||||
CrawlPlan,
|
||||
CrawlInstance,
|
||||
SendRecovery
|
||||
SendRecovery,
|
||||
CountAccount
|
||||
}
|
||||
|
||||
public enum JobState
|
||||
|
||||
@@ -88,6 +88,10 @@ namespace PrivaPub.Models.User
|
||||
public DateTime? BannedAt { get; set; }
|
||||
public DateTime? DeletionAt { get; set; }
|
||||
public DateTime? ForgottenAt { get; set; }//its likes, votes, boosts and replies were taken out of our counts (GoneActors)
|
||||
public int? FollowersCount { get; set; }//its own collections' totalItems, read at most daily (AccountCountsJob)
|
||||
public int? FollowingCount { get; set; }
|
||||
public int? StatusesCount { get; set; }
|
||||
public DateTime? CountedAt { get; set; }
|
||||
}
|
||||
|
||||
public class AvatarSettings
|
||||
|
||||
@@ -92,6 +92,49 @@ namespace PrivaPub.Web.Pages
|
||||
}
|
||||
}
|
||||
|
||||
// The hashtag links our posts carry (/tags/{tag}): this server's public posts with that tag, as a page like a profile's.
|
||||
public class TagModel : PublicPageModel
|
||||
{
|
||||
const int PageSize = 20;
|
||||
|
||||
readonly ILocalActorService _localActors;
|
||||
readonly DbEntities _dbEntities;
|
||||
|
||||
public TagModel(ILocalActorService localActors, DbEntities dbEntities)
|
||||
{
|
||||
_localActors = localActors;
|
||||
_dbEntities = dbEntities;
|
||||
}
|
||||
|
||||
public string Tag { get; private set; }
|
||||
public IReadOnlyList<PostView> Posts { get; private set; } = Array.Empty<PostView>();
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(string tag, CancellationToken token)
|
||||
{
|
||||
Tag = tag?.TrimStart('#').ToLowerInvariant();
|
||||
if (string.IsNullOrEmpty(Tag) || Tag.Length > 100)
|
||||
return NotFound();
|
||||
Harden();
|
||||
var posts = await _dbEntities.Posts
|
||||
.Match(p => p.Tags.Contains(Tag) && !p.IsFederatedCopy && p.ReblogOfPostId == null && p.Visibility == PostVisibility.Public)
|
||||
.Match(VisibilityPolicy.IsPublic)
|
||||
.Sort(p => p.ID, Order.Descending)
|
||||
.Limit(PageSize)
|
||||
.ExecuteAsync(token);
|
||||
var authors = new Dictionary<string, LocalActor>();
|
||||
var views = new List<PostView>();
|
||||
foreach (var post in posts)
|
||||
{
|
||||
if (!authors.TryGetValue(post.GroupUserId, out var author))
|
||||
authors[post.GroupUserId] = author = await _localActors.FindById(LocalActorKind.Person, post.GroupUserId, token);
|
||||
if (author is { IsFederated: true })
|
||||
views.Add(PostView.From(post, author));
|
||||
}
|
||||
Posts = views;
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
|
||||
public class StatusModel : PublicPageModel
|
||||
{
|
||||
readonly ILocalActorService _localActors;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
@page "/tags/{tag}"
|
||||
@model PrivaPub.Web.Pages.TagModel
|
||||
@{
|
||||
ViewData["Title"] = $"#{Model.Tag}";
|
||||
}
|
||||
<header>
|
||||
<h1>#@Model.Tag</h1>
|
||||
<div class="meta">Public posts on this server with this tag.</div>
|
||||
</header>
|
||||
@foreach (var post in Model.Posts)
|
||||
{
|
||||
<partial name="_Post" model="post" />
|
||||
}
|
||||
@if (Model.Posts.Count == 0)
|
||||
{
|
||||
<p class="meta">Nothing public with this tag yet.</p>
|
||||
}
|
||||
Reference in new issue
Block a user