Skip to content

Commit 52955da

Browse files
committed
feat: Added blurhash to image metadata
Signed-off-by: skalidindi53 <s.teja2004@gmail.com>
1 parent fb4e297 commit 52955da

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed

lib/Chat/Parser/SystemMessage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,10 @@ protected function getFileFromShare(Room $room, ?Participant $participant, strin
817817
$data['width'] = (string) $sizeMetadata['width'];
818818
$data['height'] = (string) $sizeMetadata['height'];
819819
}
820+
821+
if (isset($sizeMetadata['blurhash'])) {
822+
$data['blurhash'] = $sizeMetadata['blurhash'];
823+
}
820824
} catch (FilesMetadataNotFoundException) {
821825
}
822826
}

lib/ResponseDefinitions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
* permissions?: string,
9292
* width?: string,
9393
* height?: string,
94+
* blurhash?: string,
9495
* }
9596
*
9697
* @psalm-type TalkBaseMessage = array{

lib/Share/Helper/FilesMetadataCache.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use OCP\FilesMetadata\Model\IFilesMetadata;
1616

1717
class FilesMetadataCache {
18-
/** @var array<int, ?array{width: int, height: int}> */
18+
/** @var array<int, ?array{width: int, height: int, blurhash?: string}> */
1919
protected array $filesSizeData = [];
2020

2121
public function __construct(
@@ -41,7 +41,7 @@ public function preloadMetadata(array $fileIds): void {
4141
/**
4242
* @param int $fileId
4343
* @return array
44-
* @psalm-return array{width: int, height: int}
44+
* @psalm-return array{width: int, height: int, blurhash?: string}
4545
* @throws FilesMetadataNotFoundException
4646
*/
4747
public function getMetadataPhotosSizeForFileId(int $fileId): array {
@@ -75,6 +75,12 @@ protected function cachePhotosSize(int $fileId, IFilesMetadata $metadata): void
7575
'width' => $sizeMetadata['width'],
7676
'height' => $sizeMetadata['height'],
7777
];
78+
79+
// Retrieve Blurhash from metadata (if present)
80+
if ($metadata->hasKey('blurhash')) {
81+
$dimensions['blurhash'] = $metadata->getString('blurhash');
82+
}
83+
7884
$this->filesSizeData[$fileId] = $dimensions;
7985
} else {
8086
$this->filesSizeData[$fileId] = null;

tests/php/Chat/Parser/SystemMessageTest.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,83 @@ public function testGetFileFromShareForGuest(): void {
658658
], self::invokePrivate($parser, 'getFileFromShare', [$room, $participant, '23']));
659659
}
660660

661+
public function testGetFileFromShareForGuestWithBlurhash(): void {
662+
$room = $this->createMock(Room::class);
663+
$node = $this->createMock(Node::class);
664+
$node->expects($this->once())
665+
->method('getId')
666+
->willReturn(54);
667+
$node->expects($this->once())
668+
->method('getName')
669+
->willReturn('name');
670+
$node->expects($this->atLeastOnce())
671+
->method('getMimeType')
672+
->willReturn('image/png');
673+
$node->expects($this->once())
674+
->method('getSize')
675+
->willReturn(65530);
676+
$node->expects($this->once())
677+
->method('getEtag')
678+
->willReturn(md5('etag'));
679+
$node->expects($this->once())
680+
->method('getPermissions')
681+
->willReturn(27);
682+
683+
$share = $this->createMock(IShare::class);
684+
$share->expects($this->once())
685+
->method('getNode')
686+
->willReturn($node);
687+
$share->expects($this->once())
688+
->method('getToken')
689+
->willReturn('token');
690+
691+
$this->shareProvider->expects($this->once())
692+
->method('getShareById')
693+
->with('23')
694+
->willReturn($share);
695+
696+
$this->url->expects($this->once())
697+
->method('linkToRouteAbsolute')
698+
->with('files_sharing.sharecontroller.showShare', [
699+
'token' => 'token',
700+
])
701+
->willReturn('absolute-link');
702+
703+
$this->previewManager->expects($this->once())
704+
->method('isAvailable')
705+
->with($node)
706+
->willReturn(true);
707+
708+
$this->filesMetadataCache->expects($this->once())
709+
->method('getMetadataPhotosSizeForFileId')
710+
->with(54)
711+
->willReturn([
712+
'width' => 1234,
713+
'height' => 4567,
714+
'blurhash' => 'LEHV9uae2yk8pyo0adR*.7kCMdnj'
715+
]);
716+
717+
$participant = $this->createMock(Participant::class);
718+
719+
$parser = $this->getParser();
720+
721+
$this->assertSame([
722+
'type' => 'file',
723+
'id' => '54',
724+
'name' => 'name',
725+
'size' => '65530',
726+
'path' => 'name',
727+
'link' => 'absolute-link',
728+
'etag' => '1872ade88f3013edeb33decd74a4f947',
729+
'permissions' => '27',
730+
'mimetype' => 'image/png',
731+
'preview-available' => 'yes',
732+
'width' => '1234',
733+
'height' => '4567',
734+
'blurhash' => 'LEHV9uae2yk8pyo0adR*.7kCMdnj',
735+
], self::invokePrivate($parser, 'getFileFromShare', [$room, $participant, '23']));
736+
}
737+
661738
public function testGetFileFromShareForOwner(): void {
662739
$room = $this->createMock(Room::class);
663740
$node = $this->createMock(Node::class);

0 commit comments

Comments
 (0)