Skip to content

Commit

Permalink
Post review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln committed Jun 18, 2024
1 parent 922b768 commit 43c51a1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
21 changes: 11 additions & 10 deletions examples/FileSharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@
$pubnub = new PubNub($config);

// Sending file
// $fileHandle = fopen(__DIR__ . DIRECTORY_SEPARATOR . $fileName, "r");
// $sendFileResult = $pubnub->sendFile()
// ->channel($channelName)
// ->fileName($fileName)
// ->message("Hello from PHP SDK")
// ->fileHandle($fileHandle)
// ->sync();
$fileHandle = fopen(__DIR__ . DIRECTORY_SEPARATOR . $fileName, "r");
$sendFileResult = $pubnub->sendFile()
->channel($channelName)
->fileName($fileName)
->message("Hello from PHP SDK")
->fileHandle($fileHandle)
->sync();

// fclose($fileHandle);
fclose($fileHandle);

// Listing files in the channel
$channelFiles = $pubnub->listFiles()->channel($channelName)->sync();
if ($channelFiles->getCount() > 0) {
print("There are {$channelFiles->getCount()} files in the channel {$channelName}\n");
$fileCount = $channelFiles->getCount();
if ($fileCount > 0) {
print("There are {$fileCount} files in the channel {$channelName}\n");
foreach ($channelFiles->getFiles() as $idx => $file) {
print("File[{$idx}]: {$file->getName()} with ID: {$file->getId()},"
. "size {$file->getSize()}, created at: {$file->getCreationTime()}\n");
Expand Down
10 changes: 5 additions & 5 deletions src/PubNub/Endpoints/FileSharing/PublishFileMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@ protected function buildPath()
public function encryptMessage($message)
{
$crypto = $this->pubnub->getCryptoSafe();
$message = PubNubUtil::writeValueAsString($message);
$messageString = PubNubUtil::writeValueAsString($message);
if ($crypto) {
return $crypto->encrypt($message);
return $crypto->encrypt($messageString);
}
return $message;
return $messageString;
}

protected function buildMessage()
{
$message = [
$messageData = [
"message" => $this->message,
"file" => [
"id" => $this->fileId,
"name" => $this->fileName
]
];

return $this->encryptMessage($message);
return $this->encryptMessage($messageData);
}

protected function customParams()
Expand Down
6 changes: 3 additions & 3 deletions src/PubNub/Endpoints/FileSharing/SendFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ public function sync()
if (isset($this->meta)) {
$publishRequest->meta($this->meta);
}
if (isset($this->meta)) {
if (isset($this->message)) {
$publishRequest->message($this->message);
}
if (isset($this->meta)) {
if (isset($this->shouldStore)) {
$publishRequest->shouldStore($this->shouldStore);
}
if (isset($this->meta)) {
if (isset($this->ttl)) {
$publishRequest->ttl($this->ttl);
}

Expand Down

0 comments on commit 43c51a1

Please sign in to comment.