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