Claire
4 years ago
13 changed files with 591 additions and 198 deletions
@ -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<MatrixError>(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<MatrixLoginResponse>(responseString); |
||||
|
||||
// return response; |
||||
//} |
@ -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; } |
||||
|
||||
/// <summary> |
||||
/// Gets or sets the event content info property - check FileInfo.MimeType for file type |
||||
/// </summary> |
||||
[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<string> 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<MatrixError>(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<MatrixLoginResponse>(responseString); |
||||
|
||||
// return response; |
||||
//} |
@ -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<MatrixError>(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<MatrixLoginResponse>(responseString); |
||||
|
||||
// return response; |
||||
//} |
@ -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<MatrixError>(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<MatrixLoginResponse>(responseString); |
||||
|
||||
// return response; |
||||
//} |
@ -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<MatrixError>(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<MatrixLoginResponse>(responseString); |
||||
|
||||
// return response; |
||||
//} |
@ -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<MatrixError>(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<MatrixLoginResponse>(responseString); |
||||
|
||||
// return response; |
||||
//} |
@ -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<MatrixError>(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<MatrixLoginResponse>(responseString); |
||||
|
||||
// return response; |
||||
//} |
@ -0,0 +1,7 @@
|
||||
namespace MatrixDotNetLib |
||||
{ |
||||
public class MatrixSyncBody |
||||
{ |
||||
public MatrixSyncRooms Rooms { get; set; } |
||||
} |
||||
} |
@ -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<MatrixError>(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<MatrixLoginResponse>(responseString); |
||||
|
||||
// return response; |
||||
//} |
@ -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<string,MatrixSyncRoom> Joined { get; private set;} |
||||
|
||||
public Dictionary<string, MatrixSyncRoom> Invited { get; private set; } |
||||
|
||||
public Dictionary<string, MatrixSyncRoom> 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<string, MatrixSyncRoom>(); |
||||
|
||||
// these AREN'T an array |
||||
ParseRooms(value, "Joined"); |
||||
} |
||||
} |
||||
|
||||
public JObject Invite |
||||
{ |
||||
get { return null; } |
||||
set |
||||
{ |
||||
// create dict for Joined |
||||
Invited = new Dictionary<string, MatrixSyncRoom>(); |
||||
|
||||
// these AREN'T an array |
||||
ParseRooms(value, "Invited"); |
||||
} |
||||
} |
||||
|
||||
public JObject Leave |
||||
{ |
||||
get { return null; } |
||||
set |
||||
{ |
||||
// create dict for Joined |
||||
Left = new Dictionary<string, MatrixSyncRoom>(); |
||||
|
||||
// these AREN'T an array |
||||
ParseRooms(value, "Left"); |
||||
} |
||||
} |
||||
|
||||
public void ParseRooms(JObject roomsJson, string valType) |
||||
{ |
||||
// get the children of this object |
||||
JEnumerable<JToken> kids = roomsJson.Children(); |
||||
|
||||
Dictionary<string,MatrixSyncRoom> roomList = new Dictionary<string,MatrixSyncRoom>(); |
||||
|
||||
foreach (JProperty kid in kids) |
||||
{ |
||||
MatrixSyncRoom msr = JsonConvert.DeserializeObject<MatrixSyncRoom>(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<MatrixError>(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<MatrixLoginResponse>(responseString); |
||||
|
||||
// return response; |
||||
//} |
@ -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<MatrixError>(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<MatrixLoginResponse>(responseString); |
||||
|
||||
// return response; |
||||
//} |
Loading…
issues.context.reference_issue