A native .NET C# library for developing Matrix clients.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
45 KiB

<Query Kind="Program">
<NuGetReference>Newtonsoft.Json</NuGetReference>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Bson</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
</Query>
void Main()
{
string txt = "{\n \"account_data\": {\n \"events\": [\n {\n \"type\": \"m.direct\",\n \"content\": {\n \"@jay:post.hyrule.cc\": [\n \"!gGpGMWeoEhhMMaWdGT:post.hyrule.cc\"\n ]\n }\n },\n {\n \"type\": \"m.secret_storage.key.qAQTfRWJpnqBn92JsgmzImEZoEq5I81L\",\n \"content\": {\n \"algorithm\": \"m.secret_storage.v1.aes-hmac-sha2\",\n \"passphrase\": {\n \"algorithm\": \"m.pbkdf2\",\n \"iterations\": 500000,\n \"salt\": \"yluvcuEslWDOoGjx0kdSpL6XypugFAlF\"\n },\n \"iv\": \"r44S20rG0vYHmS/1f9JE8A==\",\n \"mac\": \"0hJUMdPcwfFsUcAD3J4GrbTIbW+f52lbOmTxzEewvYE=\"\n }\n },\n {\n \"type\": \"m.secret_storage.default_key\",\n \"content\": {\n \"key\": \"qAQTfRWJpnqBn92JsgmzImEZoEq5I81L\"\n }\n },\n {\n \"type\": \"m.cross_signing.master\",\n \"content\": {\n \"encrypted\": {\n \"qAQTfRWJpnqBn92JsgmzImEZoEq5I81L\": {\n \"iv\": \"7ghVcptd3VhhfI4b/u17qg==\",\n \"ciphertext\": \"GuyMsI+roUkAfVxZPFOuKTWNuEAkb1CKQ8/VnYVUcJ25F4qHiG0xaaKP4kQ=\",\n \"mac\": \"KvqtwcOy73HCHYem1Oy7+KxUBvu+rw2+XnOPyzpozSc=\"\n }\n }\n }\n },\n {\n \"type\": \"m.cross_signing.self_signing\",\n \"content\": {\n \"encrypted\": {\n \"qAQTfRWJpnqBn92JsgmzImEZoEq5I81L\": {\n \"iv\": \"qWmjLCQyLGp1Jg7fAMh5lw==\",\n \"ciphertext\": \"mKc9wkV93IhwDWjuB1hPfR5VRuQiFVe+pF+BDZBoEJxOjxRJwXTgs/sXbAc=\",\n \"mac\": \"jaoUtwZGVA1nPP2dySZP0YSDb+QkfeWVqG3BHiNuH60=\"\n }\n }\n }\n },\n {\n \"type\": \"m.cross_signing.user_signing\",\n \"content\": {\n \"encrypted\": {\n \"qAQTfRWJpnqBn92JsgmzImEZoEq5I81L\": {\n \"iv\": \"lUCmom8R9UEJi6YGFgHESA==\",\n \"ciphertext\": \"vFIpV/NUohPu+G9iWtOi57jbRjWjhNBjS91rdkKolypaMuuOba9C8CjDD+s=\",\n \"mac\": \"5jdCXMplGXv2ufQKS6GEW+16mgaXGGKuThkPJ1qjubk=\"\n }\n }\n }\n },\n {\n \"type\": \"m.megolm_backup.v1\",\n \"content\": {\n \"encrypted\": {\n \"qAQTfRWJpnqBn92JsgmzImEZoEq5I81L\": {\n \"iv\": \"fiiaOiPwdC4UOgN0z8cujQ==\",\n \"ciphertext\": \"iT1CWwcGw6hRp343hFx00vIGyTDDSsvqCCVOEsU58N5WtQ3K7ilkIJ7xgrU=\",\n \"mac\": \"FgmKjel+mKt7gSlV0zqejfC9VMB+N5v02uv5v49ME74=\"\n }\n }\n }\n },\n {\n \"type\": \"im.vector.setting.breadcrumbs\",\n \"content\": {\n \"recent_rooms\": [\n \"!iEOZzedJhdJtozSkCK:post.hyrule.cc\",\n \"!OdeSTaDBtVXdpAAVue:post.hyrule.cc\",\n \"!gGpGMWeoEhhMMaWdGT:post.hyrule.cc\"\n ]\n }\n },\n {\n \"type\": \"im.vector.web.settings\",\n \"content\": {\n \"theme\": \"light\",\n \"useCompactLayout\": true\n }\n },\n {\n \"type\": \"m.push_rules\",\n \"content\": {\n \"global\": {\n \"underride\": [\n {\n \"conditions\": [\n {\n \"kind\": \"event_match\",\n \"key\": \"type\",\n \"pattern\": \"m.call.invite\"\n }\n ],\n \"actions\": [\n \"notify\",\n {\n \"set_tweak\": \"sound\",\n \"value\": \"ring\"\n },\n {\n \"set_tweak\": \"highlight\",\n \"value\": false\n }\n ],\n \"rule_id\": \".m.rule.call\",\n \"default\": true,\n \"enabled\": true\n },\n {\n \"conditions\": [\n {\n \"kind\"
dynamic d = JObject.Parse(txt);
JObject obj = d.rooms.join;
JEnumerable<JToken> kids = obj.Children();
foreach (JProperty kid in kids)
{
Console.WriteLine(kid.Name);
Console.WriteLine(kid.Value);
}
//Console.WriteLine(d.rooms.join["!gGpGMWeoEhhMMaWdGT:post.hyrule.cc"].timeline.events);
}
// Define other methods and classes here
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<string,MatrixSyncRoom> Joined { 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
// these AREN'T an array
ParseRooms(value);
}
}
public void ParseRooms(JObject roomsJson)
{
// get the children of this object
}
}
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
{
public string EventType { get; set; }
}