💥 Update activity data format
This commit is contained in:
parent
c63d6e0fbc
commit
b7263b9804
@ -1,4 +1,3 @@
|
||||
|
||||
using DysonNetwork.Sphere.Account;
|
||||
using DysonNetwork.Sphere.Discovery;
|
||||
using DysonNetwork.Sphere.Post;
|
||||
@ -12,9 +11,14 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace DysonNetwork.Sphere.Activity;
|
||||
|
||||
public class ActivityService(AppDatabase db, PublisherService pub, RelationshipService rels, PostService ps, DiscoveryService ds)
|
||||
public class ActivityService(
|
||||
AppDatabase db,
|
||||
PublisherService pub,
|
||||
RelationshipService rels,
|
||||
PostService ps,
|
||||
DiscoveryService ds)
|
||||
{
|
||||
private double CalculateHotRank(Post.Post post, Instant now)
|
||||
private static double CalculateHotRank(Post.Post post, Instant now)
|
||||
{
|
||||
var score = post.Upvotes - post.Downvotes;
|
||||
var postTime = post.PublishedAt ?? post.CreatedAt;
|
||||
@ -32,7 +36,9 @@ public class ActivityService(AppDatabase db, PublisherService pub, RelationshipS
|
||||
var realms = await ds.GetPublicRealmsAsync(null, null, 5, 0, true);
|
||||
if (realms.Count > 0)
|
||||
{
|
||||
activities.Add(new DiscoveryActivity("Explore Realms", realms.Cast<object>().ToList()).ToActivity());
|
||||
activities.Add(new DiscoveryActivity(
|
||||
realms.Select(x => new DiscoveryItem("realm", x)).ToList()
|
||||
).ToActivity());
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +98,9 @@ public class ActivityService(AppDatabase db, PublisherService pub, RelationshipS
|
||||
var realms = await ds.GetPublicRealmsAsync(null, null, 5, 0, true);
|
||||
if (realms.Count > 0)
|
||||
{
|
||||
activities.Add(new DiscoveryActivity("Explore Realms", realms.Cast<object>().ToList()).ToActivity());
|
||||
activities.Add(new DiscoveryActivity(
|
||||
realms.Select(x => new DiscoveryItem("realm", x)).ToList()
|
||||
).ToActivity());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,31 +2,25 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using NodaTime;
|
||||
|
||||
namespace DysonNetwork.Sphere.Activity
|
||||
namespace DysonNetwork.Sphere.Activity;
|
||||
|
||||
public class DiscoveryActivity(List<DiscoveryItem> items) : IActivity
|
||||
{
|
||||
public class DiscoveryActivity : IActivity
|
||||
public List<DiscoveryItem> Items { get; set; } = items;
|
||||
|
||||
public Activity ToActivity()
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public List<object> Items { get; set; }
|
||||
|
||||
public DiscoveryActivity(string title, List<object> items)
|
||||
var now = SystemClock.Instance.GetCurrentInstant();
|
||||
return new Activity
|
||||
{
|
||||
Title = title;
|
||||
Items = items;
|
||||
}
|
||||
|
||||
public Activity ToActivity()
|
||||
{
|
||||
var now = SystemClock.Instance.GetCurrentInstant();
|
||||
return new Activity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Type = "discovery",
|
||||
ResourceIdentifier = "discovery",
|
||||
Data = this,
|
||||
CreatedAt = now,
|
||||
UpdatedAt = now,
|
||||
};
|
||||
}
|
||||
Id = Guid.NewGuid(),
|
||||
Type = "discovery",
|
||||
ResourceIdentifier = "discovery",
|
||||
Data = this,
|
||||
CreatedAt = now,
|
||||
UpdatedAt = now,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public record DiscoveryItem(string Type, object Data);
|
Loading…
x
Reference in New Issue
Block a user