public void GetUser(string userId, Action <IFizzUser, FizzException> callback) { IfOpened(() => { string path = string.Format(FizzConfig.API_PATH_USER, userId); _client.Get(FizzConfig.API_BASE_URL, path, (response, ex) => { if (ex != null) { FizzUtils.DoCallback <IFizzUser>(null, ex, callback); } else { try { JSONNode userResponse = JSONNode.Parse(response); FizzJsonUser user = new FizzJsonUser(userId, userResponse); FizzUtils.DoCallback <IFizzUser>(user, null, callback); } catch { FizzUtils.DoCallback <IFizzUser>(null, ERROR_INVALID_RESPONSE_FORMAT, callback); } } }); }); }
public void Unsubscribe(Action <FizzException> cb) { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before unsubscribing user."); return; } try { Client.Chat.Users.Unsubscribe(Id, ex => { if (ex == null) { IsSubscribed = false; } FizzUtils.DoCallback(ex, cb); }); } catch (Exception e) { FizzLogger.E(e); } }
public void UpdateGroup( string userId, string groupId, FizzGroupMemberState?state, long?lastReadMessageId, Action <FizzException> callback ) { IfOpened(() => { string path = string.Format(FizzConfig.API_PATH_USER_GROUP, userId, groupId); JSONClass body = new JSONClass(); if (state != null) { body["state"] = Value(state.Value); } if (lastReadMessageId != null) { body["last_read_message_id"].AsDouble = lastReadMessageId.Value; } _client.Post(FizzConfig.API_BASE_URL, path, body.ToString(), (response, ex) => { FizzUtils.DoCallback(ex, callback); }); }); }
public void UnsubscribeUserNotifications(Action <FizzException> cb) { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before unsubscribing user."); return; } try { Client.Chat.UserNotifications.Unsubscribe(ex => { if (ex == null) { if (OnUserNotificationsUnsubscribed != null) { OnUserNotificationsUnsubscribed.Invoke(); } } FizzUtils.DoCallback(ex, cb); }); } catch (Exception e) { FizzLogger.E(e); } }
public void UpdateMessage( string channelId, long messageId, string nick, string body, Dictionary <string, string> data, bool translate, bool filter, bool persist, Action <FizzException> callback) { IfOpened(() => { if (string.IsNullOrEmpty(channelId)) { FizzUtils.DoCallback(ERROR_INVALID_CHANNEL, callback); return; } if (messageId < 1) { FizzUtils.DoCallback(ERROR_INVALID_MESSAGE_ID, callback); return; } try { string path = string.Format(FizzConfig.API_PATH_MESSAGE_ACTION, channelId, messageId); JSONClass json = new JSONClass(); json[FizzJsonChannelMessage.KEY_NICK] = nick; json[FizzJsonChannelMessage.KEY_BODY] = body; json[FizzJsonChannelMessage.KEY_PERSIST].AsBool = persist; json[FizzJsonChannelMessage.KEY_FILTER].AsBool = filter; json[FizzJsonChannelMessage.KEY_TRANSLATE].AsBool = translate; string dataStr = string.Empty; if (data != null) { JSONClass dataJson = new JSONClass(); foreach (KeyValuePair <string, string> pair in data) { dataJson.Add(pair.Key, new JSONData(pair.Value)); } dataStr = dataJson.ToString(); } json[FizzJsonChannelMessage.KEY_DATA] = dataStr; _restClient.Post(FizzConfig.API_BASE_URL, path, json.ToString(), (response, ex) => { FizzUtils.DoCallback(ex, callback); }); } catch (FizzException ex) { FizzUtils.DoCallback(ex, callback); } }); }
public void DeleteMessage(string channelId, long messageId, Action <FizzException> callback) { IfOpened(() => { if (string.IsNullOrEmpty(channelId)) { FizzUtils.DoCallback(ERROR_INVALID_CHANNEL, callback); return; } if (messageId < 1) { FizzUtils.DoCallback(ERROR_INVALID_MESSAGE_ID, callback); return; } try { string path = string.Format(FizzConfig.API_PATH_MESSAGE_ACTION, channelId, messageId); _restClient.Delete(FizzConfig.API_BASE_URL, path, string.Empty, (response, ex) => { FizzUtils.DoCallback(ex, callback); }); } catch (FizzException ex) { FizzUtils.DoCallback(ex, callback); } }); }
public override void PublishMessage(string nick, string body, string locale, Dictionary <string, string> data, bool translate, Action <FizzException> callback) { if (FizzService.Instance.GroupRepository.GroupInvites.ContainsKey(GroupId)) { // Can't send messages in group with pending membership return; } FizzService.Instance.Client.Chat.Groups.PublishMessage( GroupId, nick, body, locale, data, translate, Meta.FilterContent, Meta.PersistMessages, ex => { FizzUtils.DoCallback(ex, callback); }); }
public void Unmute(string channel, string userId, Action <FizzException> callback) { IfOpened(() => { if (string.IsNullOrEmpty(channel)) { FizzUtils.DoCallback(ERROR_INVALID_CHANNEL, callback); return; } if (string.IsNullOrEmpty(userId)) { FizzUtils.DoCallback(ERROR_INVALID_USER, callback); return; } try { string path = string.Format(FizzConfig.API_PATH_MUTE, channel); JSONClass json = new JSONClass(); json["user_id"] = userId; _restClient.Delete(FizzConfig.API_BASE_URL, path, json.ToString(), (response, ex) => { FizzUtils.DoCallback(ex, callback); }); } catch (FizzException ex) { FizzUtils.DoCallback(ex, callback); } }); }
public void Next(Action <IList <IFizzUserGroup>, FizzException> callback) { string path = string.Format(FizzConfig.API_PATH_USER_GROUPS, _userId) + "?page_size=100"; if (_next != null && _next != string.Empty) { path += "&page=" + _next; } _restClient.Get(FizzConfig.API_BASE_URL, path, (response, ex) => { if (ex != null) { FizzUtils.DoCallback <IList <IFizzUserGroup> >(null, ex, callback); } else { try { FizzUtils.DoCallback <IList <IFizzUserGroup> >(ParseResponse(response), null, callback); } catch { FizzUtils.DoCallback <IList <IFizzUserGroup> >(null, FizzRestClient.ERROR_INVALID_RESPONSE_FORMAT, callback); } } }); }
private void OnConnDisconnected(object sender, FizzMqttDisconnectedArgs args) { FizzLogger.D("MQTT - OnDisconnected: " + args.ClientWasConnected.ToString()); if (OnDisconnected != null) { if (args.Exception == null) { OnDisconnected.Invoke(null); } else { if (args.Exception.GetType() == typeof(FizzMqttAuthException)) { OnDisconnected.Invoke(ERROR_AUTH_FAILED); if (_sessionRepo != null) { _sessionRepo.FetchToken(null); } } else { OnDisconnected.Invoke(ERROR_CONNECTION_FAILED); } } } if (_closeCallback != null) { FizzUtils.DoCallback(_closeCallback); } }
public void Unsubscribe(Action <FizzException> callback) { IfOpened(() => { string path = FizzConfig.API_PATH_USER_NOTIFICATIONS; _client.Delete(FizzConfig.API_BASE_URL, path, string.Empty, (response, ex) => { FizzUtils.DoCallback(ex, callback); }); }); }
private void IfOpened(Action callback) { if (_restClient != null) { FizzUtils.DoCallback(callback); } else { FizzLogger.W("Client should have been opened."); } }
private void IfClosed(Action callback) { if (_restClient == null) { FizzUtils.DoCallback(callback); } else { FizzLogger.W("Moderation client should be closed before opening."); } }
private void IfClosed(Action callback) { if (string.IsNullOrEmpty(_userId)) { FizzUtils.DoCallback(callback); } else { FizzLogger.W("Chat client should be closed before opening."); } }
public void Unsubscribe(string userId, Action <FizzException> callback) { IfOpened(() => { string path = string.Format(FizzConfig.API_PATH_USER_SUBCRIBERS, userId); _client.Delete(FizzConfig.API_BASE_URL, path, string.Empty, (response, ex) => { FizzUtils.DoCallback(ex, callback); }); }); }
private void IfOpened(Action callback) { if (_restClient != null) { FizzUtils.DoCallback(callback); } else { FizzLogger.W("Moderation client should be opened before usage."); } }
private void IfClosed(Action callback) { if (_client == null) { FizzUtils.DoCallback(callback); } else { FizzLogger.W("Client should have been closed."); } }
public void RemoveGroup(string userId, string groupId, Action <FizzException> callback) { IfOpened(() => { string path = string.Format(FizzConfig.API_PATH_USER_GROUP, userId, groupId); _client.Delete(FizzConfig.API_BASE_URL, path, string.Empty, (response, ex) => { FizzUtils.DoCallback(ex, callback); }); }); }
public void RemoveGroup(string groupId, Action <FizzException> cb) { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before removing group."); return; } Client.Chat.Users.RemoveGroup(UserId, groupId, ex => { FizzUtils.DoCallback(ex, cb); }); }
public void QueryLatest(string channel, int count, long beforeId, Action <IList <FizzChannelMessage>, FizzException> callback) { IfOpened(() => { if (string.IsNullOrEmpty(channel)) { FizzUtils.DoCallback <IList <FizzChannelMessage> > (null, ERROR_INVALID_CHANNEL, callback); return; } if (count < 0) { FizzUtils.DoCallback <IList <FizzChannelMessage> > (null, ERROR_INVALID_MESSAGE_QUERY_COUNT, callback); return; } if (count == 0) { FizzUtils.DoCallback <IList <FizzChannelMessage> > (new List <FizzChannelMessage> (), null, callback); return; } string path = string.Format(FizzConfig.API_PATH_MESSAGES, channel) + "?count=" + count; if (beforeId > 0) { path += "&before_id=" + beforeId; } _restClient.Get(FizzConfig.API_BASE_URL, path, (response, ex) => { if (ex != null) { FizzUtils.DoCallback <IList <FizzChannelMessage> > (null, ex, callback); } else { try { JSONArray messagesArr = JSONNode.Parse(response).AsArray; IList <FizzChannelMessage> messages = new List <FizzChannelMessage> (); foreach (JSONNode message in messagesArr.Childs) { messages.Add(new FizzJsonChannelMessage(message)); } FizzUtils.DoCallback <IList <FizzChannelMessage> > (messages, null, callback); } catch { FizzUtils.DoCallback <IList <FizzChannelMessage> > (null, ERROR_INVALID_RESPONSE_FORMAT, callback); } } }); }); }
public void Subscribe(Action <FizzException> cb) { FizzService.Instance.Client.Chat.Subscribe(Id, ex => { if (ex == null) { if (FizzService.Instance.OnChannelSubscribed != null) { FizzService.Instance.OnChannelSubscribed.Invoke(Id); } } FizzUtils.DoCallback(ex, cb); }); }
public void Close(Action <FizzException> callback) { try { if (State == FizzClientState.Closed) { return; } Close(() => { FizzUtils.DoCallback(null, callback); }); } catch (FizzException ex) { FizzUtils.DoCallback(ex, callback); } }
public void Flush() { if (_flushInProgress) { FizzUtils.DoCallback(_onLogEmpty); return; } _flushInProgress = true; _eventLog.Read(128, items => { if (items.Count <= 0) { _flushInProgress = false; FizzUtils.DoCallback(_onLogEmpty); return; } PostEvents(items, (response, ex) => { bool rollLog = true; if (ex != null) { if (ex.Code == FizzError.ERROR_REQUEST_FAILED) { FizzLogger.W("Failed to submit events to service"); rollLog = false; } else if (ex.Code == FizzError.ERROR_INVALID_REQUEST) { FizzLogger.E("Submission of some events failed: " + ex.Message); } } if (rollLog) { _eventLog.RollTo(items[items.Count - 1]); } FizzUtils.DoCallback(_onLogEmpty); _flushInProgress = false; }); }); }
public void FetchGroup(string groupId, Action <IFizzGroup, FizzException> callback) { IfOpened(() => { string path = string.Format(FizzConfig.API_PATH_GROUP, groupId); _restClient.Get(FizzConfig.API_BASE_URL, path, (response, ex) => { if (ex != null) { FizzUtils.DoCallback <IFizzGroup> (null, ex, callback); } else { FizzUtils.DoCallback <IFizzGroup>(new FizzJsonGroup(response), null, callback); } }); }); }
public void PublishMessage( string groupId, string nick, string body, string locale, Dictionary <string, string> data, bool translate, bool filter, bool persist, Action <FizzException> callback) { IfOpened(() => { string path = string.Format(FizzConfig.API_PATH_GROUP_MESSAGES, groupId); JSONClass json = new JSONClass(); json[FizzJsonChannelMessage.KEY_NICK] = nick; json[FizzJsonChannelMessage.KEY_BODY] = body; json[FizzJsonChannelMessage.KEY_PERSIST].AsBool = persist; json[FizzJsonChannelMessage.KEY_FILTER].AsBool = filter; json[FizzJsonChannelMessage.KEY_TRANSLATE].AsBool = translate; string dataStr = string.Empty; if (data != null) { JSONClass dataJson = new JSONClass(); foreach (KeyValuePair <string, string> pair in data) { dataJson.Add(pair.Key, new JSONData(pair.Value)); } dataStr = dataJson.ToString(); } json[FizzJsonChannelMessage.KEY_DATA] = dataStr; if (!string.IsNullOrEmpty(locale)) { json[FizzJsonChannelMessage.KEY_LOCALE] = locale; } _restClient.Post(FizzConfig.API_BASE_URL, path, json.ToString(), (response, ex) => { FizzUtils.DoCallback(ex, callback); }); }); }
public void UpdateGroup(string groupId, Action <FizzException> cb) { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before joining group."); return; } Client.Chat.Users.UpdateGroup(UserId, groupId, null, null, ex => { if (ex == null) { GroupInvites.Remove(groupId); groupLookup[groupId].Channel.SubscribeAndQueryLatest(); } FizzUtils.DoCallback(ex, cb); }); }
public void Subscribe(Action <FizzException> cb) { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before subscribing user."); return; } Client.Chat.Users.Subscribe(Id, ex => { if (ex == null) { IsSubscribed = true; } FizzUtils.DoCallback(ex, cb); }); }
public void Unsubscribe(string channel, Action <FizzException> callback) { IfOpened(() => { if (channel == null || string.IsNullOrEmpty(channel)) { FizzUtils.DoCallback(ERROR_INVALID_CHANNEL, callback); return; } string path = string.Format(FizzConfig.API_PATH_SUBSCRIBERS, channel); _restClient.Delete(FizzConfig.API_BASE_URL, path, "", (resp, ex) => { FizzUtils.DoCallback(ex, callback); }); }); }
private void GetUser(GetUserRequest request) { Client.Chat.Users.GetUser(request.UserId, (userMeta, ex) => { FizzUserModel user = null; if (ex == null) { user = new FizzUserModel(userMeta, Client); Users[user.Id] = user; } FizzUtils.DoCallback(user, ex, request.Callback); requestQueue.Dequeue(); if (requestQueue.Count > 0) { GetUser(requestQueue.Peek()); } }); }
public void Close(Action cb) { _closeCallback = cb; if (_connection == null) { FizzUtils.DoCallback(_closeCallback); _closeCallback = null; return; } lock (synclock) { _sessionRepo.OnSessionUpdate -= OnSessionUpdate; _sessionRepo = null; var conn = _connection; _connection = null; conn.DisconnectAsync(); } }