Skip to content

Commit cf6a674

Browse files
committed
Polish. Use try-catch-finally. Some restructure
Signed-off-by: Andrey Borysenko <[email protected]>
1 parent df4298d commit cf6a674

File tree

5 files changed

+132
-184
lines changed

5 files changed

+132
-184
lines changed

lib/Reference/ProfilePickerReferenceProvider.php

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
namespace OCA\Contacts\Reference;
2828

29+
2930
use OC\Collaboration\Reference\LinkReferenceProvider;
3031
use OCP\Collaboration\Reference\ADiscoverableReferenceProvider;
3132
use OCP\Collaboration\Reference\Reference;
@@ -39,10 +40,7 @@
3940
use OCP\IUserManager;
4041

4142
class ProfilePickerReferenceProvider extends ADiscoverableReferenceProvider {
42-
43-
// private const RICH_OBJECT_TYPE = Application::APP_ID . '_profile_picker';
4443
private const RICH_OBJECT_TYPE = 'users_picker_profile';
45-
4644
private ?string $userId;
4745
private IL10N $l10n;
4846
private IURLGenerator $urlGenerator;
@@ -105,52 +103,53 @@ public function matchReference(string $referenceText): bool {
105103
* @inheritDoc
106104
*/
107105
public function resolveReference(string $referenceText): ?IReference {
108-
if ($this->matchReference($referenceText)) {
109-
$userId = $this->getObjectId($referenceText);
110-
$user = $this->userManager->get($userId);
111-
if ($user !== null) {
112-
$reference = new Reference($referenceText);
113-
114-
$userDisplayName = $user->getDisplayName();
115-
$userEmail = $user->getEMailAddress();
116-
$userAvatarUrl = $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $userId, 'size' => '64']);
117-
118-
$bio = $this->accountManager->getAccount($user)->getProperty(IAccountManager::PROPERTY_BIOGRAPHY);
119-
$bio = $bio->getScope() !== IAccountManager::SCOPE_PRIVATE ? $bio->getValue() : null;
120-
$headline = $this->accountManager->getAccount($user)->getProperty(IAccountManager::PROPERTY_HEADLINE);
121-
$location = $this->accountManager->getAccount($user)->getProperty(IAccountManager::PROPERTY_ADDRESS);
122-
$website = $this->accountManager->getAccount($user)->getProperty(IAccountManager::PROPERTY_WEBSITE);
123-
$organisation = $this->accountManager->getAccount($user)->getProperty(IAccountManager::PROPERTY_ORGANISATION);
124-
$role = $this->accountManager->getAccount($user)->getProperty(IAccountManager::PROPERTY_ROLE);
125-
126-
// for clients who can't render the reference widgets
127-
$reference->setTitle($userDisplayName);
128-
$reference->setDescription($userEmail ?? $userDisplayName);
129-
$reference->setImageUrl($userAvatarUrl);
130-
131-
// for the Vue reference widget
132-
$reference->setRichObject(
133-
self::RICH_OBJECT_TYPE,
134-
[
135-
'user_id' => $userId,
136-
'title' => $userDisplayName,
137-
'subline' => $userEmail ?? $userDisplayName,
138-
'email' => $userEmail,
139-
'bio' => isset($bio) && $bio !== '' ? substr_replace($bio, '...', 80, strlen($bio)) : null,
140-
'headline' => $headline->getScope() !== IAccountManager::SCOPE_PRIVATE ? $headline->getValue() : null,
141-
'location' => $location->getScope() !== IAccountManager::SCOPE_PRIVATE ? $location->getValue() : null,
142-
'location_url' => $location->getScope() !== IAccountManager::SCOPE_PRIVATE ? $this->getOpenStreetLocationUrl($location->getValue()) : null,
143-
'website' => $website->getScope() !== IAccountManager::SCOPE_PRIVATE ? $website->getValue() : null,
144-
'organisation' => $organisation->getScope() !== IAccountManager::SCOPE_PRIVATE ? $organisation->getValue() : null,
145-
'role' => $role->getScope() !== IAccountManager::SCOPE_PRIVATE ? $role->getValue() : null,
146-
'url' => $referenceText,
147-
]
148-
);
149-
return $reference;
150-
}
151-
return $this->linkReferenceProvider->resolveReference($referenceText);
106+
if (!$this->matchReference($referenceText)) {
107+
return null;
152108
}
153-
return null;
109+
110+
$userId = $this->getObjectId($referenceText);
111+
$user = $this->userManager->get($userId);
112+
if ($user !== null) {
113+
$reference = new Reference($referenceText);
114+
115+
$userDisplayName = $user->getDisplayName();
116+
$userEmail = $user->getEMailAddress();
117+
$userAvatarUrl = $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $userId, 'size' => '64']);
118+
119+
$bio = $this->accountManager->getAccount($user)->getProperty(IAccountManager::PROPERTY_BIOGRAPHY);
120+
$bio = $bio->getScope() !== IAccountManager::SCOPE_PRIVATE ? $bio->getValue() : null;
121+
$headline = $this->accountManager->getAccount($user)->getProperty(IAccountManager::PROPERTY_HEADLINE);
122+
$location = $this->accountManager->getAccount($user)->getProperty(IAccountManager::PROPERTY_ADDRESS);
123+
$website = $this->accountManager->getAccount($user)->getProperty(IAccountManager::PROPERTY_WEBSITE);
124+
$organisation = $this->accountManager->getAccount($user)->getProperty(IAccountManager::PROPERTY_ORGANISATION);
125+
$role = $this->accountManager->getAccount($user)->getProperty(IAccountManager::PROPERTY_ROLE);
126+
127+
// for clients who can't render the reference widgets
128+
$reference->setTitle($userDisplayName);
129+
$reference->setDescription($userEmail ?? $userDisplayName);
130+
$reference->setImageUrl($userAvatarUrl);
131+
132+
// for the Vue reference widget
133+
$reference->setRichObject(
134+
self::RICH_OBJECT_TYPE,
135+
[
136+
'user_id' => $userId,
137+
'title' => $userDisplayName,
138+
'subline' => $userEmail ?? $userDisplayName,
139+
'email' => $userEmail,
140+
'bio' => isset($bio) && $bio !== '' ? substr_replace($bio, '...', 80, strlen($bio)) : null,
141+
'headline' => $headline->getScope() !== IAccountManager::SCOPE_PRIVATE ? $headline->getValue() : null,
142+
'location' => $location->getScope() !== IAccountManager::SCOPE_PRIVATE ? $location->getValue() : null,
143+
'location_url' => $location->getScope() !== IAccountManager::SCOPE_PRIVATE ? $this->getOpenStreetLocationUrl($location->getValue()) : null,
144+
'website' => $website->getScope() !== IAccountManager::SCOPE_PRIVATE ? $website->getValue() : null,
145+
'organisation' => $organisation->getScope() !== IAccountManager::SCOPE_PRIVATE ? $organisation->getValue() : null,
146+
'role' => $role->getScope() !== IAccountManager::SCOPE_PRIVATE ? $role->getValue() : null,
147+
'url' => $referenceText,
148+
]
149+
);
150+
return $reference;
151+
}
152+
return $this->linkReferenceProvider->resolveReference($referenceText);
154153
}
155154

156155
private function getObjectId(string $url): ?string {
@@ -169,7 +168,7 @@ private function getObjectId(string $url): ?string {
169168
return null;
170169
}
171170

172-
private function getOpenStreetLocationUrl($location) {
171+
private function getOpenStreetLocationUrl($location): string {
173172
return 'https://www.openstreetmap.org/search?query=' . urlencode($location);
174173
}
175174

src/components/ProfilePicker/ProfilePickerReferenceWidget.vue

Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,19 @@
1-
<!--
2-
- @copyright Copyright (c) 2023 Andrey Borysenko <andrey18106x@gmail.com>
3-
-
4-
- @author 2023 Andrey Borysenko <[email protected]>
5-
-
6-
- @license AGPL-3.0-or-later
7-
-
8-
- This program is free software: you can redistribute it and/or modify
9-
- it under the terms of the GNU Affero General Public License as
10-
- published by the Free Software Foundation, either version 3 of the
11-
- License, or (at your option) any later version.
12-
-
13-
- This program is distributed in the hope that it will be useful,
14-
- but WITHOUT ANY WARRANTY; without even the implied warranty of
15-
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16-
- GNU Affero General Public License for more details.
17-
-
18-
- You should have received a copy of the GNU Affero General Public License
19-
- along with this program. If not, see <http://www.gnu.org/licenses/>.
20-
-
21-
-->
22-
231
<template>
24-
<div class="profile_picker-referece">
25-
<div class="profile_picker-wrapper">
26-
<div class="profile-card-header">
27-
<NcAvatar :user="richObject.user_id" :size="48" class="profile-avatar" />
28-
<div class="profile-title">
2+
<div class="profile-reference">
3+
<div class="profile-reference__wrapper">
4+
<div class="profile-card__header">
5+
<NcAvatar :user="richObject.user_id" :size="48" class="profile-card__avatar" />
6+
<div class="profile-card__title">
297
<a :href="richObject.url" target="_blank">
30-
<UserIcon :size="20" />
8+
<Account :size="20" />
319
<strong>
3210
{{ richObject.email !== null ? richObject.title + ' - ' + richObject.email : richObject.title }}
3311
</strong>
3412
</a>
3513
</div>
3614
</div>
3715
<div class="profile-content">
38-
<p class="profile-subline">
16+
<p class="profile-content__subline">
3917
<span v-if="richObject.headline" class="headline">
4018
{{ richObject.headline }}
4119
</span>
@@ -73,23 +51,23 @@
7351
<script>
7452
import NcAvatar from '@nextcloud/vue/dist/Components/NcAvatar.js'
7553
54+
import Account from 'vue-material-design-icons/Account.vue'
7655
import MapMarker from 'vue-material-design-icons/MapMarker.vue'
77-
import TextAccount from 'vue-material-design-icons/TextAccount.vue'
78-
import UserIcon from './icons/UserIcon.vue'
79-
import Domain from 'vue-material-design-icons/Domain.vue'
8056
import Web from 'vue-material-design-icons/Web.vue'
57+
import Domain from 'vue-material-design-icons/Domain.vue'
8158
import Handshake from 'vue-material-design-icons/Handshake.vue'
59+
import TextAccount from 'vue-material-design-icons/TextAccount.vue'
8260
8361
export default {
8462
name: 'ProfilePickerReferenceWidget',
8563
components: {
8664
NcAvatar,
65+
Account,
8766
MapMarker,
88-
TextAccount,
89-
UserIcon,
90-
Domain,
9167
Web,
68+
Domain,
9269
Handshake,
70+
TextAccount,
9371
},
9472
props: {
9573
richObjectType: {
@@ -109,44 +87,44 @@ export default {
10987
</script>
11088

11189
<style scoped lang="scss">
112-
.profile_picker-referece {
90+
.profile-reference {
11391
width: 100%;
11492
white-space: normal;
11593
display: flex;
11694
117-
.profile_picker-wrapper {
95+
.profile-reference__wrapper {
11896
width: 100%;
11997
display: flex;
12098
align-items: center;
12199
flex-direction: column;
122100
123-
.profile-card-header {
101+
.profile-card__header {
124102
width: 100%;
125103
min-height: 70px;
126104
background-color: var(--color-primary);
127105
background-image: var(--gradient-primary-background);
128106
position: relative;
107+
}
108+
109+
.profile-card__avatar {
110+
position: relative;
111+
bottom: -50%;
112+
left: 10px;
113+
}
129114
130-
.profile-avatar {
131-
position: relative;
132-
bottom: -50%;
133-
left: 10px;
115+
.profile-card__title {
116+
display: flex;
117+
position: relative;
118+
bottom: 5px;
119+
left: 70px;
120+
121+
& span {
122+
margin-right: 5px;
134123
}
135124
136-
.profile-title {
125+
& a {
137126
display: flex;
138-
position: relative;
139-
bottom: 5px;
140-
left: 70px;
141-
142-
& span {
143-
margin-right: 5px;
144-
}
145-
146-
& a {
147-
display: flex;
148-
color: #fff;
149-
}
127+
color: #fff;
150128
}
151129
}
152130
@@ -164,7 +142,7 @@ export default {
164142
padding-left: 5px;
165143
}
166144
167-
.profile-subline {
145+
.profile-content__subline {
168146
padding: 0 0 0 10px;
169147
170148
& span.material-design-icon {

0 commit comments

Comments
 (0)