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