| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class PrivateChatHUDView : ChatHUDView |
| | 6 | | { |
| | 7 | | [SerializeField] private DateSeparatorEntry separatorEntryPrefab; |
| | 8 | |
|
| 17 | 9 | | private readonly Dictionary<string, DateSeparatorEntry> dateSeparators = new Dictionary<string, DateSeparatorEntry>( |
| | 10 | |
|
| | 11 | | public override void AddEntry(ChatEntryModel model, bool setScrollPositionToBottom = false) |
| | 12 | | { |
| 0 | 13 | | AddSeparatorEntryIfNeeded(model); |
| 0 | 14 | | base.AddEntry(model, setScrollPositionToBottom); |
| 0 | 15 | | } |
| | 16 | |
|
| | 17 | | private void AddSeparatorEntryIfNeeded(ChatEntryModel chatEntryModel) |
| | 18 | | { |
| 0 | 19 | | var entryDateTime = GetDateTimeFromUnixTimestampMilliseconds(chatEntryModel.timestamp).Date; |
| 0 | 20 | | var separatorId = $"{entryDateTime.Ticks}"; |
| 0 | 21 | | if (dateSeparators.ContainsKey(separatorId)) return; |
| 0 | 22 | | var dateSeparatorEntry = Instantiate(separatorEntryPrefab, chatEntriesContainer); |
| 0 | 23 | | dateSeparatorEntry.Populate(chatEntryModel); |
| 0 | 24 | | dateSeparatorEntry.SetFadeout(IsFadeoutModeEnabled); |
| 0 | 25 | | dateSeparators[separatorId] = dateSeparatorEntry; |
| 0 | 26 | | SetEntry(separatorId, dateSeparatorEntry); |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | private DateTime GetDateTimeFromUnixTimestampMilliseconds(ulong milliseconds) |
| | 30 | | { |
| 0 | 31 | | DateTime result = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); |
| 0 | 32 | | return result.AddMilliseconds(milliseconds); |
| | 33 | | } |
| | 34 | | } |