Skip to content

Commit

Permalink
feat: Add username label on shared photos
Browse files Browse the repository at this point in the history
Fixes pulsejet#955

Signed-off-by: Jo Van Bulck <[email protected]>
  • Loading branch information
jovanbulck committed Oct 27, 2024
1 parent a773471 commit 8b7c31b
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/Db/TimelineQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TimelineQuery
'f.etag', 'f.name AS basename',
'f.size', 'm.epoch', // auid
'mimetypes.mimetype',
'm.uid',
];

protected ?TimelineRoot $_root = null; // cache
Expand Down
5 changes: 5 additions & 0 deletions lib/Db/TimelineQueryDays.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OCA\Memories\ClustersBackend;
use OCA\Memories\Exif;
use OCA\Memories\Settings\SystemConfig;
use OCA\Memories\Util;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;

Expand Down Expand Up @@ -315,6 +316,10 @@ private function postProcessDayPhoto(array &$row, bool $monthView = false): void
unset($row['liveid']);
}

if ($row['uid'] === Util::getUID()) {
unset($row['uid']);
}

// Favorite field, may not be present
if ($row['categoryid'] ?? null) {
$row['isfavorite'] = 1;
Expand Down
2 changes: 2 additions & 0 deletions lib/Db/TimelineWrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function processFile(
// Get parameters
$mtime = $file->getMtime();
$fileId = $file->getId();
$uid = $file->getOwner()?->getUID();
$isvideo = Index::isVideo($file);

// Get previous row
Expand Down Expand Up @@ -172,6 +173,7 @@ public function processFile(
'orphan' => $query->createNamedParameter(false, IQueryBuilder::PARAM_BOOL),
'buid' => $query->createNamedParameter($buid, IQueryBuilder::PARAM_STR),
'parent' => $query->createNamedParameter($file->getParent()->getId(), IQueryBuilder::PARAM_INT),
'uid' => $query->createNamedParameter($uid, IQueryBuilder::PARAM_STR),
];

// There is no easy way to UPSERT in standard SQL
Expand Down
120 changes: 120 additions & 0 deletions lib/Migration/Version800001Date20241026171056.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Varun Patil <radialapps@gmail.com>
* @author Varun Patil <radialapps@gmail.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace OCA\Memories\Migration;

use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* FIXME Auto-generated migration step: Please modify to your needs!
*/
class Version800001Date20241026171056 extends SimpleMigrationStep
{
public function __construct(private IDBConnection $dbc) {}

/**
* @param \Closure(): ISchemaWrapper $schemaClosure
*/
public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void {}

/**
* @param \Closure(): ISchemaWrapper $schemaClosure
*/
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options): ?ISchemaWrapper
{
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if (!$schema->hasTable('memories')) {
throw new \Exception('Memories table does not exist');
}

$table = $schema->getTable('memories');

if (!$table->hasColumn('uid')) {
$table->addColumn('uid', 'string', [
'notnull' => false,
'length' => 64,
]);
}

return $schema;
}

/**
* @param \Closure(): ISchemaWrapper $schemaClosure
*/
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void
{
// create database triggers; this will never throw
\OCA\Memories\Db\AddMissingIndices::createFilecacheTriggers($output);

// migrate uid values from filecache
try {
$output->info('Migrating values for uid from filecache');

$platform = $this->dbc->getDatabasePlatform();

// copy existing parent values from filecache
if (preg_match('/mysql|mariadb/i', $platform::class)) {
$this->dbc->executeQuery(
'UPDATE *PREFIX*memories AS m
JOIN *PREFIX*filecache AS f ON f.fileid = m.fileid
JOIN *PREFIX*storages AS s ON f.storage = s.numeric_id
SET m.uid = SUBSTRING_INDEX(s.id, \'::\', -1)
WHERE s.id LIKE \'home::%\'
',
);
} elseif (preg_match('/postgres/i', $platform::class)) {
$this->dbc->executeQuery(
'UPDATE *PREFIX*memories AS m
SET uid = split_part(s.id, \'::\', 2)
FROM *PREFIX*filecache AS f
JOIN *PREFIX*storages AS s ON f.storage = s.numeric_id
WHERE f.fileid = m.fileid
AND s.id LIKE \'home::%\'
',
);
} elseif (preg_match('/sqlite/i', $platform::class)) {
$this->dbc->executeQuery(
'UPDATE memories AS m
SET uid = SUBSTR(s.id, INSTR(s.id, \'::\') + 2)
FROM filecache AS f
JOIN storages AS s ON f.storage = s.numeric_id
WHERE f.fileid = m.fileid
AND s.id LIKE \'home::%\'
',
);
} else {
throw new \Exception('Unsupported '.$platform::class);
}

$output->info('Values for uid migrated successfully');
} catch (\Exception $e) {
$output->warning('Failed to copy uid values from fileid: '.$e->getMessage());
$output->warning('Please run occ memories:index -f');
}
}
}
26 changes: 25 additions & 1 deletion src/components/frame/Photo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@
</div>
</div>

<div class="flag bottom-left">
<div class="flag bottom-right">
<StarIcon :size="22" v-if="data.flag & c.FLAG_IS_FAVORITE" />
<LocalIcon :size="22" v-if="data.flag & c.FLAG_IS_LOCAL" />
</div>

<div class="flag bottom-left">
<AccountMultipleIcon :size="22" v-if="data.uid" />
<span class="username" v-if="data.uid">{{ owner }}</span>
</div>

<div
class="img-outer fill-block"
:class="{ 'memories-livephoto': data.liveid }"
Expand Down Expand Up @@ -81,6 +86,7 @@ import StarIcon from 'vue-material-design-icons/Star.vue';
import VideoIcon from 'vue-material-design-icons/PlayCircleOutline.vue';
import LocalIcon from 'vue-material-design-icons/CloudOff.vue';
import RawIcon from 'vue-material-design-icons/Raw.vue';
import AccountMultipleIcon from 'vue-material-design-icons/AccountMultiple.vue';
import type { IDay, IPhoto } from '@typings';
import type XImg from '@components/XImg.vue';
Expand All @@ -96,6 +102,7 @@ export default defineComponent({
StarIcon,
LocalIcon,
RawIcon,
AccountMultipleIcon,
},
props: {
Expand Down Expand Up @@ -173,6 +180,10 @@ export default defineComponent({
return null;
},
owner(): string | null {
return this.data.uid || null;
},
videoUrl(): string | null {
if (this.data.liveid) {
return utils.getLivePhotoVideoUrl(this.data, true);
Expand Down Expand Up @@ -414,6 +425,19 @@ $icon-size: $icon-half-size * 2;
}
}
&.bottom-right {
bottom: var(--icon-dist);
right: var(--icon-dist);
.p-outer.selected > & {
transform: translate($icon-size, -$icon-size);
}
}
> .username {
font-size: 0.75em;
margin-left: 3px;
}
> .video {
display: flex;
line-height: 22px; // force text height to match
Expand Down
2 changes: 2 additions & 0 deletions src/typings/data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ declare module '@typings' {

/** Stacked RAW photos */
stackraw?: IPhoto[];

uid?: string;
};

export interface IImageInfo {
Expand Down

0 comments on commit 8b7c31b

Please sign in to comment.