:drunk: Write shit code trying to split up the Auth (WIP)
This commit is contained in:
@ -1,37 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using NodaTime;
|
||||
|
||||
namespace DysonNetwork.Sphere.Activity;
|
||||
|
||||
public interface IActivity
|
||||
{
|
||||
public Activity ToActivity();
|
||||
}
|
||||
|
||||
[NotMapped]
|
||||
public class Activity : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[MaxLength(1024)] public string Type { get; set; } = null!;
|
||||
[MaxLength(4096)] public string ResourceIdentifier { get; set; } = null!;
|
||||
[Column(TypeName = "jsonb")] public Dictionary<string, object> Meta { get; set; } = new();
|
||||
|
||||
public object? Data { get; set; }
|
||||
|
||||
// Outdated fields, for backward compability
|
||||
public int Visibility => 0;
|
||||
|
||||
public static Activity Empty()
|
||||
{
|
||||
var now = SystemClock.Instance.GetCurrentInstant();
|
||||
return new Activity
|
||||
{
|
||||
CreatedAt = now,
|
||||
UpdatedAt = now,
|
||||
Id = Guid.NewGuid(),
|
||||
Type = "empty",
|
||||
ResourceIdentifier = "none"
|
||||
};
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NodaTime;
|
||||
using NodaTime.Text;
|
||||
|
||||
@ -22,7 +21,7 @@ public class ActivityController(
|
||||
/// Besides, when users are logged in, it will also mix the other kinds of data and who're plying to them.
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<List<Activity>>> ListActivities(
|
||||
public async Task<ActionResult<List<Common.Models.Activity>>> ListActivities(
|
||||
[FromQuery] string? cursor,
|
||||
[FromQuery] string? filter,
|
||||
[FromQuery] int take = 20,
|
||||
@ -45,7 +44,7 @@ public class ActivityController(
|
||||
var debugIncludeSet = debugInclude?.Split(',').ToHashSet() ?? new HashSet<string>();
|
||||
|
||||
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||
return currentUserValue is not Account.Account currentUser
|
||||
return currentUserValue is Account.Account currentUser
|
||||
? Ok(await acts.GetActivitiesForAnyone(take, cursorTimestamp, debugIncludeSet))
|
||||
: Ok(await acts.GetActivities(take, cursorTimestamp, currentUser, filter, debugIncludeSet));
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using DysonNetwork.Sphere.Account;
|
||||
|
||||
using DysonNetwork.Sphere.Connection.WebReader;
|
||||
using DysonNetwork.Sphere.Discovery;
|
||||
using DysonNetwork.Sphere.Post;
|
||||
@ -11,11 +11,11 @@ namespace DysonNetwork.Sphere.Activity;
|
||||
public class ActivityService(
|
||||
AppDatabase db,
|
||||
PublisherService pub,
|
||||
RelationshipService rels,
|
||||
|
||||
PostService ps,
|
||||
DiscoveryService ds)
|
||||
{
|
||||
private static double CalculateHotRank(Post.Post post, Instant now)
|
||||
private static double CalculateHotRank(Common.Models.Post post, Instant now)
|
||||
{
|
||||
var score = post.Upvotes - post.Downvotes;
|
||||
var postTime = post.PublishedAt ?? post.CreatedAt;
|
||||
@ -24,10 +24,10 @@ public class ActivityService(
|
||||
return (score + 1) / Math.Pow(hours + 2, 1.8);
|
||||
}
|
||||
|
||||
public async Task<List<Activity>> GetActivitiesForAnyone(int take, Instant? cursor,
|
||||
public async Task<List<Common.Models.Activity>> GetActivitiesForAnyone(int take, Instant? cursor,
|
||||
HashSet<string>? debugInclude = null)
|
||||
{
|
||||
var activities = new List<Activity>();
|
||||
var activities = new List<Common.Models.Activity>();
|
||||
debugInclude ??= new HashSet<string>();
|
||||
|
||||
if (cursor == null && (debugInclude.Contains("realms") || Random.Shared.NextDouble() < 0.2))
|
||||
@ -110,12 +110,12 @@ public class ActivityService(
|
||||
activities.Add(post.ToActivity());
|
||||
|
||||
if (activities.Count == 0)
|
||||
activities.Add(Activity.Empty());
|
||||
activities.Add(Common.Models.Activity.Empty());
|
||||
|
||||
return activities;
|
||||
}
|
||||
|
||||
public async Task<List<Activity>> GetActivities(
|
||||
public async Task<List<Common.Models.Activity>> GetActivities(
|
||||
int take,
|
||||
Instant? cursor,
|
||||
Account.Account currentUser,
|
||||
@ -123,8 +123,7 @@ public class ActivityService(
|
||||
HashSet<string>? debugInclude = null
|
||||
)
|
||||
{
|
||||
var activities = new List<Activity>();
|
||||
var userFriends = await rels.ListAccountFriends(currentUser);
|
||||
var activities = new List<Common.Models.Activity>();
|
||||
var userPublishers = await pub.GetUserPublishers(currentUser.Id);
|
||||
debugInclude ??= [];
|
||||
|
||||
@ -191,9 +190,7 @@ public class ActivityService(
|
||||
var filteredPublishers = filter switch
|
||||
{
|
||||
"subscriptions" => await pub.GetSubscribedPublishers(currentUser.Id),
|
||||
"friends" => (await pub.GetUserPublishersBatch(userFriends)).SelectMany(x => x.Value)
|
||||
.DistinctBy(x => x.Id)
|
||||
.ToList(),
|
||||
|
||||
_ => null
|
||||
};
|
||||
|
||||
@ -214,7 +211,7 @@ public class ActivityService(
|
||||
|
||||
// Complete the query with visibility filtering and execute
|
||||
var posts = await postsQuery
|
||||
.FilterWithVisibility(currentUser, userFriends, filter is null ? userPublishers : [], isListing: true)
|
||||
.FilterWithVisibility(filter is null ? userPublishers : [], isListing: true)
|
||||
.Take(take * 5) // Fetch more posts to have a good pool for ranking
|
||||
.ToListAsync();
|
||||
|
||||
@ -245,12 +242,12 @@ public class ActivityService(
|
||||
activities.Add(post.ToActivity());
|
||||
|
||||
if (activities.Count == 0)
|
||||
activities.Add(Activity.Empty());
|
||||
activities.Add(Common.Models.Activity.Empty());
|
||||
|
||||
return activities;
|
||||
}
|
||||
|
||||
private static double CalculatePopularity(List<Post.Post> posts)
|
||||
private static double CalculatePopularity(List<Common.Models.Post> posts)
|
||||
{
|
||||
var score = posts.Sum(p => p.Upvotes - p.Downvotes);
|
||||
var postCount = posts.Count;
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DysonNetwork.Common.Models;
|
||||
using NodaTime;
|
||||
|
||||
namespace DysonNetwork.Sphere.Activity;
|
||||
@ -8,10 +9,10 @@ public class DiscoveryActivity(List<DiscoveryItem> items) : IActivity
|
||||
{
|
||||
public List<DiscoveryItem> Items { get; set; } = items;
|
||||
|
||||
public Activity ToActivity()
|
||||
public Common.Models.Activity ToActivity()
|
||||
{
|
||||
var now = SystemClock.Instance.GetCurrentInstant();
|
||||
return new Activity
|
||||
return new Common.Models.Activity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Type = "discovery",
|
||||
|
Reference in New Issue
Block a user