| | 1 | | using System; |
| | 2 | | using System.Globalization; |
| | 3 | | using DCL.Chat.HUD; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | /// <summary> |
| | 8 | | /// Special type of entry to be used as date separator in chat conversations. |
| | 9 | | /// </summary> |
| | 10 | | public class DateSeparatorEntry : ChatEntry |
| | 11 | | { |
| | 12 | | [SerializeField] internal TextMeshProUGUI title; |
| | 13 | |
|
| | 14 | | private DateTime timestamp; |
| | 15 | | private ChatEntryModel chatEntryModel; |
| | 16 | |
|
| | 17 | | public override string DateString => |
| 0 | 18 | | GetDateFormat(GetDateTimeFromUnixTimestampMilliseconds(Model.timestamp)); |
| | 19 | | public override event Action<ChatEntry> OnUserNameClicked; |
| | 20 | | public override event Action<ChatEntry> OnTriggerHover; |
| | 21 | | public override event Action<ChatEntry, ParcelCoordinates> OnTriggerHoverGoto; |
| | 22 | | public override event Action OnCancelHover; |
| | 23 | | public override event Action OnCancelGotoHover; |
| 0 | 24 | | public override ChatEntryModel Model => chatEntryModel; |
| | 25 | |
|
| | 26 | | public override void Populate(ChatEntryModel model) |
| | 27 | | { |
| 2 | 28 | | chatEntryModel = model; |
| 2 | 29 | | title.text = GetDateFormat(GetDateTimeFromUnixTimestampMilliseconds(model.timestamp)); |
| 2 | 30 | | } |
| | 31 | |
|
| | 32 | | public override void SetFadeout(bool enabled) |
| | 33 | | { |
| 0 | 34 | | if (enabled) return; |
| 0 | 35 | | group.alpha = 1; |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | public override void DockContextMenu(RectTransform panel) |
| | 39 | | { |
| 0 | 40 | | } |
| | 41 | |
|
| | 42 | | public override void DockHoverPanel(RectTransform panel) |
| | 43 | | { |
| 0 | 44 | | } |
| | 45 | |
|
| | 46 | | private string GetDateFormat(DateTime date) |
| | 47 | | { |
| 2 | 48 | | string result = string.Empty; |
| | 49 | |
|
| 2 | 50 | | if (date.Year == DateTime.Now.Year && |
| | 51 | | date.Month == DateTime.Now.Month && |
| | 52 | | date.Day == DateTime.Now.Day) |
| | 53 | | { |
| 1 | 54 | | result = "Today"; |
| 1 | 55 | | } |
| | 56 | | else |
| | 57 | | { |
| 1 | 58 | | result = date.ToString("D", DateTimeFormatInfo.InvariantInfo); |
| | 59 | | } |
| | 60 | |
|
| 2 | 61 | | return result; |
| | 62 | | } |
| | 63 | |
|
| | 64 | | private DateTime GetDateTimeFromUnixTimestampMilliseconds(ulong milliseconds) |
| | 65 | | { |
| 2 | 66 | | DateTime result = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); |
| 2 | 67 | | return result.AddMilliseconds(milliseconds); |
| | 68 | | } |
| | 69 | | } |