feat: Auto retry send events
This commit is contained in:
parent
adb907bbc4
commit
5019ebfeb5
|
@ -61,6 +61,8 @@ class Client extends MatrixApi {
|
||||||
|
|
||||||
Set<String> roomPreviewLastEvents;
|
Set<String> roomPreviewLastEvents;
|
||||||
|
|
||||||
|
int sendMessageTimeoutSeconds;
|
||||||
|
|
||||||
/// Create a client
|
/// Create a client
|
||||||
/// [clientName] = unique identifier of this client
|
/// [clientName] = unique identifier of this client
|
||||||
/// [database]: The database instance to use
|
/// [database]: The database instance to use
|
||||||
|
@ -92,6 +94,7 @@ class Client extends MatrixApi {
|
||||||
this.importantStateEvents,
|
this.importantStateEvents,
|
||||||
this.roomPreviewLastEvents,
|
this.roomPreviewLastEvents,
|
||||||
this.pinUnreadRooms = false,
|
this.pinUnreadRooms = false,
|
||||||
|
this.sendMessageTimeoutSeconds = 60,
|
||||||
@deprecated bool debug,
|
@deprecated bool debug,
|
||||||
}) {
|
}) {
|
||||||
verificationMethods ??= <KeyVerificationMethod>{};
|
verificationMethods ??= <KeyVerificationMethod>{};
|
||||||
|
|
|
@ -722,7 +722,7 @@ class Room {
|
||||||
content['formatted_body'] = '* ' + content['formatted_body'];
|
content['formatted_body'] = '* ' + content['formatted_body'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
final sentDate = DateTime.now();
|
||||||
final syncUpdate = SyncUpdate()
|
final syncUpdate = SyncUpdate()
|
||||||
..rooms = (RoomsUpdate()
|
..rooms = (RoomsUpdate()
|
||||||
..join = (<String, JoinedRoomUpdate>{}..[id] = (JoinedRoomUpdate()
|
..join = (<String, JoinedRoomUpdate>{}..[id] = (JoinedRoomUpdate()
|
||||||
|
@ -733,7 +733,7 @@ class Room {
|
||||||
..type = type
|
..type = type
|
||||||
..eventId = messageID
|
..eventId = messageID
|
||||||
..senderId = client.userID
|
..senderId = client.userID
|
||||||
..originServerTs = DateTime.now()
|
..originServerTs = sentDate
|
||||||
..unsigned = {
|
..unsigned = {
|
||||||
MessageSendingStatusKey: 0,
|
MessageSendingStatusKey: 0,
|
||||||
'transaction_id': messageID,
|
'transaction_id': messageID,
|
||||||
|
@ -742,26 +742,38 @@ class Room {
|
||||||
await _handleFakeSync(syncUpdate);
|
await _handleFakeSync(syncUpdate);
|
||||||
|
|
||||||
// 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 {
|
String res;
|
||||||
final res = await _sendContent(
|
while (res == null) {
|
||||||
type,
|
try {
|
||||||
content,
|
res = await _sendContent(
|
||||||
txid: messageID,
|
type,
|
||||||
);
|
content,
|
||||||
syncUpdate.rooms.join.values.first.timeline.events.first
|
txid: messageID,
|
||||||
.unsigned[MessageSendingStatusKey] = 1;
|
);
|
||||||
syncUpdate.rooms.join.values.first.timeline.events.first.eventId = res;
|
} catch (e, s) {
|
||||||
await _handleFakeSync(syncUpdate);
|
if ((DateTime.now().millisecondsSinceEpoch -
|
||||||
|
sentDate.millisecondsSinceEpoch) <
|
||||||
return res;
|
(1000 * client.sendMessageTimeoutSeconds)) {
|
||||||
} catch (e, s) {
|
Logs.warning('[Client] Problem while sending message because of "' +
|
||||||
Logs.warning(
|
e.toString() +
|
||||||
'[Client] Problem while sending message: ' + e.toString(), s);
|
'". Try again in 1 seconds...');
|
||||||
syncUpdate.rooms.join.values.first.timeline.events.first
|
await Future.delayed(Duration(seconds: 1));
|
||||||
.unsigned[MessageSendingStatusKey] = -1;
|
} else {
|
||||||
await _handleFakeSync(syncUpdate);
|
Logs.warning(
|
||||||
|
'[Client] Problem while sending message: ' + e.toString(), s);
|
||||||
|
syncUpdate.rooms.join.values.first.timeline.events.first
|
||||||
|
.unsigned[MessageSendingStatusKey] = -1;
|
||||||
|
await _handleFakeSync(syncUpdate);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
syncUpdate.rooms.join.values.first.timeline.events.first
|
||||||
|
.unsigned[MessageSendingStatusKey] = 1;
|
||||||
|
syncUpdate.rooms.join.values.first.timeline.events.first.eventId = res;
|
||||||
|
await _handleFakeSync(syncUpdate);
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call the Matrix API to join this room if the user is not already a member.
|
/// Call the Matrix API to join this room if the user is not already a member.
|
||||||
|
|
|
@ -33,7 +33,8 @@ void main() {
|
||||||
var updateCount = 0;
|
var updateCount = 0;
|
||||||
var insertList = <int>[];
|
var insertList = <int>[];
|
||||||
|
|
||||||
var client = Client('testclient', httpClient: FakeMatrixApi());
|
var client = Client('testclient',
|
||||||
|
httpClient: FakeMatrixApi(), sendMessageTimeoutSeconds: 5);
|
||||||
|
|
||||||
var room = Room(
|
var room = Room(
|
||||||
id: roomID, client: client, prev_batch: '1234', roomAccountData: {});
|
id: roomID, client: client, prev_batch: '1234', roomAccountData: {});
|
||||||
|
|
Loading…
Reference in a new issue