| | 1 | | using DCL.Social.Chat; |
| | 2 | | using System; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | namespace DCL.Social.Chat |
| | 8 | | { |
| | 9 | | public class PublicChatEntry : BaseComponentView, IComponentModelConfig<PublicChatEntryModel> |
| | 10 | | { |
| | 11 | | [SerializeField] internal Button openChatButton; |
| | 12 | | [SerializeField] internal TMP_Text nameLabel; |
| | 13 | | [SerializeField] internal PublicChatEntryModel model; |
| | 14 | | [SerializeField] internal UnreadNotificationBadge unreadNotifications; |
| 57 | 15 | | [SerializeField] internal string namePrefix = "#"; |
| | 16 | | [SerializeField] internal TMP_Text memberCountLabel; |
| | 17 | | [SerializeField] internal Button optionsButton; |
| | 18 | | [SerializeField] internal Button leaveButton; |
| | 19 | | [SerializeField] internal Button joinButton; |
| | 20 | | [SerializeField] internal GameObject leaveButtonContainer; |
| | 21 | | [SerializeField] internal GameObject openChatContainer; |
| | 22 | | [SerializeField] internal GameObject joinedContainer; |
| | 23 | | [SerializeField] internal Toggle muteNotificationsToggle; |
| | 24 | |
|
| | 25 | | private IChatController chatController; |
| | 26 | | private DataStore_Mentions mentionsDataStore; |
| | 27 | |
|
| 5 | 28 | | public PublicChatEntryModel Model => model; |
| | 29 | |
|
| | 30 | | public event Action<PublicChatEntry> OnOpenChat; |
| | 31 | | public event Action<PublicChatEntry> OnLeave; |
| | 32 | | public event Action<PublicChatEntry> OnJoin; |
| | 33 | | public event Action<PublicChatEntry> OnOpenOptions; |
| | 34 | |
|
| | 35 | | public override void Awake() |
| | 36 | | { |
| 53 | 37 | | base.Awake(); |
| 56 | 38 | | openChatButton.onClick.AddListener(() => OnOpenChat?.Invoke(this)); |
| | 39 | |
|
| 53 | 40 | | if (optionsButton) |
| 29 | 41 | | optionsButton.onClick.AddListener(() => OnOpenOptions?.Invoke(this)); |
| | 42 | |
|
| 53 | 43 | | if (leaveButton) |
| 28 | 44 | | leaveButton.onClick.AddListener(() => OnLeave?.Invoke(this)); |
| | 45 | |
|
| 53 | 46 | | if (joinButton) |
| 26 | 47 | | joinButton.onClick.AddListener(() => OnJoin?.Invoke(this)); |
| 53 | 48 | | } |
| | 49 | |
|
| | 50 | | public void Initialize( |
| | 51 | | IChatController chatController, |
| | 52 | | DataStore_Mentions mentionsDataStore) |
| | 53 | | { |
| 37 | 54 | | this.chatController = chatController; |
| 37 | 55 | | this.mentionsDataStore = mentionsDataStore; |
| 37 | 56 | | } |
| | 57 | |
|
| | 58 | | public void Configure(PublicChatEntryModel newModel) |
| | 59 | | { |
| 53 | 60 | | model = newModel; |
| 53 | 61 | | RefreshControl(); |
| 53 | 62 | | } |
| | 63 | |
|
| | 64 | | public override void RefreshControl() |
| | 65 | | { |
| 53 | 66 | | nameLabel.text = $"{namePrefix}{model.name}"; |
| 53 | 67 | | if (unreadNotifications) |
| 29 | 68 | | unreadNotifications.Initialize(chatController, model.channelId, mentionsDataStore); |
| 53 | 69 | | if (memberCountLabel) |
| 53 | 70 | | memberCountLabel.SetText($"{model.memberCount} members {(model.showOnlyOnlineMembers ? "online" : "joine |
| 53 | 71 | | if (joinedContainer) |
| 24 | 72 | | joinedContainer.SetActive(model.isJoined); |
| 53 | 73 | | if (leaveButtonContainer) |
| 24 | 74 | | leaveButtonContainer.SetActive(model.isJoined); |
| 53 | 75 | | if (openChatContainer) |
| 24 | 76 | | openChatContainer.SetActive(!model.isJoined); |
| 53 | 77 | | if (muteNotificationsToggle) |
| 29 | 78 | | muteNotificationsToggle.SetIsOnWithoutNotify(model.muted); |
| 53 | 79 | | } |
| | 80 | |
|
| | 81 | | public void Dock(ChannelContextualMenu contextualMenu) |
| | 82 | | { |
| 1 | 83 | | contextualMenu.transform.position = optionsButton.transform.position; |
| 1 | 84 | | } |
| | 85 | | } |
| | 86 | | } |