feat(backend): add support conversations

This commit is contained in:
sam 2024-10-03 19:27:26 +02:00
parent a4ca0902a3
commit ed3159c05d
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
12 changed files with 620 additions and 0 deletions

View file

@ -0,0 +1,47 @@
using Foxnouns.Backend.Database;
using Foxnouns.Backend.Database.Models;
using Foxnouns.Backend.Utils;
using Newtonsoft.Json;
namespace Foxnouns.Backend.Services;
public class SupportRendererService(UserRendererService userRenderer)
{
public ConversationResponse ToResponse(SupportConversation c) =>
new(
c.Id,
userRenderer.RenderPartialUser(c.User),
c.Title,
userRenderer.TryRenderPartialUser(c.AssignedTo),
c.Status
);
public MessageResponse ToResponse(SupportMessage m, bool modView = false) =>
new(
m.Id,
m.IsAnonymous
? modView
? userRenderer.RenderPartialUser(m.User)
: null
: userRenderer.RenderPartialUser(m.User),
m.IsAnonymous,
m.Content
);
public record ConversationResponse(
Snowflake Id,
UserRendererService.PartialUser User,
string Title,
UserRendererService.PartialUser? AssignedTo,
[property: JsonConverter(typeof(ScreamingSnakeCaseEnumConverter))]
SupportConversationStatus Status
);
public record MessageResponse(
Snowflake Id,
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
UserRendererService.PartialUser? User,
bool IsAnonymous,
string? Content
);
}

View file

@ -92,6 +92,9 @@ public class UserRendererService(
user.CustomPreferences
);
public PartialUser? TryRenderPartialUser(User? user) =>
user != null ? RenderPartialUser(user) : null;
private string? AvatarUrlFor(User user) =>
user.Avatar != null
? $"{config.MediaBaseUrl}/users/{user.Id}/avatars/{user.Avatar}.webp"