feat(service): React to messages of type error

This commit is contained in:
PapaTutuWawa 2022-11-22 22:21:05 +01:00
parent f0c6713d76
commit d59a37f185

View File

@ -777,12 +777,44 @@ class XmppService {
&& await GetIt.I.get<RosterService>().isInRoster(conversationJid); && await GetIt.I.get<RosterService>().isInRoster(conversationJid);
} }
/// Handles receiving a message stanza of type error.
Future<void> _handleErrorMessage(MessageEvent event) async {
final ms = GetIt.I.get<MessageService>();
final msg = await ms.getMessageByStanzaId(
event.fromJid.toBare().toString(),
event.sid,
);
if (msg == null) {
_log.warning('Received error for message ${event.sid} we cannot find');
return;
}
// TODO(PapaTutuWawa): Figure out the error reason
var error = unspecifiedError;
final newMsg = await ms.updateMessage(
msg.id,
errorType: error,
);
// TODO(PapaTutuWawa): Show a notification for certain error types, i.e. those
// that mean that the message could not be delivered.
sendEvent(MessageUpdatedEvent(message: newMsg));
}
Future<void> _onMessage(MessageEvent event, { dynamic extra }) async { Future<void> _onMessage(MessageEvent event, { dynamic extra }) async {
// The jid this message event is meant for // The jid this message event is meant for
final conversationJid = event.isCarbon final conversationJid = event.isCarbon
? event.toJid.toBare().toString() ? event.toJid.toBare().toString()
: event.fromJid.toBare().toString(); : event.fromJid.toBare().toString();
if (event.type == 'error') {
await _handleErrorMessage(event);
_log.finest('Processed error message. Ending event processing here.');
return;
}
// Process the chat state update. Can also be attached to other messages // Process the chat state update. Can also be attached to other messages
if (event.chatState != null) await _onChatState(event.chatState!, conversationJid); if (event.chatState != null) await _onChatState(event.chatState!, conversationJid);