diff --git a/MatrixDotNetLib/MatrixDotNetCmd/Program.cs b/MatrixDotNetLib/MatrixDotNetCmd/Program.cs index 771294c..ded1c8d 100644 --- a/MatrixDotNetLib/MatrixDotNetCmd/Program.cs +++ b/MatrixDotNetLib/MatrixDotNetCmd/Program.cs @@ -193,3 +193,37 @@ namespace MatrixDotNetCmd } } } + + + + + +//// simplest implementation +//// might not work for UWP +//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c +//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json"); + +//HttpClient client = new HttpClient(); +//client.BaseAddress = new Uri(loginUrl); +//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + +//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result; +//string responseString = responseMessage.Content.ReadAsStringAsync().Result; + +//if(responseString.Contains("errcode")) +//{ +// // deserialize into error object +// MatrixError error = JsonConvert.DeserializeObject(responseString); + +// // convert error object to a string +// string errMsg = error.ErrorCode + ": " + error.ErrorMessage; + +// // throw exception (can be caught and handled gracefully) +// throw new Exception(errMsg); +//} +//else +//{ +// MatrixLoginResponse response = JsonConvert.DeserializeObject(responseString); + +// return response; +//} \ No newline at end of file diff --git a/MatrixDotNetLib/MatrixDotNetLib/MatrixEvent.cs b/MatrixDotNetLib/MatrixDotNetLib/MatrixEvent.cs new file mode 100644 index 0000000..4338527 --- /dev/null +++ b/MatrixDotNetLib/MatrixDotNetLib/MatrixEvent.cs @@ -0,0 +1,55 @@ +using Newtonsoft.Json; +using System; + +namespace MatrixDotNetLib +{ + public class MatrixEvent + { + [JsonProperty("type")] + public string EventType { get; set; } + + public string Sender { get; set; } + + public MatrixEventContent Content { get; set; } + + [JsonProperty("state_key")] + public string StateKey { get; set; } + + [JsonProperty("origin_server_ts")] + public Int64 OriginTs { get; set; } + + public MatrixEventUnsigned Unsigned { get; set; } + } +} + + + +//// simplest implementation +//// might not work for UWP +//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c +//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json"); + +//HttpClient client = new HttpClient(); +//client.BaseAddress = new Uri(loginUrl); +//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + +//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result; +//string responseString = responseMessage.Content.ReadAsStringAsync().Result; + +//if(responseString.Contains("errcode")) +//{ +// // deserialize into error object +// MatrixError error = JsonConvert.DeserializeObject(responseString); + +// // convert error object to a string +// string errMsg = error.ErrorCode + ": " + error.ErrorMessage; + +// // throw exception (can be caught and handled gracefully) +// throw new Exception(errMsg); +//} +//else +//{ +// MatrixLoginResponse response = JsonConvert.DeserializeObject(responseString); + +// return response; +//} \ No newline at end of file diff --git a/MatrixDotNetLib/MatrixDotNetLib/MatrixEventContent.cs b/MatrixDotNetLib/MatrixDotNetLib/MatrixEventContent.cs new file mode 100644 index 0000000..38d0797 --- /dev/null +++ b/MatrixDotNetLib/MatrixDotNetLib/MatrixEventContent.cs @@ -0,0 +1,76 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace MatrixDotNetLib +{ + public class MatrixEventContent + { + + public string Body { get; set; } + + public string Creator { get; set; } + + public string DisplayName { get; set; } + + [JsonProperty("event_id")] + public string EventId { get; set; } + + /// + /// Gets or sets the event content info property - check FileInfo.MimeType for file type + /// + [JsonProperty("info")] + public MatrixImageInfo FileInfo { get; set; } + + [JsonProperty("currently_active")] + public bool IsActive { get; set; } + + [JsonProperty("join_rule")] + public string JoinRule { get; set; } + + [JsonProperty("last_active_ago")] + public int LastActive { get; set; } + + public string Membership { get; set; } + + public string Name { get; set; } + + public string Presence { get; set; } + + [JsonProperty("room_version")] + public string RoomVersion { get; set; } + + public List Users { get; set; } + } +} + + + +//// simplest implementation +//// might not work for UWP +//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c +//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json"); + +//HttpClient client = new HttpClient(); +//client.BaseAddress = new Uri(loginUrl); +//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + +//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result; +//string responseString = responseMessage.Content.ReadAsStringAsync().Result; + +//if(responseString.Contains("errcode")) +//{ +// // deserialize into error object +// MatrixError error = JsonConvert.DeserializeObject(responseString); + +// // convert error object to a string +// string errMsg = error.ErrorCode + ": " + error.ErrorMessage; + +// // throw exception (can be caught and handled gracefully) +// throw new Exception(errMsg); +//} +//else +//{ +// MatrixLoginResponse response = JsonConvert.DeserializeObject(responseString); + +// return response; +//} \ No newline at end of file diff --git a/MatrixDotNetLib/MatrixDotNetLib/MatrixEventPrevContent.cs b/MatrixDotNetLib/MatrixDotNetLib/MatrixEventPrevContent.cs new file mode 100644 index 0000000..659609c --- /dev/null +++ b/MatrixDotNetLib/MatrixDotNetLib/MatrixEventPrevContent.cs @@ -0,0 +1,46 @@ +using Newtonsoft.Json; + +namespace MatrixDotNetLib +{ + public class MatrixEventPrevContent + { + [JsonProperty("is_direct")] + public bool IsDirect { get; set; } + + public string Membership { get; set; } + + public string DisplayName { get; set; } + } +} + + + +//// simplest implementation +//// might not work for UWP +//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c +//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json"); + +//HttpClient client = new HttpClient(); +//client.BaseAddress = new Uri(loginUrl); +//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + +//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result; +//string responseString = responseMessage.Content.ReadAsStringAsync().Result; + +//if(responseString.Contains("errcode")) +//{ +// // deserialize into error object +// MatrixError error = JsonConvert.DeserializeObject(responseString); + +// // convert error object to a string +// string errMsg = error.ErrorCode + ": " + error.ErrorMessage; + +// // throw exception (can be caught and handled gracefully) +// throw new Exception(errMsg); +//} +//else +//{ +// MatrixLoginResponse response = JsonConvert.DeserializeObject(responseString); + +// return response; +//} \ No newline at end of file diff --git a/MatrixDotNetLib/MatrixDotNetLib/MatrixEventUnsigned.cs b/MatrixDotNetLib/MatrixDotNetLib/MatrixEventUnsigned.cs new file mode 100644 index 0000000..0387ed6 --- /dev/null +++ b/MatrixDotNetLib/MatrixDotNetLib/MatrixEventUnsigned.cs @@ -0,0 +1,47 @@ +using Newtonsoft.Json; + +namespace MatrixDotNetLib +{ + public class MatrixEventUnsigned + { + public int Age { get; set; } + + [JsonProperty("replaces_state")] + public string ReplaceState { get; set; } + + [JsonProperty("prev_content")] + public MatrixEventPrevContent PrevContent { get; set; } + } +} + + + +//// simplest implementation +//// might not work for UWP +//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c +//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json"); + +//HttpClient client = new HttpClient(); +//client.BaseAddress = new Uri(loginUrl); +//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + +//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result; +//string responseString = responseMessage.Content.ReadAsStringAsync().Result; + +//if(responseString.Contains("errcode")) +//{ +// // deserialize into error object +// MatrixError error = JsonConvert.DeserializeObject(responseString); + +// // convert error object to a string +// string errMsg = error.ErrorCode + ": " + error.ErrorMessage; + +// // throw exception (can be caught and handled gracefully) +// throw new Exception(errMsg); +//} +//else +//{ +// MatrixLoginResponse response = JsonConvert.DeserializeObject(responseString); + +// return response; +//} \ No newline at end of file diff --git a/MatrixDotNetLib/MatrixDotNetLib/MatrixFileInfo.cs b/MatrixDotNetLib/MatrixDotNetLib/MatrixFileInfo.cs new file mode 100644 index 0000000..4b9146d --- /dev/null +++ b/MatrixDotNetLib/MatrixDotNetLib/MatrixFileInfo.cs @@ -0,0 +1,43 @@ +using System; + +namespace MatrixDotNetLib +{ + public class MatrixFileInfo + { + public Int64 size { get; set; } + + public string MimeType { get; set; } + } +} + + + +//// simplest implementation +//// might not work for UWP +//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c +//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json"); + +//HttpClient client = new HttpClient(); +//client.BaseAddress = new Uri(loginUrl); +//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + +//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result; +//string responseString = responseMessage.Content.ReadAsStringAsync().Result; + +//if(responseString.Contains("errcode")) +//{ +// // deserialize into error object +// MatrixError error = JsonConvert.DeserializeObject(responseString); + +// // convert error object to a string +// string errMsg = error.ErrorCode + ": " + error.ErrorMessage; + +// // throw exception (can be caught and handled gracefully) +// throw new Exception(errMsg); +//} +//else +//{ +// MatrixLoginResponse response = JsonConvert.DeserializeObject(responseString); + +// return response; +//} \ No newline at end of file diff --git a/MatrixDotNetLib/MatrixDotNetLib/MatrixImageInfo.cs b/MatrixDotNetLib/MatrixDotNetLib/MatrixImageInfo.cs new file mode 100644 index 0000000..ab2ea65 --- /dev/null +++ b/MatrixDotNetLib/MatrixDotNetLib/MatrixImageInfo.cs @@ -0,0 +1,44 @@ +using Newtonsoft.Json; + +namespace MatrixDotNetLib +{ + public class MatrixImageInfo : MatrixImageThumbInfo + { + [JsonProperty("thumbnail_info")] + public MatrixImageThumbInfo ThumbnailInfo { get; set; } + + public string ThumbnailUrl { get; set; } + } +} + + + +//// simplest implementation +//// might not work for UWP +//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c +//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json"); + +//HttpClient client = new HttpClient(); +//client.BaseAddress = new Uri(loginUrl); +//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + +//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result; +//string responseString = responseMessage.Content.ReadAsStringAsync().Result; + +//if(responseString.Contains("errcode")) +//{ +// // deserialize into error object +// MatrixError error = JsonConvert.DeserializeObject(responseString); + +// // convert error object to a string +// string errMsg = error.ErrorCode + ": " + error.ErrorMessage; + +// // throw exception (can be caught and handled gracefully) +// throw new Exception(errMsg); +//} +//else +//{ +// MatrixLoginResponse response = JsonConvert.DeserializeObject(responseString); + +// return response; +//} \ No newline at end of file diff --git a/MatrixDotNetLib/MatrixDotNetLib/MatrixImageThumbInfo.cs b/MatrixDotNetLib/MatrixDotNetLib/MatrixImageThumbInfo.cs new file mode 100644 index 0000000..ca5e1c6 --- /dev/null +++ b/MatrixDotNetLib/MatrixDotNetLib/MatrixImageThumbInfo.cs @@ -0,0 +1,45 @@ +using Newtonsoft.Json; + +namespace MatrixDotNetLib +{ + public class MatrixImageThumbInfo : MatrixFileInfo + { + [JsonProperty("w")] + public int Width { get; set; } + + [JsonProperty("h")] + public int Height { get; set; } + } +} + + + +//// simplest implementation +//// might not work for UWP +//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c +//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json"); + +//HttpClient client = new HttpClient(); +//client.BaseAddress = new Uri(loginUrl); +//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + +//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result; +//string responseString = responseMessage.Content.ReadAsStringAsync().Result; + +//if(responseString.Contains("errcode")) +//{ +// // deserialize into error object +// MatrixError error = JsonConvert.DeserializeObject(responseString); + +// // convert error object to a string +// string errMsg = error.ErrorCode + ": " + error.ErrorMessage; + +// // throw exception (can be caught and handled gracefully) +// throw new Exception(errMsg); +//} +//else +//{ +// MatrixLoginResponse response = JsonConvert.DeserializeObject(responseString); + +// return response; +//} \ No newline at end of file diff --git a/MatrixDotNetLib/MatrixDotNetLib/MatrixSessionManager.cs b/MatrixDotNetLib/MatrixDotNetLib/MatrixSessionManager.cs index 50fcfa1..7a27f67 100644 --- a/MatrixDotNetLib/MatrixDotNetLib/MatrixSessionManager.cs +++ b/MatrixDotNetLib/MatrixDotNetLib/MatrixSessionManager.cs @@ -1,7 +1,5 @@ using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using System; -using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net; @@ -283,202 +281,6 @@ namespace MatrixDotNetLib } } } - - // classes to be moved // - - - public class MatrixSyncBody - { - public MatrixSyncRooms Rooms { get; set; } - } - - public class MatrixSyncRooms - { - // once the JSON from "join" is parsed, this is set to its contents as an object - public Dictionary Joined { get; private set;} - - public Dictionary Invited { get; private set; } - - public Dictionary Left { get; private set; } - - public JObject Join - { - get { return null; } - set - { - // takes JSON children and parses them into objects - // we have to do this bc the entity names under "join" are dynamic - // each entity holds a well-defined object though - - // create dict for Joined - Joined = new Dictionary(); - - // these AREN'T an array - ParseRooms(value, "Joined"); - } - } - - public JObject Invite - { - get { return null; } - set - { - // create dict for Joined - Invited = new Dictionary(); - - // these AREN'T an array - ParseRooms(value, "Invited"); - } - } - - public JObject Leave - { - get { return null; } - set - { - // create dict for Joined - Left = new Dictionary(); - - // these AREN'T an array - ParseRooms(value, "Left"); - } - } - - public void ParseRooms(JObject roomsJson, string valType) - { - // get the children of this object - JEnumerable kids = roomsJson.Children(); - - Dictionary roomList = new Dictionary(); - - foreach (JProperty kid in kids) - { - MatrixSyncRoom msr = JsonConvert.DeserializeObject(kid.Value.ToString()); - - roomList.Add(kid.Name, msr); - } - - // get the target - this.GetType().GetProperty(valType).SetValue(this,roomList); - } - } - - public class MatrixSyncRoom - { - public MatrixTimeline Timeline { get; set; } - } - - public class MatrixTimeline - { - public MatrixEvent[] Events { get; set; } - - [JsonProperty("prev_batch")] - public string PreviousBatch { get; set; } - - public bool IsLimited { get; set; } - } - - public class MatrixEvent - { - [JsonProperty("type")] - public string EventType { get; set; } - - public string Sender { get; set; } - - public MatrixEventContent Content { get; set; } - - [JsonProperty("state_key")] - public string StateKey { get; set; } - - [JsonProperty("origin_server_ts")] - public Int64 OriginTs { get; set; } - - public MatrixEventUnsigned Unsigned { get; set; } - } - - public class MatrixEventUnsigned - { - public int Age { get; set; } - - [JsonProperty("replaces_state")] - public string ReplaceState { get; set; } - - [JsonProperty("prev_content")] - public MatrixEventPrevContent PrevContent { get; set; } - } - - public class MatrixEventPrevContent - { - [JsonProperty("is_direct")] - public bool IsDirect { get; set; } - - public string Membership { get; set; } - - public string DisplayName { get; set; } - } - - public class MatrixEventContent - { - - public string Body { get; set; } - - public string Creator { get; set; } - - public string DisplayName { get; set; } - - [JsonProperty("event_id")] - public string EventId { get; set; } - - /// - /// Gets or sets the event content info property - check FileInfo.MimeType for file type - /// - [JsonProperty("info")] - public MatrixImageInfo FileInfo { get; set; } - - [JsonProperty("currently_active")] - public bool IsActive { get; set; } - - [JsonProperty("join_rule")] - public string JoinRule { get; set; } - - [JsonProperty("last_active_ago")] - public int LastActive { get; set; } - - public string Membership { get; set; } - - public string Name { get; set; } - - public string Presence { get; set; } - - [JsonProperty("room_version")] - public string RoomVersion { get; set; } - - public List Users { get; set; } - } - - public class MatrixFileInfo - { - public Int64 size { get; set; } - - public string MimeType { get; set; } - } - - public class MatrixImageThumbInfo : MatrixFileInfo - { - [JsonProperty("w")] - public int Width { get; set; } - - [JsonProperty("h")] - public int Height { get; set; } - } - - public class MatrixImageInfo : MatrixImageThumbInfo - { - [JsonProperty("thumbnail_info")] - public MatrixImageThumbInfo ThumbnailInfo { get; set; } - - public string ThumbnailUrl { get; set; } - } } diff --git a/MatrixDotNetLib/MatrixDotNetLib/MatrixSyncBody.cs b/MatrixDotNetLib/MatrixDotNetLib/MatrixSyncBody.cs new file mode 100644 index 0000000..76c5daa --- /dev/null +++ b/MatrixDotNetLib/MatrixDotNetLib/MatrixSyncBody.cs @@ -0,0 +1,7 @@ +namespace MatrixDotNetLib +{ + public class MatrixSyncBody + { + public MatrixSyncRooms Rooms { get; set; } + } +} \ No newline at end of file diff --git a/MatrixDotNetLib/MatrixDotNetLib/MatrixSyncRoom.cs b/MatrixDotNetLib/MatrixDotNetLib/MatrixSyncRoom.cs new file mode 100644 index 0000000..2215d78 --- /dev/null +++ b/MatrixDotNetLib/MatrixDotNetLib/MatrixSyncRoom.cs @@ -0,0 +1,39 @@ +namespace MatrixDotNetLib +{ + public class MatrixSyncRoom + { + public MatrixTimeline Timeline { get; set; } + } +} + + + +//// simplest implementation +//// might not work for UWP +//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c +//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json"); + +//HttpClient client = new HttpClient(); +//client.BaseAddress = new Uri(loginUrl); +//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + +//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result; +//string responseString = responseMessage.Content.ReadAsStringAsync().Result; + +//if(responseString.Contains("errcode")) +//{ +// // deserialize into error object +// MatrixError error = JsonConvert.DeserializeObject(responseString); + +// // convert error object to a string +// string errMsg = error.ErrorCode + ": " + error.ErrorMessage; + +// // throw exception (can be caught and handled gracefully) +// throw new Exception(errMsg); +//} +//else +//{ +// MatrixLoginResponse response = JsonConvert.DeserializeObject(responseString); + +// return response; +//} \ No newline at end of file diff --git a/MatrixDotNetLib/MatrixDotNetLib/MatrixSyncRooms.cs b/MatrixDotNetLib/MatrixDotNetLib/MatrixSyncRooms.cs new file mode 100644 index 0000000..82aae26 --- /dev/null +++ b/MatrixDotNetLib/MatrixDotNetLib/MatrixSyncRooms.cs @@ -0,0 +1,109 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System.Collections.Generic; + +namespace MatrixDotNetLib +{ + public class MatrixSyncRooms + { + // once the JSON from "join" is parsed, this is set to its contents as an object + public Dictionary Joined { get; private set;} + + public Dictionary Invited { get; private set; } + + public Dictionary Left { get; private set; } + + public JObject Join + { + get { return null; } + set + { + // takes JSON children and parses them into objects + // we have to do this bc the entity names under "join" are dynamic + // each entity holds a well-defined object though + + // create dict for Joined + Joined = new Dictionary(); + + // these AREN'T an array + ParseRooms(value, "Joined"); + } + } + + public JObject Invite + { + get { return null; } + set + { + // create dict for Joined + Invited = new Dictionary(); + + // these AREN'T an array + ParseRooms(value, "Invited"); + } + } + + public JObject Leave + { + get { return null; } + set + { + // create dict for Joined + Left = new Dictionary(); + + // these AREN'T an array + ParseRooms(value, "Left"); + } + } + + public void ParseRooms(JObject roomsJson, string valType) + { + // get the children of this object + JEnumerable kids = roomsJson.Children(); + + Dictionary roomList = new Dictionary(); + + foreach (JProperty kid in kids) + { + MatrixSyncRoom msr = JsonConvert.DeserializeObject(kid.Value.ToString()); + + roomList.Add(kid.Name, msr); + } + + // get the target + this.GetType().GetProperty(valType).SetValue(this,roomList); + } + } +} + + + +//// simplest implementation +//// might not work for UWP +//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c +//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json"); + +//HttpClient client = new HttpClient(); +//client.BaseAddress = new Uri(loginUrl); +//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + +//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result; +//string responseString = responseMessage.Content.ReadAsStringAsync().Result; + +//if(responseString.Contains("errcode")) +//{ +// // deserialize into error object +// MatrixError error = JsonConvert.DeserializeObject(responseString); + +// // convert error object to a string +// string errMsg = error.ErrorCode + ": " + error.ErrorMessage; + +// // throw exception (can be caught and handled gracefully) +// throw new Exception(errMsg); +//} +//else +//{ +// MatrixLoginResponse response = JsonConvert.DeserializeObject(responseString); + +// return response; +//} \ No newline at end of file diff --git a/MatrixDotNetLib/MatrixDotNetLib/MatrixTimeline.cs b/MatrixDotNetLib/MatrixDotNetLib/MatrixTimeline.cs new file mode 100644 index 0000000..4089f11 --- /dev/null +++ b/MatrixDotNetLib/MatrixDotNetLib/MatrixTimeline.cs @@ -0,0 +1,46 @@ +using Newtonsoft.Json; + +namespace MatrixDotNetLib +{ + public class MatrixTimeline + { + public MatrixEvent[] Events { get; set; } + + [JsonProperty("prev_batch")] + public string PreviousBatch { get; set; } + + public bool IsLimited { get; set; } + } +} + + + +//// simplest implementation +//// might not work for UWP +//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c +//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json"); + +//HttpClient client = new HttpClient(); +//client.BaseAddress = new Uri(loginUrl); +//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + +//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result; +//string responseString = responseMessage.Content.ReadAsStringAsync().Result; + +//if(responseString.Contains("errcode")) +//{ +// // deserialize into error object +// MatrixError error = JsonConvert.DeserializeObject(responseString); + +// // convert error object to a string +// string errMsg = error.ErrorCode + ": " + error.ErrorMessage; + +// // throw exception (can be caught and handled gracefully) +// throw new Exception(errMsg); +//} +//else +//{ +// MatrixLoginResponse response = JsonConvert.DeserializeObject(responseString); + +// return response; +//} \ No newline at end of file