private void HandleSendData(Dictionary <string, string> data) { if (data == null) { return; } if (ChannelsView.CurrentSelectedChannel == null) { return; } FizzChannel channel = ChannelsView.CurrentSelectedChannel; try { long now = FizzUtils.Now(); data.Add(FizzMessageCellModel.KEY_CLIENT_ID, now + ""); FizzMessageCellModel model = new FizzMessageCellModel( now, FizzService.Instance.UserId, FizzService.Instance.UserName, channel.Id, string.Empty, data, null, now) { DeliveryState = FizzChatCellDeliveryState.Pending }; MessagesView.AddMessage(model); FizzService.Instance.Client.Chat.PublishMessage( channel.Id, FizzService.Instance.UserName, string.Empty, data, FizzService.Instance.IsTranslationEnabled, channel.Meta.FilterContent, channel.Meta.PersistMessages, exception => { if (exception == null) { model.DeliveryState = FizzChatCellDeliveryState.Sent; MessagesView.AddMessage(model); string dataStr = Utils.GetDictionaryToString(data, FizzMessageCellModel.KEY_CLIENT_ID); FizzService.Instance.Client.Ingestion.TextMessageSent(channel.Id, dataStr, FizzService.Instance.UserName); } }); } catch { FizzLogger.E("Something went wrong while calling PublishMessage of FizzService."); } }
public bool SetChannel(string channelId) { if (!_initialized) { Initialize(); } FizzChannel channel = GetChannelById(channelId); if (channel == null) { return(false); } if (_channelsLookup.ContainsKey(channel.Id)) { HandleChannelSelected(channel); return(true); } else { FizzLogger.W("FizzChatView: Unable to set channel, add channel first"); return(false); } }
public void SetData(FizzChannel channel, Action <FizzChannel> onClick) { _channel = channel; _onClickAction = onClick; NameLabel.text = channel.Meta.Name; }
private bool RemoveChannelInternal(string channelId) { bool _removed = false; if (!string.IsNullOrEmpty(channelId) && _channelsLookup.ContainsKey(channelId)) { if (CurrentSelectedChannel != null && CurrentSelectedChannel.Id.Equals(channelId)) { CurrentSelectedChannel = null; } FizzChannel channel = _channelsLookup[channelId].GetChannel(); if (channel != null && !string.IsNullOrEmpty(channel.Meta.Group) && _groupsLookup.ContainsKey(channel.Meta.Group)) { _groupsLookup[channel.Meta.Group].ChannelCount--; } Destroy(_channelsLookup[channelId].gameObject); _channelsLookup.Remove(channelId); _removed = true; } if (_removed) { RemoveChannelGroup(channelId); } return(_removed); }
public void AddChannel(string channelId, bool select = false) { if (!_initialized) { Initialize(); } FizzChannel channel = GetChannelById(channelId); if (channel == null) { if (!_channelWatchList.Contains(channelId)) { _channelWatchList.Add(channelId); } FizzLogger.W("Channel not found, please add channel [" + channelId + "] to FizzService first."); return; } if (!_channelsLookup.ContainsKey(channel.Id)) { AddChannelInternal(channel); } if (_channelsLookup.ContainsKey(channel.Id) && select) { HandleChannelSelected(channel); } }
private bool AddChannelInternal(FizzChannel _item) { if (_item == null) { return(false); } bool _added = false; if (!_channelsLookup.ContainsKey(_item.Id)) { FizzChannelView _button = Instantiate(ChannelPrefab); _button.gameObject.SetActive(true); _button.transform.SetParent(GetChannelGroup(_item).transform, false); _button.transform.SetAsLastSibling(); _button.transform.localScale = Vector3.one; _button.SetData(_item, HandleChannelSelected); _channelsLookup.Add(_item.Id, _button); _button.gameObject.name = _item.Name; if (!string.IsNullOrEmpty(_item.Meta.Group) && _groupsLookup.ContainsKey(_item.Meta.Group)) { _groupsLookup[_item.Meta.Group].ChannelCount++; } _added = true; } return(_added); }
private void HandleChannelSelected(FizzChannel data) { if (CurrentSelectedChannel != null) { if (CurrentSelectedChannel.Id.Equals(data.Id)) { if (OnChannelSelected != null) { OnChannelSelected.Invoke(data); } return; } FizzChannelView currentButton = _channelsLookup[CurrentSelectedChannel.Id]; currentButton.SetSelected(false); } CurrentSelectedChannel = data; if (OnChannelSelected != null) { OnChannelSelected.Invoke(data); } FizzChannelView barButton = _channelsLookup[data.Id]; barButton.SetSelected(true); }
public void Reset() { if (!_initialized) { Initialize(); } CurrentSelectedChannel = null; foreach (KeyValuePair <string, FizzChannelView> pair in _channelsLookup) { FizzChannelView button = pair.Value; if (button != null) { Destroy(button.gameObject); } } foreach (KeyValuePair <string, FizzChannelGroupView> pair in _groupsLookup) { FizzChannelGroupView group = pair.Value; if (group != null) { Destroy(group.gameObject); } } _channelsLookup.Clear(); _groupsLookup.Clear(); _channelWatchList.Clear(); }
private void OnChannelHistoryUpdated(string channelId) { if (!string.IsNullOrEmpty(channelId)) { FizzChannel channel = FizzService.Instance.GetChannelById(channelId); buttonBar.AddButton(new UIButtonBarItemModel { text = channel.Name, data = channel.Id }); } }
private void TabBarButtonHandler(UIButtonBarItemModel selected) { if (selected != null && !string.IsNullOrEmpty(selected.data)) { FizzChannel channel = FizzService.Instance.GetChannelById(selected.data); if (selectedModelItem != null && !selectedModelItem.data.Equals(selected.data)) { chatView.Reset(); } selectedModelItem = selected; chatView.EnableFetchHistory = true; chatView.SetData(channel); } }
/// <summary> /// Sets the data. /// </summary> /// <param name="room">Room.</param> public void SetData(FizzChannel room) { if (!_isInitialized) { Initialize(); } _data = room; _isAppTranslationEnabled = FizzService.Instance.IsTranslationEnabled; _userId = FizzService.Instance.UserId; //StartCoroutine (LoadChatAsync (true)); //CancelInvoke ("RefreshScrollContent"); //InvokeRepeating ("RefreshScrollContent", 0.5f, 0.1f); LoadChatAsync(true); }
private RectTransform GetChannelGroup(FizzChannel channel) { string channelGroup = (string.IsNullOrEmpty(channel.Meta.Group) ? DEFAULT_NO_GROUP : channel.Meta.Group); RectTransform parentRect = Container; if (_groupsLookup.ContainsKey(channelGroup)) { parentRect = _groupsLookup[channelGroup].RectTransform; } else { parentRect = AddChannelGroup(channel, channelGroup); } return(parentRect); }
private void HandleChannelSelected(FizzChannel channel) { if (channel != null) { MessagesView.SetChannel(channel.Id); HeaderView.SetTitleText(channel.Name); if (_isChannelListVisible) { HandleChannelsButton(); } } else { MessagesView.Reset(); } }
private RectTransform AddChannelGroup(FizzChannel channel, string channelGroup) { RectTransform groupRect = null; if (!_groupsLookup.ContainsKey(channelGroup)) { FizzChannelGroupView channelGroupView = Instantiate(ChannelGroupPrefab); channelGroupView.gameObject.SetActive(true); channelGroupView.transform.SetParent(Container.transform, false); channelGroupView.transform.localScale = Vector3.one; channelGroupView.SetData(channel.Meta.Group); _groupsLookup.Add(channelGroup, channelGroupView); groupRect = channelGroupView.RectTransform; channelGroupView.gameObject.name = channelGroup; } return(groupRect); }