|
68 | 68 | {
|
69 | 69 | <MudListItem>
|
70 | 70 | <MudTooltip Placement="Placement.Top" ShowOnClick ShowOnHover="false" Arrow Text="@message.SentUtc.DisplayExactTime()">
|
71 |
| - <MudTooltip ShowOnHover Arrow Text="@message.SentUtc.DisplayTimePassed()"> |
| 71 | + <MudTooltip ShowOnHover Arrow Text="@message.SentUtc.DisplayTimePassed()"> |
72 | 72 | <MudChip Class="pl-0 pb-0 chat-chip">
|
73 | 73 | <MudAvatar Size="Size.Medium" Class="mr-2">
|
74 |
| - <MudImage Src="@message.Sender.ProfilePictureUrl" loading="lazy" Alt="Avatar" /> |
| 74 | + <MudImage Src="@GetRecipientsProfilePictureUrl(message)" loading="lazy" Alt="Avatar" /> |
75 | 75 | </MudAvatar>
|
76 | 76 | @message.Text
|
77 | 77 | </MudChip>
|
78 | 78 | </MudTooltip>
|
79 | 79 | </MudTooltip>
|
80 |
| - </MudListItem> |
| 80 | + </MudListItem> |
81 | 81 | }
|
82 | 82 |
|
83 | 83 | </Virtualize>
|
| 84 | + @if (LastMessageWasSentSuccessfully) |
| 85 | + { |
| 86 | + <div title="Din besked er blevet sendt" class="message-sent-successfully-container"> |
| 87 | + <MudIcon Icon="@Icons.Material.Outlined.CheckCircleOutline" |
| 88 | + Class="message-sent-successfully" /> |
| 89 | + </div> |
| 90 | + } |
| 91 | + |
84 | 92 | <MudTextField @bind-Value="_userText"
|
85 | 93 | FullWidth
|
86 | 94 | Immediate
|
|
111 | 119 | private bool _isActiveChatPublished = true;
|
112 | 120 | private bool _isLoading = true;
|
113 | 121 |
|
| 122 | + private Dictionary<Guid, Guid> _lastSuccessfullySentMessageForChat = new(); |
| 123 | + private bool LastMessageWasSentSuccessfully |
| 124 | + { |
| 125 | + get |
| 126 | + { |
| 127 | + if (_activeChat is null) |
| 128 | + { |
| 129 | + return false; |
| 130 | + } |
| 131 | + var lastMessage = _activeChat.Messages.LastOrDefault(); |
| 132 | + if (lastMessage is null) |
| 133 | + { |
| 134 | + return false; |
| 135 | + } |
| 136 | + var lastMessageIsFromCurrentUser = lastMessage.SenderId == _currentUser!.Id; |
| 137 | + |
| 138 | + var lastMessageWasSuccessfullySent = _lastSuccessfullySentMessageForChat.TryGetValue(_activeChat.Id, out var lastSuccessfullySentMessage) && |
| 139 | + lastSuccessfullySentMessage == lastMessage.Id; |
| 140 | + |
| 141 | + return lastMessageIsFromCurrentUser && lastMessageWasSuccessfullySent; |
| 142 | + } |
| 143 | + } |
| 144 | + |
114 | 145 | // TODO: Select currently displayed chat using this, when we update to dotnet 8
|
115 | 146 | [SupplyParameterFromQuery]
|
116 | 147 | public Guid? ChatId { get; set; }
|
|
149 | 180 | {
|
150 | 181 | return;
|
151 | 182 | }
|
152 |
| - if (message.Sender.Id == _currentUser.Id) |
| 183 | + if (message.SenderId == _currentUser.Id) |
153 | 184 | {
|
154 |
| - // TODO: Message should be shown as sent |
| 185 | + _lastSuccessfullySentMessageForChat[chat.Id] = message.Id; |
155 | 186 | return;
|
156 | 187 | }
|
157 | 188 |
|
|
165 | 196 | }
|
166 | 197 | else
|
167 | 198 | {
|
168 |
| - _chats = _chats.OrderByDescending(chat => chat.UnreadMessageCount).ToList(); |
| 199 | + _chats = _chats.OrderByDescending(c => c.UnreadMessageCount).ToList(); |
169 | 200 | chat.UnreadMessageCount++;
|
170 | 201 | StateHasChanged();
|
171 | 202 | }
|
|
223 | 254 | ChatId = _activeChat.Id,
|
224 | 255 | Id = NewId.NextGuid(),
|
225 | 256 | SentUtc = DateTime.UtcNow,
|
226 |
| - Sender = _currentUserSlim, |
| 257 | + SenderId = _currentUserSlim.Id, |
227 | 258 | Text = _userText
|
228 | 259 | };
|
229 | 260 |
|
|
251 | 282 | }
|
252 | 283 | }
|
253 | 284 |
|
254 |
| - private bool IsMessageFromSelf(ChatMessageDto message) => message.Sender.Id == _currentUser!.Id; |
| 285 | + private bool IsMessageFromSelf(ChatMessageDto message) => message.SenderId == _currentUser!.Id; |
255 | 286 |
|
256 | 287 | private async Task StartNewChat(IEnumerable<UserSlim> users)
|
257 | 288 | {
|
|
293 | 324 |
|
294 | 325 | await SelectChat(newChat);
|
295 | 326 | }
|
| 327 | + |
| 328 | + private string GetRecipientsProfilePictureUrl(ChatMessageDto message) |
| 329 | + { |
| 330 | + return _activeChat?.Recipients.FirstOrDefault(recipient => recipient.Id == message.SenderId)?.ProfilePictureUrl ?? ProfileConstants.Default_Profile_Picture; |
| 331 | + } |
| 332 | + |
296 | 333 | }
|
0 commit comments