internal static Message FromJObject(JObject jObj) { var result = new Message(); result._data = JsonHelpers.FromJObject(result, jObj); var userObj = result._data.GetData <JObject>("user"); if (userObj != null) { result.User = User.FromJObject(userObj); result._data.RemoveData("user"); } var attachs = result._data.GetData <JArray>("attachments"); if (attachs != null) { var attachments = new List <Attachment>(); foreach (var att in attachs) { var attachObj = att as JObject; attachments.Add(Attachment.FromJObject(attachObj)); } result.Attachments = attachments; result._data.RemoveData("attachments"); } var latestReacts = result._data.GetData <JArray>("latest_reactions"); if (latestReacts != null) { var latestReactions = new List <Reaction>(); foreach (var reaction in latestReacts) { var reactionObj = reaction as JObject; latestReactions.Add(Reaction.FromJObject(reactionObj)); } result.LatestReactions = latestReactions; result._data.RemoveData("latest_reactions"); } var ownReacts = result._data.GetData <JArray>("own_reactions"); if (ownReacts != null) { var ownReactions = new List <Reaction>(); foreach (var reaction in ownReacts) { var reactionObj = reaction as JObject; ownReactions.Add(Reaction.FromJObject(reactionObj)); } result.OwnReactions = ownReactions; result._data.RemoveData("own_reactions"); } var mentionedUsrs = result._data.GetData <JArray>("mentioned_users"); if (mentionedUsrs != null) { var mentionedUsers = new List <User>(); foreach (var usr in mentionedUsrs) { var usrObj = usr as JObject; mentionedUsers.Add(User.FromJObject(usrObj)); } result.MentionedUsers = mentionedUsers; result._data.RemoveData("mentioned_users"); } return(result); }
internal static ChannelState FromJObject(JObject jObj) { var result = new ChannelState(); var data = JsonHelpers.FromJObject(result, jObj); var chanObj = data.GetData <JObject>("channel"); if (chanObj != null) { result.Channel = ChannelObjectWithInfo.FromJObject(chanObj); } var msgs = data.GetData <JArray>("messages"); if (msgs != null) { var messages = new List <Message>(); foreach (var msg in msgs) { var msgObj = msg as JObject; messages.Add(Message.FromJObject(msgObj)); } result.Messages = messages; } var usrs = data.GetData <JArray>("watchers"); if (usrs != null) { var users = new List <User>(); foreach (var usr in usrs) { var usrObj = usr as JObject; users.Add(User.FromJObject(usrObj)); } result.Watchers = users; } var reads = data.GetData <JArray>("read"); if (reads != null) { var readsList = new List <Read>(); foreach (var read in reads) { var readObj = read as JObject; readsList.Add(Read.FromJObject(readObj)); } result.Reads = readsList; } var mbrs = data.GetData <JArray>("members"); if (mbrs != null) { var members = new List <ChannelMember>(); foreach (var mbr in mbrs) { var memberObj = mbr as JObject; members.Add(ChannelMember.FromJObject(memberObj)); } result.Members = members; } return(result); }