Enhance message acknowledgment handling in EncryptionChannelReceive with improved error management

https://github.com/nosial/Socialbox-PHP/issues/16
This commit is contained in:
netkas 2025-03-07 19:32:03 -05:00
parent 7165734aef
commit 0ff277ed4c

View file

@ -76,18 +76,30 @@
try
{
$messages = EncryptionChannelManager::receiveData(
$rpcRequest->getParameter('channel_uuid'), $encryptionChannel->determineRecipient($requestingPeer->getAddress(), true)
);
$messageUuids = array_map(fn($message) => $message->getUuid(), $messages);
}
catch(DatabaseOperationException $e)
{
throw new StandardRpcException('Failed to retrieve the messages', StandardError::INTERNAL_SERVER_ERROR, $e);
}
if($acknowledge)
{
$messageUuids = array_map(fn($message) => $message->getUuid(), $messages);
try
{
EncryptionChannelManager::acknowledgeMessagesBatch(
channelUuid: $rpcRequest->getParameter('channel_uuid'),
messageUuids: $messageUuids,
);
}
catch (DatabaseOperationException $e)
{
throw new StandardRpcException('Failed to acknowledge the messages locally', StandardError::INTERNAL_SERVER_ERROR, $e);
}
$externalPeer = $encryptionChannel->getExternalPeer();
if($externalPeer !== null)
@ -121,11 +133,6 @@
}
}
}
}
catch(DatabaseOperationException $e)
{
throw new StandardRpcException('Failed to retrieve the messages', StandardError::INTERNAL_SERVER_ERROR, $e);
}
return $rpcRequest->produceResponse(array_map(fn($message) => $message->toStandard(), $messages));
}