diff --git a/DysonNetwork.Pass/Account/Account.cs b/DysonNetwork.Pass/Account/Account.cs index 5f378e1..fd68e8f 100644 --- a/DysonNetwork.Pass/Account/Account.cs +++ b/DysonNetwork.Pass/Account/Account.cs @@ -20,7 +20,7 @@ public class Account : ModelBase [MaxLength(32)] public string Language { get; set; } = string.Empty; public Instant? ActivatedAt { get; set; } public bool IsSuperuser { get; set; } = false; - + // The ID is the BotAccount ID in the DysonNetwork.Develop public Guid? AutomatedId { get; set; } @@ -135,8 +135,19 @@ public class AccountProfile : ModelBase, IIdentifiedResource [Column(TypeName = "jsonb")] public VerificationMark? Verification { get; set; } [Column(TypeName = "jsonb")] public BadgeReferenceObject? ActiveBadge { get; set; } - public int Experience { get; set; } = 0; + public int Experience { get; set; } [NotMapped] public int Level => Leveling.ExperiencePerLevel.Count(xp => Experience >= xp) - 1; + + public double SocialCredits { get; set; } + + [NotMapped] + public int SocialCreditsLevel => SocialCredits switch + { + < 100 => -1, + > 100 and < 200 => 0, + < 200 => 1, + _ => 2 + }; [NotMapped] public double LevelingProgress => Level >= Leveling.ExperiencePerLevel.Count - 1 @@ -168,6 +179,8 @@ public class AccountProfile : ModelBase, IIdentifiedResource Experience = Experience, Level = Level, LevelingProgress = LevelingProgress, + SocialCredits = SocialCredits, + SocialCreditsLevel = SocialCreditsLevel, Picture = Picture?.ToProtoValue(), Background = Background?.ToProtoValue(), AccountId = AccountId.ToString(), @@ -198,6 +211,7 @@ public class AccountProfile : ModelBase, IIdentifiedResource Verification = proto.Verification is null ? null : VerificationMark.FromProtoValue(proto.Verification), ActiveBadge = proto.ActiveBadge is null ? null : BadgeReferenceObject.FromProtoValue(proto.ActiveBadge), Experience = proto.Experience, + SocialCredits = proto.SocialCredits, Picture = proto.Picture is null ? null : CloudFileReferenceObject.FromProtoValue(proto.Picture), Background = proto.Background is null ? null : CloudFileReferenceObject.FromProtoValue(proto.Background), AccountId = Guid.Parse(proto.AccountId), diff --git a/DysonNetwork.Pass/Credit/SocialCreditService.cs b/DysonNetwork.Pass/Credit/SocialCreditService.cs index 8b9d196..5f8380e 100644 --- a/DysonNetwork.Pass/Credit/SocialCreditService.cs +++ b/DysonNetwork.Pass/Credit/SocialCreditService.cs @@ -18,6 +18,13 @@ public class SocialCreditService(AppDatabase db, ICacheService cache) }; db.SocialCreditRecords.Add(record); await db.SaveChangesAsync(); + + await db.AccountProfiles + .Where(p => p.AccountId == accountId) + .ExecuteUpdateAsync(p => p.SetProperty(v => v.SocialCredits, v => v.SocialCredits + record.Delta)); + + await cache.RemoveAsync($"{CacheKeyPrefix}{accountId}"); + return record; } @@ -32,6 +39,7 @@ public class SocialCreditService(AppDatabase db, ICacheService cache) .Where(x => x.AccountId == accountId) .SumAsync(x => x.Delta); records += BaseSocialCredit; + await cache.SetAsync($"{CacheKeyPrefix}{accountId}", records); return records; } diff --git a/DysonNetwork.Pass/Migrations/AppDatabaseModelSnapshot.cs b/DysonNetwork.Pass/Migrations/AppDatabaseModelSnapshot.cs index a909b3d..736bcc5 100644 --- a/DysonNetwork.Pass/Migrations/AppDatabaseModelSnapshot.cs +++ b/DysonNetwork.Pass/Migrations/AppDatabaseModelSnapshot.cs @@ -462,6 +462,10 @@ namespace DysonNetwork.Pass.Migrations .HasColumnType("character varying(1024)") .HasColumnName("pronouns"); + b.Property("SocialCredits") + .HasColumnType("double precision") + .HasColumnName("social_credits"); + b.Property("TimeZone") .HasMaxLength(1024) .HasColumnType("character varying(1024)") diff --git a/DysonNetwork.Shared/Proto/account.proto b/DysonNetwork.Shared/Proto/account.proto index 51ddd22..2de26ee 100644 --- a/DysonNetwork.Shared/Proto/account.proto +++ b/DysonNetwork.Shared/Proto/account.proto @@ -75,6 +75,8 @@ message AccountProfile { int32 experience = 14; int32 level = 15; double leveling_progress = 16; + double social_credits = 17; + int32 social_credits_level = 18; CloudFile picture = 19; CloudFile background = 20;