/// <summary> /// This method is used to retrieve the public settings, such as Site Name. /// It accepts a date as the first and only parameter which causes the results to be an object that /// contains the updated and removed settings after the provided time. /// </summary> /// <returns>The time after which settings should be returned.</returns> /// <param name="since">Since.</param> public async Task <CollectionDiff <KeyValuePair <string, object> > > GetPublicSettingsSince(DateTime since) { var res = await _meteor.CallWithResult("public-settings/get", new object[] { new Dictionary <string, object>() { { "$date", TypeUtils.DateTimeToTimestamp(since) } } }); CollectionDiff <KeyValuePair <string, object> > output = new CollectionDiff <KeyValuePair <string, object> >(); if (res == null) { return(output); } var result = res["result"]; if (result == null) { return(output); } var updates = result["update"] != null ? (result as JObject)["update"] as JArray : null; var additions = result["add"] != null ? (result as JObject)["add"] as JArray : null; var removes = result["remove"] != null ? (result as JObject)["remove"] as JArray : null; if (additions != null) { foreach (var channelTok in additions) { output.Added.Add(TypeUtils.ParseKeyValuePair(channelTok as JObject)); } } if (updates != null) { foreach (var channelTok in updates) { output.Updated.Add(TypeUtils.ParseKeyValuePair(channelTok as JObject)); } } if (removes != null) { foreach (var channelTok in removes) { output.Removed.Add(TypeUtils.ParseKeyValuePair(channelTok as JObject)); } } return(output); }
public static Room Parse(IMeteor meteor, JObject m) { var room = new Room(meteor); if (m["_id"] != null) { room.Id = m["_id"].Value <string>(); } if (m["name"] != null) { room.Name = m["name"].Value <string>(); } if (m["t"] != null) { switch (m["t"].ToString()) { case "d": room.Type = RoomType.DirectMessage; break; case "p": room.Type = RoomType.PrivateGroup; break; case "c": room.Type = RoomType.PublicChannel; break; } } if (m["u"] != null) { room.Owner = User.Parse(m["u"] as JObject); } if (m["topic"] != null) { room.Topic = m["topic"].Value <string>(); } if (m["default"] != null) { room.Default = m["default"].Value <bool>(); } if (m["ro"] != null) { room.ReadOnly = m["ro"].Value <bool>(); } if (m["description"] != null) { room.Description = m["description"].Value <string>(); } room.MutedUsers = new List <string>(); if (m["muted"] != null) { foreach (var user in m["muted"] as JArray) { room.MutedUsers.Add(user.Value <string>()); } } if (m["_deletedAt"] != null) { room.DeletedAt = TypeUtils.ParseDateTime(m["_deletedAt"] as JObject); } return(room); }
public static Message Parse(IMeteor meteor, JObject m) { Message message = new Message(meteor); if (m["_id"] != null) { message.Id = (m["_id"] as JValue).Value <string>(); } if (m["rid"] != null) { message.RoomId = (m["rid"] as JValue).Value <string>(); } if (m["t"] != null && m["t"] is JValue) { switch ((m["t"] as JValue).Value <string>()) { case "room_changed_topic": message.Type = MessageType.ROOM_CHANGED_TOPIC; break; case "uj": message.Type = MessageType.USER_JOINED; break; case "ul": message.Type = MessageType.USER_LEFT; break; case "au": message.Type = MessageType.ADDED_USER; break; case "message_pinned": message.Type = MessageType.MESSAGE_PINNED; break; default: message.Type = MessageType.MESSAGE; break; } } else { message.Type = MessageType.MESSAGE; } if (m["ts"] != null) { message.Created = TypeUtils.ParseDateTime(m["ts"] as JObject); } if (m["msg"] != null) { message.Text = (m["msg"] as JValue).Value <string>(); } if (m["_updatedAt"] != null) { message.UpdatedAt = TypeUtils.ParseDateTime(m["_updatedAt"] as JObject); } if (m["editedAt"] != null) { message.EditedAt = TypeUtils.ParseDateTime(m["editedAt"] as JObject); } if (m["editedBy"] != null) { message.EditedBy = User.Parse(m["editedBy"] as JObject); } message.Urls = new List <AttachedUrl>(); if (m["urls"] != null) { foreach (var url in m["urls"] as JArray) { message.Urls.Add(AttachedUrl.Parse(url as JObject)); } } message.Attachments = new List <Attachment>(); if (m["attachments"] != null) { foreach (var attachment in m["attachments"]) { message.Attachments.Add(Attachment.Parse(attachment as JObject)); } } if (m["alias"] != null) { message.Alias = m["alias"].Value <string>(); } if (m["avatar"] != null) { message.Avatar = m["avatar"].Value <string>(); } if (m["groupable"] != null) { message.Groupable = m["groupable"].Value <bool>(); } if (m["parseUrls"] != null) { message.ParseUrls = m["parseUrls"].Value <bool>(); } if (m["u"] != null) { message.User = User.Parse(m["u"] as JObject); } if (m["bot"] != null) { message.Bot = Bot.Parse(m["bot"] as JObject); } message.Reactions = new Dictionary <string, List <string> >(); if (m["reactions"] != null && m["reactions"] is JObject) { foreach (var reaction in (m["reactions"] as JObject)) { message.Reactions.Add(reaction.Key, new List <string>()); if (reaction.Value["usernames"] != null) { foreach (var user in reaction.Value["usernames"]) { message.Reactions[reaction.Key].Add(user.Value <string>()); } } } } return(message); }