| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public class PublicChannelEntry : BaseComponentView, IComponentModelConfig |
| | 7 | | { |
| | 8 | | [SerializeField] internal Button openChatButton; |
| | 9 | | [SerializeField] internal TMP_Text nameLabel; |
| | 10 | | [SerializeField] internal PublicChannelEntryModel model; |
| | 11 | | [SerializeField] internal UnreadNotificationBadge unreadNotifications; |
| | 12 | |
|
| | 13 | | private IChatController chatController; |
| | 14 | | private ILastReadMessagesService lastReadMessagesService; |
| | 15 | |
|
| 0 | 16 | | public PublicChannelEntryModel Model => model; |
| | 17 | |
|
| | 18 | | public event Action<PublicChannelEntry> OnOpenChat; |
| | 19 | |
|
| | 20 | | public static PublicChannelEntry Create() |
| | 21 | | { |
| 2 | 22 | | return Instantiate(Resources.Load<PublicChannelEntry>("SocialBarV1/PublicChannelElement")); |
| | 23 | | } |
| | 24 | |
|
| | 25 | | public override void Awake() |
| | 26 | | { |
| 21 | 27 | | base.Awake(); |
| 23 | 28 | | openChatButton.onClick.AddListener(() => OnOpenChat?.Invoke(this)); |
| 21 | 29 | | } |
| | 30 | |
|
| | 31 | | public void Initialize(IChatController chatController, |
| | 32 | | ILastReadMessagesService lastReadMessagesService) |
| | 33 | | { |
| 0 | 34 | | this.chatController = chatController; |
| 0 | 35 | | this.lastReadMessagesService = lastReadMessagesService; |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | public void Configure(BaseComponentModel newModel) |
| | 39 | | { |
| 15 | 40 | | model = (PublicChannelEntryModel) newModel; |
| 15 | 41 | | RefreshControl(); |
| 15 | 42 | | } |
| | 43 | |
|
| | 44 | | public override void RefreshControl() |
| | 45 | | { |
| 15 | 46 | | nameLabel.text = $"#{model.name}"; |
| 15 | 47 | | unreadNotifications.Initialize(chatController, model.channelId, lastReadMessagesService); |
| 15 | 48 | | } |
| | 49 | |
|
| | 50 | | [Serializable] |
| | 51 | | public class PublicChannelEntryModel : BaseComponentModel |
| | 52 | | { |
| | 53 | | public string channelId; |
| | 54 | | public string name; |
| | 55 | |
|
| 15 | 56 | | public PublicChannelEntryModel(string channelId, string name) |
| | 57 | | { |
| 15 | 58 | | this.channelId = channelId; |
| 15 | 59 | | this.name = name; |
| 15 | 60 | | } |
| | 61 | | } |
| | 62 | | } |