mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Runtime.CompilerServices;
|
|
using RadicadeServer.API.Notifications;
|
|
using RadicadeServer.DB;
|
|
using RadicadeServer.Extensions;
|
|
using RadicadeServer.RecNet.Enums.Messages;
|
|
using RadicadeServer.RecNet.Messages;
|
|
using RadicadeServer.RecNet.Notifications;
|
|
using RadicadeServer.RecNet.Relationships;
|
|
|
|
namespace RadicadeServer.API.Relationships
|
|
{
|
|
public static class RelationshipsShared
|
|
{
|
|
internal static IDbContextFactory<RecDBContext> DbFactory = null!;
|
|
|
|
internal static async Task<RealRelationship> GetOrCreate(RecDBContext db, long accountId, long playerId)
|
|
{
|
|
var rel = await db.Relationships.FirstOrDefaultAsync(x => x.AccountId == accountId && x.PlayerId == playerId);
|
|
if (rel == null)
|
|
{
|
|
rel = new RealRelationship { AccountId = accountId, PlayerId = playerId };
|
|
await db.Relationships.AddAsync(rel);
|
|
}
|
|
|
|
await db.SaveChangesAsync();
|
|
|
|
return rel;
|
|
}
|
|
|
|
internal static void SetReciprocalStatus(
|
|
RealRelationship mine, RealRelationship theirs,
|
|
Func<RealRelationship, ReciprocalStatus> getter,
|
|
Action<RealRelationship, ReciprocalStatus> setter,
|
|
bool enabling)
|
|
{
|
|
if (enabling)
|
|
{
|
|
var theirStatus = getter(theirs);
|
|
bool theyHaveIt = theirStatus == ReciprocalStatus.Local || theirStatus == ReciprocalStatus.Mutual;
|
|
setter(mine, theyHaveIt ? ReciprocalStatus.Mutual : ReciprocalStatus.Local);
|
|
setter(theirs, theyHaveIt ? ReciprocalStatus.Mutual : ReciprocalStatus.Remote);
|
|
}
|
|
else
|
|
{
|
|
var theirStatus = getter(theirs);
|
|
setter(mine, ReciprocalStatus.None);
|
|
setter(theirs, theirStatus == ReciprocalStatus.Mutual ? ReciprocalStatus.Remote : ReciprocalStatus.None);
|
|
}
|
|
}
|
|
}
|
|
}
|