Implement message preview feature for support tickets
- Added a new property `MessagePreview` to the `TicketSummaryDto` to display the truncated first message of a ticket. - Updated the `TicketMapping` class to retrieve the first message for each ticket and truncate it for preview purposes. - Modified the `SupportTicketList` and `AdminSupportPage` components to conditionally render the message preview in the ticket list, enhancing user experience by providing context at a glance.
This commit is contained in:
@@ -99,6 +99,18 @@ internal static class TicketMapping
|
||||
.Select(g => new { TicketId = g.Key, Last = g.Max(c => c.CreatedAt) })
|
||||
.ToDictionaryAsync(x => x.TicketId, x => x.Last, cancellationToken);
|
||||
|
||||
// Первое сообщение (не последний комментарий) — это исходный текст обращения, а не переписка.
|
||||
var firstMessages = await dbContext
|
||||
.TicketComments.AsNoTracking()
|
||||
.Where(c => ticketIds.Contains(c.TicketId))
|
||||
.GroupBy(c => c.TicketId)
|
||||
.Select(g => new
|
||||
{
|
||||
TicketId = g.Key,
|
||||
Body = g.OrderBy(c => c.CreatedAt).Select(c => c.Body).First(),
|
||||
})
|
||||
.ToDictionaryAsync(x => x.TicketId, x => x.Body, cancellationToken);
|
||||
|
||||
var userIds = tickets.Select(t => t.UserId).Distinct().ToList();
|
||||
var userNames = await identityService.GetUserNamesAsync(userIds, cancellationToken);
|
||||
|
||||
@@ -110,8 +122,17 @@ internal static class TicketMapping
|
||||
t.Type,
|
||||
t.Status,
|
||||
t.CreatedAt,
|
||||
lastActivity.GetValueOrDefault(t.Id, t.CreatedAt)
|
||||
lastActivity.GetValueOrDefault(t.Id, t.CreatedAt),
|
||||
TruncatePreview(firstMessages.GetValueOrDefault(t.Id))
|
||||
))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static string? TruncatePreview(string? message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return message;
|
||||
|
||||
return message.Length > 200 ? message[..200] + "…" : message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ using PnvPanel.Domain.Support;
|
||||
namespace PnvPanel.Application.Support;
|
||||
|
||||
/// <summary>Строка списка тикетов — свой (ListMyTicketsQuery) и админский (ListAllTicketsQuery) списки
|
||||
/// используют один и тот же DTO (владелец видит только свои UserId/UserName — не секрет для себя).</summary>
|
||||
/// используют один и тот же DTO (владелец видит только свои UserId/UserName — не секрет для себя).
|
||||
/// MessagePreview — начало первого сообщения тикета (обрезано), для превью в списке.</summary>
|
||||
public sealed record TicketSummaryDto(
|
||||
Guid Id,
|
||||
Guid UserId,
|
||||
@@ -11,5 +12,6 @@ public sealed record TicketSummaryDto(
|
||||
TicketType Type,
|
||||
TicketStatus Status,
|
||||
DateTimeOffset CreatedAt,
|
||||
DateTimeOffset LastActivityAt
|
||||
DateTimeOffset LastActivityAt,
|
||||
string? MessagePreview
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user