Merge branch 'event-enhance-eventtypes' into 'master'

[Sending] Refactoring

See merge request famedly/famedlysdk!44
This commit is contained in:
Phillipp Kurtz 2019-07-23 09:09:13 +00:00
commit f1c78b6406
5 changed files with 21 additions and 20 deletions

View file

@ -193,7 +193,6 @@ class Room {
"content": {
"msgtype": "m.text",
"body": message,
"txid": messageID,
}
});
client.connection.onEvent.add(eventUpdate);
@ -208,6 +207,7 @@ class Room {
if (res is ErrorResponse || !(res["event_id"] is String)) {
// On error, set status to -1
eventUpdate.content["status"] = -1;
eventUpdate.content["unsigned"] = {"transaction_id": messageID};
client.connection.onEvent.add(eventUpdate);
await client.store?.transaction(() {
client.store.storeEventUpdate(eventUpdate);
@ -215,6 +215,7 @@ class Room {
});
} else {
eventUpdate.content["status"] = 1;
eventUpdate.content["unsigned"] = {"transaction_id": messageID};
eventUpdate.content["event_id"] = res["event_id"];
client.connection.onEvent.add(eventUpdate);
await client.store?.transaction(() {
@ -375,7 +376,9 @@ class Room {
static Future<Room> getRoomFromTableRow(
Map<String, dynamic> row, Client matrix) async {
String name = row["topic"];
if (name == "")
if (name == "" && !row["canonical_alias"].isEmpty)
name = row["canonical_alias"];
else if (name == "")
name = await matrix.store?.getChatNameFromMemberNames(row["id"]) ?? "";
String avatarUrl = row["avatar_url"];
@ -400,6 +403,7 @@ class Room {
guestAccess: row["guest_access"],
historyVisibility: row["history_visibility"],
joinRules: row["join_rules"],
canonicalAlias: row["canonical_alias"],
powerLevels: {
"power_events_default": row["power_events_default"],
"power_state_default": row["power_state_default"],

View file

@ -55,7 +55,7 @@ class Store {
_init() async {
var databasePath = await getDatabasesPath();
String path = p.join(databasePath, "FluffyMatrix.db");
_db = await openDatabase(path, version: 7,
_db = await openDatabase(path, version: 8,
onCreate: (Database db, int version) async {
await createTables(db);
}, onUpgrade: (Database db, int oldVersion, int newVersion) async {
@ -300,6 +300,12 @@ class Store {
txn.rawUpdate("UPDATE Rooms SET guest_access=? WHERE id=?",
[eventContent["content"]["guest_access"], chat_id]);
break;
// This event means, that the canonical alias of a room has been changed, so
// it has to be changed in the database
case "m.room.canonical_alias":
txn.rawUpdate("UPDATE Chats SET canonical_alias=? WHERE id=?",
[eventContent["content"]["alias"] ?? "", chat_id]);
break;
// This event means, that the topic of a room has been changed, so
// it has to be changed in the database
case "m.room.join_rules":

View file

@ -44,14 +44,11 @@ class Timeline {
sub ??= room.client.connection.onEvent.stream.listen(_handleEventUpdate);
}
int _findEvent({String event_id, String txid, String unsigned_txid}) {
int _findEvent({String event_id, String unsigned_txid}) {
int i;
for (i = 0; i < events.length; i++) {
if (events[i].content.containsKey("txid") &&
(txid != null && events[i].content["txid"] == txid) ||
events[i].id == event_id ||
(unsigned_txid != null && events[i].content["txid"] == unsigned_txid))
break;
if (events[i].id == event_id ||
(unsigned_txid != null && events[i].id == unsigned_txid)) break;
}
return i;
}
@ -65,13 +62,10 @@ class Timeline {
if (i < events.length) events.removeAt(i);
}
// Is this event already in the timeline?
else if (eventUpdate.content["status"] == 1 ||
eventUpdate.content["status"] == -1 ||
(eventUpdate.content.containsKey("unsigned") &&
eventUpdate.content["unsigned"]["transaction_id"] is String)) {
else if (eventUpdate.content.containsKey("unsigned") &&
eventUpdate.content["unsigned"]["transaction_id"] is String) {
int i = _findEvent(
event_id: eventUpdate.content["event_id"],
txid: eventUpdate.content["content"]["txid"],
unsigned_txid: eventUpdate.content.containsKey("unsigned")
? eventUpdate.content["unsigned"]["transaction_id"]
: null);

View file

@ -59,6 +59,7 @@ void main() {
final String fullyRead = "fjh82jdjifd:server.abc";
final String notificationSettings = "all";
final String guestAccess = "forbidden";
final String canonicalAlias = "#testroom:example.com";
final String historyVisibility = "invite";
final String joinRules = "invite";
final int now = DateTime.now().millisecondsSinceEpoch;
@ -85,6 +86,7 @@ void main() {
"guest_access": guestAccess,
"history_visibility": historyVisibility,
"join_rules": joinRules,
"canonical_alias": canonicalAlias,
"power_events_default": 0,
"power_state_default": 0,
"power_redact": 0,
@ -115,6 +117,7 @@ void main() {
expect(room.notificationSettings, notificationSettings);
expect(room.directChatMatrixID, "");
expect(room.draft, "");
expect(room.canonicalAlias, canonicalAlias);
expect(room.prev_batch, "");
expect(room.guestAccess, guestAccess);
expect(room.historyVisibility, historyVisibility);

View file

@ -103,7 +103,6 @@ void main() {
expect(updateCount, 4);
expect(insertList, [0, 0, 0]);
expect(insertList.length, timeline.events.length);
expect(timeline.events[0].content["txid"], "1234");
expect(timeline.events[0].id, "42");
expect(timeline.events[0].status, 1);
@ -154,11 +153,8 @@ void main() {
expect(updateCount, 12);
expect(insertList, [0, 0, 0, 0, 0, 0, 0]);
expect(insertList.length, timeline.events.length);
expect(timeline.events[0].content["txid"], "errortxid3");
expect(timeline.events[0].status, -1);
expect(timeline.events[1].content["txid"], "errortxid2");
expect(timeline.events[1].status, -1);
expect(timeline.events[2].content["txid"], "errortxid");
expect(timeline.events[2].status, -1);
});
@ -171,7 +167,6 @@ void main() {
expect(insertList, [0, 0, 0, 0, 0, 0, 0]);
expect(timeline.events.length, 6);
expect(timeline.events[0].content["txid"], "errortxid2");
expect(timeline.events[0].status, -1);
});
@ -184,7 +179,6 @@ void main() {
expect(insertList, [0, 0, 0, 0, 0, 0, 0, 0]);
expect(timeline.events.length, 6);
expect(timeline.events[0].content["txid"], "1234");
expect(timeline.events[0].status, 1);
});