using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Text.Json.Serialization; using System.Threading.Tasks; using gehGassiApp.Domain.Base; using gehGassiApp.Domain.Common; namespace gehGassiApp.Domain.Messages { /// /// Repräsentiert eine Konversation zwischen 2 Benutzern /// public class Conversation : SyncEntity { /// /// Ziel der Konversation - UserId /// [Required] [MaxLength(128)] [JsonPropertyName("recipient")] public string Recipient { get; set; } /// /// Typ des Empfängers. DogOwner oder DogWalker /// [JsonPropertyName("receipientType")] public AppUserType ReceipientType { get; set; } /// /// Name des Addressaten /// [MaxLength(300)] [JsonPropertyName("recipientName")] public string RecipientName { get; set; } /// /// Kürzel des Addressaten /// [MaxLength(2)] [JsonPropertyName("recipientShort")] public string RecipientShort { get; set; } /// /// Foto /// [JsonPropertyName("recipientPhoto")] public string RecipientPhoto { get; set; } /// /// Id der letzten Nachricht /// [MaxLength(128)] [JsonPropertyName("lastMessageId")] public string LastMessageId { get; set; } /// /// Vorschautext der letzten Nachricht /// [JsonPropertyName("lastMessagePreview")] public string LastMessagePreview { get; set; } /// /// Gibt an ob ungelesene Nachrichten enthalten sind /// [JsonPropertyName("hasUnreadMessages")] public bool HasUnreadMessages { get; set; } /// /// Wann wurde die Konversation erstellt /// [Required] [JsonPropertyName("created")] public DateTimeOffset Created { get; set; } /// /// Vorname + Nachname erster Buchstabe + Punkt, oder nur Vorname wenn kein Nachname /// [NotMapped] [JsonIgnore] public string RecipientFullNameShort { get { if (!string.IsNullOrWhiteSpace(RecipientName)) { var parts = RecipientName.Split(" "); var firstName = parts[0]; var lastName = string.Empty; if (parts.Length > 1) lastName = parts[1]; return string.IsNullOrWhiteSpace(lastName) ? firstName : $"{firstName} {lastName[..1]}."; } return string.Empty; } } } }