public async Task <UpdateChannelResponse> Update(GenericData customData, MessageInput msg = null, bool skipPush = false) { var payload = new JObject(); payload.Add(new JProperty("data", customData.ToJObject())); if (msg != null) { payload.Add(new JProperty("message", msg.ToJObject())); if (skipPush) { payload.Add("skip_push", true); } } var request = this._client.BuildAppRequest(this.Endpoint, HttpMethod.POST); request.SetJsonBody(payload.ToString()); var response = await this._client.MakeRequest(request); if (response.StatusCode == System.Net.HttpStatusCode.Created) { this._data = customData; var respObj = JObject.Parse(response.Content); return(UpdateChannelResponse.FromJObject(respObj)); } throw StreamChatException.FromResponse(response); }
internal Channel(Client client, string type, string id = "", GenericData data = null) { _client = client; if (string.IsNullOrWhiteSpace(type)) { throw new ArgumentNullException("channel type", "Channel type can't be empty"); } this.Type = type; this.ID = id; if (data != null) { this._data = data; } }
internal static GenericData FromJObject <T>(T obj, JObject json) { #if NETSTANDARD1_6 PropertyInfo[] properties = typeof(T).GetTypeInfo().GetProperties(); #else PropertyInfo[] properties = typeof(T).GetProperties(); #endif Dictionary <string, PropertyInfo> objProps = new Dictionary <string, PropertyInfo>(); GenericData extra = new GenericData(); foreach (var prop in properties) { bool ignore = false; string propName = prop.Name; var attrs = prop.GetCustomAttributes(true); foreach (var attr in attrs) { JsonIgnoreAttribute ignoreAttr = attr as JsonIgnoreAttribute; if (ignoreAttr != null) { ignore = true; break; } JsonPropertyAttribute result = attr as JsonPropertyAttribute; if (result != null) { propName = result.PropertyName; break; } } if (!ignore && !objProps.ContainsKey(propName)) { objProps.Add(propName, prop); } } var jsonProps = json.Properties(); foreach (var jsonProp in jsonProps) { PropertyInfo objProp; if (objProps.TryGetValue(jsonProp.Name, out objProp)) { objProp.SetValue(obj, jsonProp.Value.ToObject(objProp.PropertyType)); } else { extra.SetData(jsonProp.Name, jsonProp.Value); } } return(extra); }
public IChannel Channel(string channelType, string channelID = "", GenericData data = null) { return(new Channel(this, channelType, channelID, data)); }