Move Matrix.Event.Receipt._receipt_data to Gee.HashMap
This commit is contained in:
parent
51c204cc90
commit
a39edfc15a
@ -30,7 +30,7 @@ public class Matrix.Event.Receipt : Matrix.Event.Base {
|
|||||||
string user;
|
string user;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashTable<ReceiptData?, ulong?> _receipt_data = null;
|
private Gee.HashMap<ReceiptData?, ulong?> _receipt_data = null;
|
||||||
|
|
||||||
private static bool
|
private static bool
|
||||||
_rd_equal(ReceiptData k1, ReceiptData k2)
|
_rd_equal(ReceiptData k1, ReceiptData k2)
|
||||||
@ -43,8 +43,7 @@ public class Matrix.Event.Receipt : Matrix.Event.Base {
|
|||||||
private void
|
private void
|
||||||
_init_receipt_data()
|
_init_receipt_data()
|
||||||
{
|
{
|
||||||
_receipt_data = new HashTable<ReceiptData?, ulong?>(
|
_receipt_data = new Gee.HashMap<ReceiptData?, ulong?>(null, (Gee.EqualDataFunc)_rd_equal);
|
||||||
direct_hash, (EqualFunc)_rd_equal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void
|
protected override void
|
||||||
@ -76,9 +75,8 @@ public class Matrix.Event.Receipt : Matrix.Event.Base {
|
|||||||
user = r_user_id
|
user = r_user_id
|
||||||
};
|
};
|
||||||
|
|
||||||
_receipt_data.replace(
|
_receipt_data[rd_key] =
|
||||||
rd_key,
|
(ulong)r_content.get_object().get_member("ts").get_int();
|
||||||
(ulong)r_content.get_object().get_member("ts").get_int());
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
warning("content.$event-id.m.read is missing from a m.presence event");
|
warning("content.$event-id.m.read is missing from a m.presence event");
|
||||||
@ -103,57 +101,57 @@ public class Matrix.Event.Receipt : Matrix.Event.Base {
|
|||||||
var content_root = root.get_member("content").get_object();
|
var content_root = root.get_member("content").get_object();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
_receipt_data.foreach((key, value) => {
|
foreach (var entry in _receipt_data.entries) {
|
||||||
Json.Object event_object;
|
Json.Object event_object;
|
||||||
Json.Object type_object;
|
Json.Object type_object;
|
||||||
Json.Object user_object;
|
Json.Object user_object;
|
||||||
|
|
||||||
if (key.event_id == null) {
|
if (entry.key.event_id == null) {
|
||||||
throw new Matrix.Error.INCOMPLETE(
|
throw new Matrix.Error.INCOMPLETE(
|
||||||
"Won't generate a m.receipt event with an empty event ID");
|
"Won't generate a m.receipt event with an empty event ID");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.typ == null) {
|
if (entry.key.typ == null) {
|
||||||
throw new Matrix.Error.INCOMPLETE(
|
throw new Matrix.Error.INCOMPLETE(
|
||||||
"Won't generate a m.receipt event with an empty receipt type");
|
"Won't generate a m.receipt event with an empty receipt type");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.user == null) {
|
if (entry.key.user == null) {
|
||||||
throw new Matrix.Error.INCOMPLETE(
|
throw new Matrix.Error.INCOMPLETE(
|
||||||
"Won't generate a m.receipt event with an empty user ID");
|
"Won't generate a m.receipt event with an empty user ID");
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
if ((node = content_root.get_member(key.event_id)) == null) {
|
if ((node = content_root.get_member(entry.key.event_id)) == null) {
|
||||||
event_object = new Json.Object();
|
event_object = new Json.Object();
|
||||||
node = new Json.Node(Json.NodeType.OBJECT);
|
node = new Json.Node(Json.NodeType.OBJECT);
|
||||||
node.set_object(event_object);
|
node.set_object(event_object);
|
||||||
content_root.set_member(key.event_id, node);
|
content_root.set_member(entry.key.event_id, node);
|
||||||
} else {
|
} else {
|
||||||
event_object = node.get_object();
|
event_object = node.get_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((node = event_object.get_member(key.typ)) == null) {
|
if ((node = event_object.get_member(entry.key.typ)) == null) {
|
||||||
type_object = new Json.Object();
|
type_object = new Json.Object();
|
||||||
node = new Json.Node(Json.NodeType.OBJECT);
|
node = new Json.Node(Json.NodeType.OBJECT);
|
||||||
node.set_object(type_object);
|
node.set_object(type_object);
|
||||||
event_object.set_member(key.typ, node);
|
event_object.set_member(entry.key.typ, node);
|
||||||
} else {
|
} else {
|
||||||
type_object = node.get_object();
|
type_object = node.get_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((node = type_object.get_member(key.user)) == null) {
|
if ((node = type_object.get_member(entry.key.user)) == null) {
|
||||||
user_object = new Json.Object();
|
user_object = new Json.Object();
|
||||||
node = new Json.Node(Json.NodeType.OBJECT);
|
node = new Json.Node(Json.NodeType.OBJECT);
|
||||||
node.set_object(user_object);
|
node.set_object(user_object);
|
||||||
type_object.set_member(key.user, node);
|
type_object.set_member(entry.key.user, node);
|
||||||
} else {
|
} else {
|
||||||
user_object = node.get_object();
|
user_object = node.get_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
user_object.set_int_member("ts", value);
|
user_object.set_int_member("ts", entry.value);
|
||||||
});
|
}
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
throw new Matrix.Error.INCOMPLETE(
|
throw new Matrix.Error.INCOMPLETE(
|
||||||
|
Loading…
Reference in New Issue
Block a user