Merge branch 'timeline-fix-event-state' into 'master'

[Timeline] Fix event state change.

See merge request famedly/famedlysdk!17
This commit is contained in:
Marcel 2019-06-26 17:03:15 +00:00
commit 294903d466
3 changed files with 11 additions and 9 deletions

View file

@ -37,8 +37,6 @@ class Timeline {
final onTimelineUpdateCallback onUpdate;
final onTimelineInsertCallback onInsert;
Set<String> waitToReplace = {};
StreamSubscription<EventUpdate> sub;
Timeline({this.room, this.events, this.onUpdate, this.onInsert}) {
@ -52,20 +50,23 @@ class Timeline {
// Is this event already in the timeline?
if (eventUpdate.content["status"] == 1 ||
eventUpdate.content["status"] == -1 ||
waitToReplace.contains(eventUpdate.content["id"])) {
(eventUpdate.content.containsKey("unsigned") &&
eventUpdate.content["unsigned"]["transaction_id"] is String)) {
int i;
for (i = 0; i < events.length; i++) {
if (events[i].content.containsKey("txid") &&
events[i].content["txid"] ==
eventUpdate.content["content"]["txid"] ||
events[i].id == eventUpdate.content["id"]) break;
events[i].id == eventUpdate.content["id"] ||
(eventUpdate.content.containsKey("unsigned") &&
eventUpdate.content["unsigned"]["transaction_id"]
is String &&
events[i].content["txid"] ==
eventUpdate.content["unsigned"]["transaction_id"]))
break;
}
if (i < events.length) {
events[i] = Event.fromJson(eventUpdate.content, room);
if (eventUpdate.content["content"]["txid"] is String)
waitToReplace.add(eventUpdate.content["id"]);
else
waitToReplace.remove(eventUpdate.content["id"]);
}
} else {
if (!eventUpdate.content.containsKey("id"))

View file

@ -36,7 +36,7 @@ class EventUpdate {
final String eventType;
// The json payload of the content of this event.
final dynamic content;
final Map<String, dynamic> content;
EventUpdate({this.eventType, this.roomID, this.type, this.content});
}

View file

@ -115,6 +115,7 @@ void main() {
"sender": "@alice:example.com",
"status": 2,
"id": "42",
"unsigned": {"transaction_id": "1234"},
"origin_server_ts": DateTime.now().millisecondsSinceEpoch
}));