2025-01-08 14:24:48 +00:00
|
|
|
module util;
|
|
|
|
import asdf;
|
|
|
|
|
2025-01-08 22:25:20 +00:00
|
|
|
string intToStr(T)(T num) {
|
|
|
|
char[] buf;
|
|
|
|
for(short i; num > 0; ++i) {
|
|
|
|
buf = (num % 10 + '0')~buf;
|
|
|
|
num /= 10;
|
|
|
|
} return cast(string)buf;
|
|
|
|
}
|
|
|
|
|
2025-01-08 14:24:48 +00:00
|
|
|
struct JsonObject {
|
2025-01-08 22:25:20 +00:00
|
|
|
import mir.conv: to;
|
2025-01-08 14:24:48 +00:00
|
|
|
string data;
|
|
|
|
|
|
|
|
SerdeException deserializeFromAsdf(Asdf data) {
|
|
|
|
this.data = data.to!string;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
void serialize(S)(ref S serializer) {
|
|
|
|
try serializer.sink.putSmallEscaped(data.parseJson.to!string);
|
|
|
|
catch (Exception) serializer.sink.putSmallEscaped("{}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Sync {
|
|
|
|
struct StrippedStateEvent {
|
|
|
|
JsonObject content;
|
|
|
|
string sender, state_key, type;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Unsigned {
|
|
|
|
int age;
|
|
|
|
string membership, transaction_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Rooms {
|
|
|
|
struct Invited {
|
|
|
|
struct IS { StrippedStateEvent[] events; }
|
|
|
|
IS invite_state;
|
|
|
|
}
|
|
|
|
struct Joined {
|
|
|
|
struct Timeline {
|
|
|
|
struct EventWithoutRoomID {
|
|
|
|
JsonObject content;
|
|
|
|
string event_id;
|
|
|
|
ulong origin_server_ts;
|
|
|
|
@serdeOptional string sender, state_key, type;
|
|
|
|
// Unsigned unsigned;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventWithoutRoomID[] events;
|
|
|
|
bool limited;
|
|
|
|
string prev_batch;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct UNC {
|
|
|
|
int highlight_count;
|
|
|
|
int notification_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
Timeline timeline;
|
|
|
|
UNC unread_notifications;
|
|
|
|
}
|
|
|
|
|
|
|
|
@serdeOptional Invited[string] invite;
|
|
|
|
@serdeOptional Joined[string] join;
|
|
|
|
}
|
|
|
|
|
|
|
|
@serdeOptional Rooms rooms;
|
|
|
|
string next_batch;
|
|
|
|
}
|
|
|
|
|
|
|
|
// EVENTS
|
|
|
|
struct MSG {
|
|
|
|
string body;
|
|
|
|
@serdeOptional @serdeIgnoreDefault string formatted_body;
|
|
|
|
string msgtype = "m.notice";
|
|
|
|
@serdeOptional string format = "org.matrix.custom.html";
|
|
|
|
}
|