| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL.Social.Chat |
| | 6 | | { |
| | 7 | | public class PrivateChatHUDView : ChatHUDView |
| | 8 | | { |
| | 9 | | [SerializeField] private PoolPrivateChatEntryFactory chatEntryFactory; |
| | 10 | |
|
| 15 | 11 | | private readonly Dictionary<string, DateSeparatorEntry> dateSeparators = new (); |
| | 12 | |
|
| | 13 | | public override void Awake() |
| | 14 | | { |
| 14 | 15 | | base.Awake(); |
| 14 | 16 | | ChatEntryFactory = chatEntryFactory; |
| 14 | 17 | | } |
| | 18 | |
|
| | 19 | | public override void SetEntry(ChatEntryModel model, bool setScrollPositionToBottom = false) |
| | 20 | | { |
| 0 | 21 | | AddSeparatorEntryIfNeeded(model); |
| 0 | 22 | | base.SetEntry(model, setScrollPositionToBottom); |
| 0 | 23 | | } |
| | 24 | |
|
| | 25 | | public override void ClearAllEntries() |
| | 26 | | { |
| 0 | 27 | | base.ClearAllEntries(); |
| 0 | 28 | | dateSeparators.Clear(); |
| 0 | 29 | | } |
| | 30 | |
|
| | 31 | | private void AddSeparatorEntryIfNeeded(ChatEntryModel chatEntryModel) |
| | 32 | | { |
| 0 | 33 | | var entryDateTime = DateTimeOffset.FromUnixTimeMilliseconds((long) chatEntryModel.timestamp).Date; |
| 0 | 34 | | var separatorId = entryDateTime.Ticks.ToString(); |
| 0 | 35 | | if (dateSeparators.ContainsKey(separatorId)) return; |
| 0 | 36 | | var dateSeparatorEntry = chatEntryFactory.CreateDateSeparator(); |
| 0 | 37 | | Dock(dateSeparatorEntry); |
| 0 | 38 | | Populate(dateSeparatorEntry, chatEntryModel); |
| 0 | 39 | | dateSeparators[separatorId] = dateSeparatorEntry; |
| 0 | 40 | | SetEntry(separatorId, dateSeparatorEntry); |
| 0 | 41 | | } |
| | 42 | | } |
| | 43 | | } |