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