Skip to content

Commit

Permalink
Revert using display name in shared albums' name
Browse files Browse the repository at this point in the history
+ Improve rendering of cover and header of shared albums

Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed May 12, 2023
1 parent 2aa5818 commit 2144dd2
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 26 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ vendor

cypress/videos
cypress/snapshots
cypress/downloads
cypress/downloads

js/*hot-update.*
4 changes: 2 additions & 2 deletions js/photos-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-main.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/photos-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/photos-src_views_SharedAlbums_vue.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-src_views_SharedAlbums_vue.js.map

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions lib/Album/AlbumMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
use OCP\Files\IMimeTypeLoader;
use OCP\Security\ISecureRandom;
use OCP\IDBConnection;
use OCP\IGroup;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IGroupManager;
use OCP\IL10N;
Expand Down Expand Up @@ -350,7 +348,7 @@ public function getCollaborators(int $albumId): array {
$rows = $query->executeQuery()->fetchAll();

$collaborators = array_map(function (array $row) {
/** @var IUser|IGroup|null */
/** @var string|null */
$displayName = null;

switch ($row['collaborator_type']) {
Expand Down Expand Up @@ -541,7 +539,7 @@ public function getSharedAlbumsForCollaboratorWithFiles(string $collaboratorId,
// Suffix album name with the album owner to prevent duplicates.
// Not done for public link as it would like owner's uid.
if ($collaboratorType !== self::TYPE_LINK) {
$albumName = $row['album_name'].' ('.$this->userManager->get($row['album_user'])->getDisplayName().')';
$albumName = $row['album_name'].' ('.$row['album_user'].')';
}
$albumsById[$albumId] = new AlbumInfo($albumId, $row['album_user'], $albumName, $row['location'], (int)$row['created'], (int)$row['last_added_photo']);
}
Expand Down
38 changes: 35 additions & 3 deletions lib/Sabre/Album/SharedAlbumRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,35 @@

use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\Conflict;
use OCA\Photos\Album\AlbumMapper;
use OCA\Photos\Album\AlbumWithFiles;
use OCA\Photos\Service\UserConfigService;
use OCP\Files\IRootFolder;
use OCP\IUserManager;

class SharedAlbumRoot extends AlbumRoot {
private IUserManager $userManager;

public function __construct(
AlbumMapper $albumMapper,
AlbumWithFiles $album,
IRootFolder $rootFolder,
string $userId,
UserConfigService $userConfigService,
IUserManager $userManager
) {
parent::__construct(
$albumMapper,
$album,
$rootFolder,
$userId,
$userConfigService,
$userManager
);

$this->userManager = $userManager;
}

/**
* @return void
*/
Expand Down Expand Up @@ -55,11 +82,16 @@ protected function addFile(int $sourceId, string $ownerUID): bool {
}

/**
* Do not reveal collaborators for shared albums.
* Return only the owner, and do not reveal other collaborators.
*/
public function getCollaborators(): array {
/** @var array{array{'nc:collaborator': array{'id': string, 'label': string, 'type': int}}} */
return [];
return [[
'nc:collaborator' => [
'id' => $this->album->getAlbum()->getUserId(),
'label' => $this->userManager->get($this->album->getAlbum()->getUserId())->getDisplayName(),
'type' => 1,
],
]];
}

public function setCollaborators($collaborators): array {
Expand Down
2 changes: 1 addition & 1 deletion lib/Sabre/Album/SharedAlbumsHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getChildren(): array {
}

$this->children = array_map(function (AlbumWithFiles $album) {
return new SharedAlbumRoot($this->albumMapper, $album, $this->rootFolder, $this->userId, $this->userConfigService);
return new SharedAlbumRoot($this->albumMapper, $album, $this->rootFolder, $this->userId, $this->userConfigService, $this->userManager);
}, $albums);
}

Expand Down
18 changes: 15 additions & 3 deletions src/views/SharedAlbumContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@
:loading="loadingFiles"
:params="{ albumName }"
:path="'/' + albumName"
:title="albumName"
:title="albumOriginalName"
@refresh="fetchAlbumContent">
<!-- <UploadPicker :accept="allowedMimes"
:destination="folder.filename"
:multiple="true"
@uploaded="onUpload" /> -->

<div v-if="album.location !== ''" slot="subtitle" class="album__location">
<MapMarker />{{ album.location }}
<MapMarker />{{ album.location }} ⸱ {{ t('photos', 'Shared by') }}&nbsp;<NcUserBubble :display-name="album.collaborators[0].label" :user="album.collaborators[0].id" />
</div>
<template v-if="album !== undefined" slot="right">
<NcButton v-if="album.nbItems !== 0"
Expand Down Expand Up @@ -122,7 +123,7 @@ import Close from 'vue-material-design-icons/Close'
// import Download from 'vue-material-design-icons/Download'
// import DownloadMultiple from 'vue-material-design-icons/DownloadMultiple'
import { NcActions, NcActionButton, NcButton, NcModal, NcEmptyContent, NcActionSeparator, isMobile } from '@nextcloud/vue'
import { NcActions, NcActionButton, NcButton, NcModal, NcEmptyContent, NcActionSeparator, NcUserBubble, isMobile } from '@nextcloud/vue'
import { getCurrentUser } from '@nextcloud/auth'
import FetchSharedAlbumsMixin from '../mixins/FetchSharedAlbumsMixin.js'
Expand All @@ -136,6 +137,7 @@ import logger from '../services/logger.js'
import client from '../services/DavClient.js'
import DavRequest from '../services/DavRequest.js'
import { genFileInfo } from '../utils/fileUtils.js'
import { translate } from '@nextcloud/l10n'
export default {
name: 'SharedAlbumContent',
Expand All @@ -153,6 +155,7 @@ export default {
NcActionSeparator,
NcButton,
NcModal,
NcUserBubble,
CollectionContent,
// ActionDownload,
FilesPicker,
Expand Down Expand Up @@ -200,6 +203,13 @@ export default {
albumFileIds() {
return this.sharedAlbumsFiles[this.albumName] || []
},
/**
* @return {string} The album name without the userId between parentheses.
*/
albumOriginalName() {
return this.albumName.replace(new RegExp(`\\(${this.album.collaborators[0].id}\\)$`), '')
},
},
watch: {
Expand Down Expand Up @@ -285,6 +295,8 @@ export default {
await this.deleteSharedAlbum({ albumName: this.albumName })
this.$router.push('/sharedalbums')
},
t: translate,
},
}
</script>
Expand Down
22 changes: 20 additions & 2 deletions src/views/SharedAlbums.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
:alt-img="t('photos', 'Cover photo for shared album {albumName}.', { albumName: collection.basename })"
:cover-url="collection.lastPhoto | coverUrl">
<h2 class="album__name">
{{ collection.basename }}
{{ collection | albumOriginalName }}
</h2>

<div slot="subtitle" class="album__details">
{{ collection.date }} ⸱ {{ n('photos', '%n item', '%n photos and videos', collection.nbItems,) }}
<br>
{{ t('photos', 'Shared by') }}&nbsp;<NcUserBubble :display-name="collection.collaborators[0].label" :user="collection.collaborators[0].id" />
</div>
</CollectionCover>

Expand All @@ -55,12 +57,13 @@
import FolderMultipleImage from 'vue-material-design-icons/FolderMultipleImage'
import { generateUrl } from '@nextcloud/router'
import { NcEmptyContent } from '@nextcloud/vue'
import { NcEmptyContent, NcUserBubble } from '@nextcloud/vue'
import FetchSharedAlbumsMixin from '../mixins/FetchSharedAlbumsMixin.js'
import CollectionsList from '../components/Collection/CollectionsList.vue'
import CollectionCover from '../components/Collection/CollectionCover.vue'
import HeaderNavigation from '../components/HeaderNavigation.vue'
import { translate, translatePlural } from '@nextcloud/l10n'
export default {
name: 'SharedAlbums',
Expand All @@ -70,11 +73,13 @@ export default {
CollectionsList,
CollectionCover,
HeaderNavigation,
NcUserBubble,
},
filters: {
/**
* @param {string} lastPhoto The album's last photos.
* @return {string}
*/
coverUrl(lastPhoto) {
if (lastPhoto === -1) {
Expand All @@ -83,11 +88,24 @@ export default {
return generateUrl(`/apps/photos/api/v1/preview/${lastPhoto}?x=${512}&y=${512}`)
},
/**
* @param {import('../services/Albums.js').Album} album The album's full name, including the userid.
* @return {string} The album name without the userId between parentheses.
*/
albumOriginalName(album) {
return album.basename.replace(new RegExp(`\\(${album.collaborators[0].id}\\)$`), '')
},
},
mixins: [
FetchSharedAlbumsMixin,
],
methods: {
t: translate,
n: translatePlural,
},
}
</script>
<style lang="scss" scoped>
Expand Down

0 comments on commit 2144dd2

Please sign in to comment.