♻️ Centralized data models (wip)
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using DysonNetwork.Shared.Data;
|
||||
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,3 +1,4 @@
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using DysonNetwork.Sphere.Discovery;
|
||||
using DysonNetwork.Sphere.Post;
|
||||
@@ -17,7 +18,7 @@ public class ActivityService(
|
||||
AccountService.AccountServiceClient accounts
|
||||
)
|
||||
{
|
||||
private static double CalculateHotRank(Post.Post post, Instant now)
|
||||
private static double CalculateHotRank(SnPost post, Instant now)
|
||||
{
|
||||
var performanceScore = post.Upvotes - post.Downvotes + post.RepliesCount + (int)post.AwardedScore / 10;
|
||||
var postTime = post.PublishedAt ?? post.CreatedAt;
|
||||
@@ -163,7 +164,7 @@ public class ActivityService(
|
||||
return await pick();
|
||||
}
|
||||
|
||||
private static List<Post.Post> RankPosts(List<Post.Post> posts, int take)
|
||||
private static List<SnPost> RankPosts(List<SnPost> posts, int take)
|
||||
{
|
||||
var now = SystemClock.Instance.GetCurrentInstant();
|
||||
return posts
|
||||
@@ -175,7 +176,7 @@ public class ActivityService(
|
||||
// return posts.Take(take).ToList();
|
||||
}
|
||||
|
||||
private async Task<List<Publisher.Publisher>> GetPopularPublishers(int take)
|
||||
private async Task<List<Shared.Models.SnPublisher>> GetPopularPublishers(int take)
|
||||
{
|
||||
var now = SystemClock.Instance.GetCurrentInstant();
|
||||
var recent = now.Minus(Duration.FromDays(7));
|
||||
@@ -268,11 +269,11 @@ public class ActivityService(
|
||||
: null;
|
||||
}
|
||||
|
||||
private async Task<List<Post.Post>> GetAndProcessPosts(
|
||||
IQueryable<Post.Post> baseQuery,
|
||||
private async Task<List<SnPost>> GetAndProcessPosts(
|
||||
IQueryable<SnPost> baseQuery,
|
||||
Account? currentUser = null,
|
||||
List<Guid>? userFriends = null,
|
||||
List<Publisher.Publisher>? userPublishers = null,
|
||||
List<Shared.Models.SnPublisher>? userPublishers = null,
|
||||
bool trackViews = true)
|
||||
{
|
||||
var posts = await baseQuery.ToListAsync();
|
||||
@@ -294,7 +295,7 @@ public class ActivityService(
|
||||
return posts;
|
||||
}
|
||||
|
||||
private IQueryable<Post.Post> BuildPostsQuery(
|
||||
private IQueryable<SnPost> BuildPostsQuery(
|
||||
Instant? cursor,
|
||||
List<Guid>? filteredPublishersId = null,
|
||||
List<Guid>? userRealms = null
|
||||
@@ -322,7 +323,7 @@ public class ActivityService(
|
||||
return query;
|
||||
}
|
||||
|
||||
private async Task<List<Publisher.Publisher>?> GetFilteredPublishers(
|
||||
private async Task<List<Shared.Models.SnPublisher>?> GetFilteredPublishers(
|
||||
string? filter,
|
||||
Account currentUser,
|
||||
List<Guid> userFriends)
|
||||
@@ -338,7 +339,7 @@ public class ActivityService(
|
||||
};
|
||||
}
|
||||
|
||||
private static double CalculatePopularity(List<Post.Post> posts)
|
||||
private static double CalculatePopularity(List<SnPost> 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.Shared.Models;
|
||||
using NodaTime;
|
||||
|
||||
namespace DysonNetwork.Sphere.Activity;
|
||||
|
Reference in New Issue
Block a user