| | 1 | | namespace DCL.Chat.HUD |
| | 2 | | { |
| | 3 | | public class ChannelLeaveErrorWindowController |
| | 4 | | { |
| | 5 | | private readonly IChannelLeaveErrorWindowView view; |
| | 6 | | private readonly IChatController chatController; |
| | 7 | | private readonly DataStore dataStore; |
| | 8 | | private string currentChannelId; |
| | 9 | |
|
| 3 | 10 | | public ChannelLeaveErrorWindowController(IChannelLeaveErrorWindowView view, |
| | 11 | | IChatController chatController, |
| | 12 | | DataStore dataStore) |
| | 13 | | { |
| 3 | 14 | | this.view = view; |
| 3 | 15 | | this.chatController = chatController; |
| 3 | 16 | | view.Hide(); |
| 3 | 17 | | view.OnClose += Close; |
| 3 | 18 | | view.OnRetry += Retry; |
| 3 | 19 | | this.dataStore = dataStore; |
| 3 | 20 | | dataStore.channels.leaveChannelError.OnChange += Show; |
| 3 | 21 | | } |
| | 22 | |
|
| | 23 | | public void Dispose() |
| | 24 | | { |
| 0 | 25 | | dataStore.channels.leaveChannelError.OnChange -= Show; |
| | 26 | |
|
| 0 | 27 | | if (view != null) |
| | 28 | | { |
| 0 | 29 | | view.OnClose -= Close; |
| 0 | 30 | | view.OnRetry -= Retry; |
| 0 | 31 | | view.Dispose(); |
| | 32 | | } |
| 0 | 33 | | } |
| | 34 | |
|
| | 35 | | private void Show(string currentChannelId, string previousChannelId) |
| | 36 | | { |
| 5 | 37 | | if (string.IsNullOrEmpty(currentChannelId)) return; |
| 5 | 38 | | this.currentChannelId = currentChannelId; |
| 5 | 39 | | var channel = chatController.GetAllocatedChannel(currentChannelId); |
| 5 | 40 | | view.Show(channel?.Name ?? currentChannelId); |
| 5 | 41 | | } |
| | 42 | |
|
| 2 | 43 | | private void Close() => view.Hide(); |
| | 44 | |
|
| | 45 | | private void Retry() |
| | 46 | | { |
| 1 | 47 | | chatController.LeaveChannel(currentChannelId); |
| 1 | 48 | | Close(); |
| 1 | 49 | | } |
| | 50 | | } |
| | 51 | | } |