feat(backend): add support conversations
This commit is contained in:
parent
a4ca0902a3
commit
ed3159c05d
12 changed files with 620 additions and 0 deletions
47
Foxnouns.Backend/Services/SupportRendererService.cs
Normal file
47
Foxnouns.Backend/Services/SupportRendererService.cs
Normal 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
|
||||
);
|
||||
}
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue