Skip to content

Commit

Permalink
timeline: show shared name
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <[email protected]>
Co-Authored-By: Jo Van Bulck <[email protected]>
  • Loading branch information
pulsejet and jovanbulck committed Jan 4, 2025
1 parent 41916ee commit eb7fa25
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/Controller/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ public function info(
$info['basename'] = $file->getName();
$info['uploadtime'] = $file->getUploadTime() ?: $file->getMTime();

// Get file owner name for shared files
if ($owner = $file->getOwner()) {
$info['owneruid'] = $owner->getUID();
$info['ownername'] = $owner->getDisplayName();
}

// Allow these ony for logged in users
if ($user = $this->userSession->getUser()) {
// Get the path of the file relative to current user
Expand Down
2 changes: 2 additions & 0 deletions lib/Db/TimelineQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IUserManager;

class TimelineQuery
{
Expand All @@ -33,6 +34,7 @@ class TimelineQuery
public function __construct(
protected IDBConnection $connection,
protected IRequest $request,
protected IUserManager $userManager,
) {}

public function allowEmptyRoot(bool $value = true): void
Expand Down
47 changes: 47 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 @@ -148,6 +149,10 @@ public function getDay(
// Filter for files in the timeline path
$query = $this->filterFilecache($query, null, $recursive, $archive, $hidden);

// SELECT storage ID to check if this photo is shared
$query->leftJoin('f', 'storages', 's', $query->expr()->eq('f.storage', 's.numeric_id'));
$query->selectAlias('s.id', 'storage_id');

// FETCH all photos in this day
$day = $this->executeQueryWithCTEs($query)->fetchAll();

Expand Down Expand Up @@ -345,6 +350,23 @@ private function postProcessDayPhoto(array &$row, bool $monthView = false): void
if ($monthView) {
$row['dayid'] = $this->dayIdToMonthId($row['dayid']);
}

// Convert storage_id to user display name
if ($storage = $row['storage_id'] ?? null) {
unset($row['storage_id']);

/** @var array<string,string> */
static $userMemo = [];
if ($user = $userMemo[$storage] ?? null) {
$row['shared_by'] = $user;
} elseif ($user = $this->storageIdToUserName($storage)) {
$row['shared_by'] = $userMemo[$storage] = $user;
}

if ('[self]' === $row['shared_by']) {
unset($row['shared_by']);
}
}
}

/**
Expand Down Expand Up @@ -382,4 +404,29 @@ private function dayIdToMonthId(int $dayId): int

return $memoize[$dayId] = strtotime(date('Ym', $dayId * 86400).'01') / 86400;
}

private function storageIdToUserName(string $storage): string
{
// Storage ID looks like "home::{uid}" or "local::{/path}" etc
$pos = strpos($storage, '::');
if (false === $pos) {
return '[unknown]';
}
$uid = substr($storage, $pos + 2);

// Check if self
if (Util::isLoggedIn() && $uid === Util::getUID()) {
return '[self]';
}

// If there are slashes, it's not a user (could be group folder)
if (str_contains($uid, '/')) {
return '[unknown]';
}

// Otherwise it *may* be a user
$user = $this->userManager->get($uid);

return $user ? $user->getDisplayName() : '[unknown]';
}
}
24 changes: 24 additions & 0 deletions src/components/Metadata.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
<div class="description" v-if="description">{{ description }}</div>
</div>

<div v-if="isShared" class="shared-by">
<div class="section-title">{{ t('memories', 'Shared By') }}</div>
<div class="top-field">
<NcAvatar key="uid" :user="baseInfo.owneruid" :showUserStatus="false" :size="24" />
<span class="name">{{ baseInfo.ownername }}</span>
</div>
</div>

<div v-if="people.length" class="people">
<div class="section-title">{{ t('memories', 'People') }}</div>
<div class="container" v-for="face of people" :key="face.cluster_id">
Expand Down Expand Up @@ -71,6 +79,7 @@ import type { Component } from 'vue';
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js';
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js';
const NcAvatar = () => import('@nextcloud/vue/dist/Components/NcAvatar.js');
import axios from '@nextcloud/axios';
import { getCanonicalLocale } from '@nextcloud/l10n';
Expand Down Expand Up @@ -107,6 +116,7 @@ export default defineComponent({
components: {
NcActions,
NcActionButton,
NcAvatar,
AlbumsList,
Cluster,
EditIcon,
Expand Down Expand Up @@ -388,6 +398,10 @@ export default defineComponent({
return clusters?.recognize ?? [];
},
isShared(): boolean {
return !!this.baseInfo.owneruid && this.baseInfo.owneruid !== utils.uid;
},
},
methods: {
Expand Down Expand Up @@ -507,6 +521,16 @@ export default defineComponent({
}
}
.shared-by {
> .top-field {
margin-top: 6px;
margin-bottom: 10px;
}
.name {
margin-left: 8px;
}
}
.people {
margin-bottom: 6px;
> .section-title {
Expand Down
29 changes: 28 additions & 1 deletion src/components/frame/Photo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@
</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">
<span class="shared-by" v-if="sharedBy">{{ sharedBy }}</span>
</div>

<div
class="img-outer fill-block"
:class="{ 'memories-livephoto': data.liveid }"
Expand Down Expand Up @@ -203,6 +207,15 @@ export default defineComponent({
isRaw(): boolean {
return !!this.data.stackraw || this.data.mimetype === this.c.MIME_RAW;
},
sharedBy(): string | null {
if (this.data.shared_by == '[unknown]') {
return this.t('memories', 'Shared');
} else if (this.data.shared_by) {
return this.data.shared_by;
}
return null;
},
},
methods: {
Expand Down Expand Up @@ -430,6 +443,20 @@ $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);
}
}
> .shared-by {
font-size: 0.75em;
line-height: 0.75em;
font-weight: 400;
}
> .video {
display: flex;
line-height: 22px; // force text height to match
Expand Down
5 changes: 5 additions & 0 deletions src/typings/data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ declare module '@typings' {
h?: number;
/** Live Photo identifier */
liveid?: string;
/** File owner display name */
shared_by?: string;

/** Grid display width px */
dispW?: number;
Expand Down Expand Up @@ -114,6 +116,9 @@ declare module '@typings' {
size: number;
uploadtime: number;

owneruid: string;
ownername: string;

filename?: string;
address?: string;
tags?: { [id: string]: string };
Expand Down

0 comments on commit eb7fa25

Please sign in to comment.