| | 1 | | using System; |
| | 2 | | using System.Text.RegularExpressions; |
| | 3 | | using DCL.Chat.HUD; |
| | 4 | | using UIComponents.CollapsableSortedList; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | public class CollapsablePublicChannelListComponentView : CollapsableSortedListComponentView<string, PublicChatEntry> |
| | 8 | | { |
| | 9 | | [SerializeField] private ChannelEntryFactory entryFactory; |
| | 10 | |
|
| | 11 | | private IChatController chatController; |
| | 12 | |
|
| | 13 | | public event Action<PublicChatEntry> OnOpenChat; |
| | 14 | |
|
| | 15 | | public void Initialize(IChatController chatController) |
| | 16 | | { |
| 0 | 17 | | this.chatController = chatController; |
| 0 | 18 | | } |
| | 19 | |
|
| | 20 | | public void Filter(string search) |
| | 21 | | { |
| 0 | 22 | | var regex = new Regex(search, RegexOptions.IgnoreCase); |
| 0 | 23 | | Filter(entry => regex.IsMatch(entry.Model.name)); |
| 0 | 24 | | } |
| | 25 | |
|
| | 26 | | public override PublicChatEntry Remove(string key) |
| | 27 | | { |
| 9 | 28 | | var entry = base.Remove(key); |
| | 29 | |
|
| 9 | 30 | | if (entry) |
| 8 | 31 | | Destroy(entry.gameObject); |
| | 32 | |
|
| 9 | 33 | | return entry; |
| | 34 | | } |
| | 35 | |
|
| | 36 | | public void Set(string channelId, PublicChatEntryModel entryModel) |
| | 37 | | { |
| 38 | 38 | | if (!Contains(entryModel.channelId)) |
| 32 | 39 | | CreateEntry(channelId); |
| | 40 | |
|
| 38 | 41 | | var entry = Get(channelId); |
| 38 | 42 | | entry.Configure(entryModel); |
| 38 | 43 | | } |
| | 44 | |
|
| | 45 | | private void CreateEntry(string channelId) |
| | 46 | | { |
| 32 | 47 | | var newFriendEntry = entryFactory.Create(channelId); |
| 32 | 48 | | var entry = newFriendEntry.gameObject.GetComponent<PublicChatEntry>(); |
| 32 | 49 | | Add(channelId, entry); |
| 32 | 50 | | entry.Initialize(chatController); |
| 32 | 51 | | entry.OnOpenChat -= HandleEntryOpenChat; |
| 32 | 52 | | entry.OnOpenChat += HandleEntryOpenChat; |
| 32 | 53 | | } |
| | 54 | |
|
| 1 | 55 | | private void HandleEntryOpenChat(PublicChatEntry entry) => OnOpenChat?.Invoke(entry); |
| | 56 | | } |