Exemplo n.º 1
0
        public void Open(string userId, string userName, IFizzLanguageCode lang, FizzServices services, bool tranlation, Action <bool> onDone)
        {
            if (!_isIntialized)
            {
                Initialize();
            }

            if (string.IsNullOrEmpty(userId))
            {
                FizzLogger.E("FizzService can not open client with null of empty userId.");
                return;
            }

            if (string.IsNullOrEmpty(userName))
            {
                FizzLogger.E("FizzService can not open client with null of empty userName.");
                return;
            }

            if (lang == null)
            {
                FizzLogger.E("FizzService can not open client with null language code.");
                return;
            }

            UserId               = userId;
            UserName             = userName;
            Language             = lang;
            IsTranslationEnabled = tranlation;
            Client.Open(userId, lang, services, ex =>
            {
                if (onDone != null)
                {
                    onDone(ex == null);
                }

                if (ex != null)
                {
                    FizzLogger.E("Something went wrong while connecting to FizzClient. " + ex);
                }
                else
                {
                    AddInternalListeners();
                }
            });
        }
Exemplo n.º 2
0
        public void Open(string userId, IFizzLanguageCode locale, FizzServices services, Action <FizzException> callback)
        {
            try
            {
                if (State == FizzClientState.Opened)
                {
                    FizzUtils.DoCallback(null, callback);
                    return;
                }

                FizzSessionRepository sessionRepo = new FizzSessionRepository(userId, locale.Code, _sessionClient);
                _authClient.Open(sessionRepo, ex =>
                {
                    if (ex == null)
                    {
                        if (services.HasFlag(FizzServices.Chat))
                        {
                            _chat.Open(userId, _authClient, sessionRepo);
                        }
                        if (services.HasFlag(FizzServices.Analytics))
                        {
                            _ingestionClient.Open(userId, sessionRepo.Session._serverTS, _authClient);
                        }
                        if (services.HasFlag(FizzServices.Moderation))
                        {
                            _moderationClient.Open(_authClient);
                        }

                        State = FizzClientState.Opened;
                        FizzUtils.DoCallback(null, callback);
                    }
                    else
                    {
                        FizzUtils.DoCallback(ex, callback);
                    }
                });
            }
            catch (FizzException ex)
            {
                FizzUtils.DoCallback(ex, callback);
            }
        }
Exemplo n.º 3
0
        public void ReportMessage(string channelId, string message, string messageId, IFizzLanguageCode lang, string userId, string offense, string description, Action <string, FizzException> callback)
        {
            IfOpened(() =>
            {
                if (string.IsNullOrEmpty(channelId))
                {
                    FizzUtils.DoCallback <string> (null, ERROR_INVALID_CHANNEL_ID, callback);
                    return;
                }
                if (string.IsNullOrEmpty(message))
                {
                    FizzUtils.DoCallback <string> (null, ERROR_INVALID_MESSAGE, callback);
                    return;
                }
                if (string.IsNullOrEmpty(messageId))
                {
                    FizzUtils.DoCallback <string> (null, ERROR_INVALID_MESSAGE_ID, callback);
                    return;
                }
                if (lang == null)
                {
                    FizzUtils.DoCallback <string> (null, ERROR_INVALID_LANGUAGE, callback);
                    return;
                }
                if (string.IsNullOrEmpty(userId))
                {
                    FizzUtils.DoCallback <string> (null, ERROR_INVALID_USER_ID, callback);
                    return;
                }
                if (string.IsNullOrEmpty(offense))
                {
                    FizzUtils.DoCallback <string> (null, ERROR_INVALID_OFFENCE, callback);
                    return;
                }

                try
                {
                    JSONClass json     = new JSONClass();
                    json["channel_id"] = channelId;
                    json["message"]    = message;
                    json["message_id"] = messageId;
                    json["language"]   = lang.Code;
                    json["user_id"]    = userId;
                    json["offense"]    = offense.ToString();
                    json.Add("time", new JSONData(FizzUtils.Now() / 1000));

                    if (!string.IsNullOrEmpty(description))
                    {
                        json["description"] = description;
                    }

                    _restClient.Post(FizzConfig.API_BASE_URL, FizzConfig.API_PATH_REPORTS, json.ToString(), (response, ex) =>
                    {
                        if (ex != null)
                        {
                            FizzUtils.DoCallback <string> (null, ex, callback);
                        }
                        else
                        {
                            try
                            {
                                JSONNode responseJson    = JSONNode.Parse(response);
                                string reportedMessageId = responseJson["id"];

                                FizzUtils.DoCallback <string> (reportedMessageId, null, callback);
                            }
                            catch
                            {
                                FizzUtils.DoCallback <string> (null, ERROR_INVALID_RESPONSE_FORMAT, callback);
                            }
                        }
                    });
                }
                catch (FizzException ex)
                {
                    FizzUtils.DoCallback <string> (null, ex, callback);
                }
            });
        }