Merge branch 'krille/fake-syncs-for-fake-events' into 'master'
Use SyncUpdate for pending messages See merge request famedly/famedlysdk!385
This commit is contained in:
commit
2697f88397
|
@ -146,7 +146,9 @@ class Event extends MatrixEvent {
|
||||||
final unsigned = Event.getMapFromPayload(jsonPayload['unsigned']);
|
final unsigned = Event.getMapFromPayload(jsonPayload['unsigned']);
|
||||||
final prevContent = Event.getMapFromPayload(jsonPayload['prev_content']);
|
final prevContent = Event.getMapFromPayload(jsonPayload['prev_content']);
|
||||||
return Event(
|
return Event(
|
||||||
status: jsonPayload['status'] ?? defaultStatus,
|
status: jsonPayload['status'] ??
|
||||||
|
unsigned[MessageSendingStatusKey] ??
|
||||||
|
defaultStatus,
|
||||||
stateKey: jsonPayload['state_key'],
|
stateKey: jsonPayload['state_key'],
|
||||||
prevContent: prevContent,
|
prevContent: prevContent,
|
||||||
content: content,
|
content: content,
|
||||||
|
|
|
@ -39,6 +39,8 @@ enum PushRuleState { notify, mentions_only, dont_notify }
|
||||||
enum JoinRules { public, knock, invite, private }
|
enum JoinRules { public, knock, invite, private }
|
||||||
enum GuestAccess { can_join, forbidden }
|
enum GuestAccess { can_join, forbidden }
|
||||||
enum HistoryVisibility { invited, joined, shared, world_readable }
|
enum HistoryVisibility { invited, joined, shared, world_readable }
|
||||||
|
const String MessageSendingStatusKey =
|
||||||
|
'com.famedly.famedlysdk.message_sending_status';
|
||||||
|
|
||||||
/// Represents a Matrix room.
|
/// Represents a Matrix room.
|
||||||
class Room {
|
class Room {
|
||||||
|
@ -678,27 +680,20 @@ class Room {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final sortOrder = newSortOrder;
|
final syncUpdate = SyncUpdate()
|
||||||
// Display a *sending* event and store it.
|
..rooms = (RoomsUpdate()
|
||||||
var eventUpdate = EventUpdate(
|
..join = (<String, JoinedRoomUpdate>{}..[id] = (JoinedRoomUpdate()
|
||||||
type: 'timeline',
|
..timeline = (TimelineUpdate()
|
||||||
roomID: id,
|
..events = [
|
||||||
eventType: type,
|
MatrixEvent()
|
||||||
sortOrder: sortOrder,
|
..content = content
|
||||||
content: {
|
..type = type
|
||||||
'type': type,
|
..eventId = messageID
|
||||||
'event_id': messageID,
|
..senderId = client.userID
|
||||||
'sender': client.userID,
|
..originServerTs = DateTime.now()
|
||||||
'status': 0,
|
..unsigned = {MessageSendingStatusKey: 0},
|
||||||
'origin_server_ts': DateTime.now().millisecondsSinceEpoch,
|
]))));
|
||||||
'content': content
|
await client.handleSync(syncUpdate);
|
||||||
},
|
|
||||||
);
|
|
||||||
client.onEvent.add(eventUpdate);
|
|
||||||
await client.database?.transaction(() async {
|
|
||||||
await client.database.storeEventUpdate(client.id, eventUpdate);
|
|
||||||
await updateSortOrder();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Send the text and on success, store and display a *sent* event.
|
// Send the text and on success, store and display a *sent* event.
|
||||||
try {
|
try {
|
||||||
|
@ -712,23 +707,18 @@ class Room {
|
||||||
messageID,
|
messageID,
|
||||||
sendMessageContent,
|
sendMessageContent,
|
||||||
);
|
);
|
||||||
eventUpdate.content['status'] = 1;
|
syncUpdate.rooms.join.values.first.timeline.events.first
|
||||||
eventUpdate.content['unsigned'] = {'transaction_id': messageID};
|
.unsigned[MessageSendingStatusKey] = 1;
|
||||||
eventUpdate.content['event_id'] = res;
|
syncUpdate.rooms.join.values.first.timeline.events.first
|
||||||
client.onEvent.add(eventUpdate);
|
.unsigned['transaction_id'] = messageID;
|
||||||
await client.database?.transaction(() async {
|
syncUpdate.rooms.join.values.first.timeline.events.first.eventId = res;
|
||||||
await client.database.storeEventUpdate(client.id, eventUpdate);
|
await client.handleSync(syncUpdate);
|
||||||
});
|
|
||||||
return res;
|
return res;
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
print('[Client] Error while sending: ' + exception.toString());
|
print('[Client] Error while sending: ' + exception.toString());
|
||||||
// On error, set status to -1
|
syncUpdate.rooms.join.values.first.timeline.events.first
|
||||||
eventUpdate.content['status'] = -1;
|
.unsigned[MessageSendingStatusKey] = -1;
|
||||||
eventUpdate.content['unsigned'] = {'transaction_id': messageID};
|
await client.handleSync(syncUpdate);
|
||||||
client.onEvent.add(eventUpdate);
|
|
||||||
await client.database?.transaction(() async {
|
|
||||||
await client.database.storeEventUpdate(client.id, eventUpdate);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,8 +186,12 @@ void main() {
|
||||||
},
|
},
|
||||||
sortOrder: room.newSortOrder));
|
sortOrder: room.newSortOrder));
|
||||||
await Future.delayed(Duration(milliseconds: 50));
|
await Future.delayed(Duration(milliseconds: 50));
|
||||||
|
|
||||||
|
expect(updateCount, 7);
|
||||||
await room.sendTextEvent('test', txid: 'errortxid');
|
await room.sendTextEvent('test', txid: 'errortxid');
|
||||||
await Future.delayed(Duration(milliseconds: 50));
|
await Future.delayed(Duration(milliseconds: 50));
|
||||||
|
|
||||||
|
expect(updateCount, 9);
|
||||||
await room.sendTextEvent('test', txid: 'errortxid2');
|
await room.sendTextEvent('test', txid: 'errortxid2');
|
||||||
await Future.delayed(Duration(milliseconds: 50));
|
await Future.delayed(Duration(milliseconds: 50));
|
||||||
await room.sendTextEvent('test', txid: 'errortxid3');
|
await room.sendTextEvent('test', txid: 'errortxid3');
|
||||||
|
|
Loading…
Reference in a new issue