Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/user_status/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@
<background-jobs>
<job>OCA\UserStatus\BackgroundJob\ClearOldStatusesBackgroundJob</job>
</background-jobs>
<contactsmenu>
<provider>OCA\UserStatus\ContactsMenu\StatusProvider</provider>
</contactsmenu>
</info>
1 change: 1 addition & 0 deletions apps/user_status/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'OCA\\UserStatus\\Capabilities' => $baseDir . '/../lib/Capabilities.php',
'OCA\\UserStatus\\Connector\\UserStatus' => $baseDir . '/../lib/Connector/UserStatus.php',
'OCA\\UserStatus\\Connector\\UserStatusProvider' => $baseDir . '/../lib/Connector/UserStatusProvider.php',
'OCA\\UserStatus\\ContactsMenu\\StatusProvider' => $baseDir . '/../lib/ContactsMenu/StatusProvider.php',
'OCA\\UserStatus\\Controller\\HeartbeatController' => $baseDir . '/../lib/Controller/HeartbeatController.php',
'OCA\\UserStatus\\Controller\\PredefinedStatusController' => $baseDir . '/../lib/Controller/PredefinedStatusController.php',
'OCA\\UserStatus\\Controller\\StatusesController' => $baseDir . '/../lib/Controller/StatusesController.php',
Expand Down
1 change: 1 addition & 0 deletions apps/user_status/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ComposerStaticInitUserStatus
'OCA\\UserStatus\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php',
'OCA\\UserStatus\\Connector\\UserStatus' => __DIR__ . '/..' . '/../lib/Connector/UserStatus.php',
'OCA\\UserStatus\\Connector\\UserStatusProvider' => __DIR__ . '/..' . '/../lib/Connector/UserStatusProvider.php',
'OCA\\UserStatus\\ContactsMenu\\StatusProvider' => __DIR__ . '/..' . '/../lib/ContactsMenu/StatusProvider.php',
'OCA\\UserStatus\\Controller\\HeartbeatController' => __DIR__ . '/..' . '/../lib/Controller/HeartbeatController.php',
'OCA\\UserStatus\\Controller\\PredefinedStatusController' => __DIR__ . '/..' . '/../lib/Controller/PredefinedStatusController.php',
'OCA\\UserStatus\\Controller\\StatusesController' => __DIR__ . '/..' . '/../lib/Controller/StatusesController.php',
Expand Down
65 changes: 65 additions & 0 deletions apps/user_status/lib/ContactsMenu/StatusProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

/*
* @copyright 2023 Christoph Wurst <[email protected]>
*
* @author 2023 Christoph Wurst <[email protected]>
*
* @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\UserStatus\ContactsMenu;

use OCA\UserStatus\Db\UserStatus;
use OCA\UserStatus\Service\StatusService;
use OCP\Contacts\ContactsMenu\IBulkProvider;
use OCP\Contacts\ContactsMenu\IEntry;
use function array_combine;
use function array_filter;
use function array_map;

class StatusProvider implements IBulkProvider {

public function __construct(private StatusService $statusService) {
}

public function process(array $entries): void {
$uids = array_filter(
array_map(fn (IEntry $entry): ?string => $entry->getProperty('UID'), $entries)
);

$statuses = $this->statusService->findByUserIds($uids);
$indexed = array_combine(
array_map(fn(UserStatus $status) => $status->getUserId(), $statuses),
$statuses
);

foreach ($entries as $entry) {
$uid = $entry->getProperty('UID');
if ($uid !== null && isset($indexed[$uid])) {
$status = $indexed[$uid];
$entry->setStatus(
$status->getStatus(),
$status->getCustomMessage(),
$status->getCustomIcon(),
);
}
}
}

}
48 changes: 36 additions & 12 deletions core/src/components/ContactsMenu/Contact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,37 @@
:href="contact.profileUrl"
class="contact__avatar-wrapper">
<NcAvatar class="contact__avatar"
:is-no-user="true"
:size="44"
:user="contact.isUser ? contact.uid : undefined"
:is-no-user="!contact.isUser"
:display-name="contact.avatarLabel"
:url="contact.avatar" />
:url="contact.avatar"
:preloaded-user-status="preloadedUserStatus" />
</a>
<a v-else-if="contact.profileUrl"
:href="contact.profileUrl">
<NcAvatar class="contact__avatar"
:is-no-user="true"
:display-name="contact.avatarLabel" />
:size="44"
:user="contact.isUser ? contact.uid : undefined"
:is-no-user="!contact.isUser"
:display-name="contact.avatarLabel"
:preloaded-user-status="preloadedUserStatus" />
</a>
<NcAvatar v-else
:size="44"
class="contact__avatar"
:is-no-user="true"
:user="contact.isUser ? contact.uid : undefined"
:is-no-user="!contact.isUser"
:display-name="contact.avatarLabel"
:url="contact.avatar" />
:url="contact.avatar"
:preloaded-user-status="preloadedUserStatus" />

<a class="contact__body"
:href="contact.profileUrl || contact.topAction?.hyperlink">
<div class="contact__body__full-name">{{ contact.fullName }}</div>
<div v-if="contact.lastMessage" class="contact__body__last-message">{{ contact.lastMessage }}</div>
<div class="contact__body__email-address">{{ contact.emailAddresses[0] }}</div>
<div v-if="contact.statusMessage" class="contact__body__status-message">{{ contact.statusMessage }}</div>
<div v-else class="contact__body__email-address">{{ contact.emailAddresses[0] }}</div>
</a>
<NcActions v-if="actions.length"
:inline="contact.topAction ? 1 : 0">
Expand Down Expand Up @@ -97,6 +107,16 @@ export default {
}
return this.contact.actions
},
preloadedUserStatus() {
if (this.contact.status) {
return {
status: this.contact.status,
message: this.contact.statusMessage,
icon: this.contact.statusIcon,
}
}
return undefined
}
},
}
</script>
Expand All @@ -118,28 +138,32 @@ export default {
}

&__avatar-wrapper {
height: 32px;
}

&__avatar {
height: 32px;
width: 32px;
display: inherit;
}

&__body {
flex-grow: 1;
padding-left: 8px;
padding-left: 10px;
min-width: 0;

div {
position: relative;
width: 100%;
overflow-x: hidden;
text-overflow: ellipsis;
margin: -1px 0;
}
div:first-of-type {
margin-top: 0;
}
div:last-of-type {
margin-bottom: 0;
}

.last-message, .email-address {
&__last-message, &__status-message, &__email-address {
color: var(--color-text-maxcontrast);
}
}
Expand Down
24 changes: 2 additions & 22 deletions core/src/tests/views/ContactsMenu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('ContactsMenu', function() {
emailAddresses: [],
}
],
contactsAppEnabled: false,
contactsAppEnabled: true,
},
})

Expand All @@ -149,26 +149,6 @@ describe('ContactsMenu', function() {
expect(view.vm.contacts.length).toBe(2)
expect(view.text()).toContain('Acosta Lancaster')
expect(view.text()).toContain('Adeline Snider')
})

it('shows link ot Contacts', async () => {
const view = shallowMount(ContactsMenu)
axios.post.mockResolvedValue({
data: {
contacts: [
{
id: 1,
},
{
id: 2,
},
],
contactsAppEnabled: true,
},
})

await view.vm.handleOpen()

expect(view.text()).toContain('Show all contacts …')
expect(view.text()).toContain('Show all contacts')
})
})
17 changes: 7 additions & 10 deletions core/src/views/ContactsMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
</ul>
</div>
<div v-if="contactsAppEnabled" class="contactsmenu__menu__content__footer">
<a :href="contactsAppURL">{{ t('core', 'Show all contacts') }}</a>
<NcButton type="tertiary" :href="contactsAppURL">{{ t('core', 'Show all contacts') }}</NcButton>
</div>
<div v-else-if="canInstallApp" class="contactsmenu__menu__content__footer">
<a :href="contactsAppMgmtURL">{{ t('core', 'Install the Contacts app') }}</a>
<NcButton type="tertiary" :href="contactsAppMgmtURL">{{ t('core', 'Install the Contacts app') }}</NcButton>
</div>
</div>
</div>
Expand All @@ -75,6 +75,7 @@ import debounce from 'debounce'
import { getCurrentUser } from '@nextcloud/auth'
import { generateUrl } from '@nextcloud/router'
import Magnify from 'vue-material-design-icons/Magnify.vue'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
import NcHeaderMenu from '@nextcloud/vue/dist/Components/NcHeaderMenu.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
Expand All @@ -91,6 +92,7 @@ export default {
Contact,
Contacts,
Magnify,
NcButton,
NcEmptyContent,
NcHeaderMenu,
NcLoadingIcon,
Expand Down Expand Up @@ -178,14 +180,9 @@ export default {
overflow-y: auto;

&__footer {
text-align: center;

a {
display: block;
width: 100%;
padding: 12px 0;
opacity: .5;
}
display: flex;
flex-direction: column;
align-items: center;
}
}

Expand Down
4 changes: 2 additions & 2 deletions dist/core-main.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files-personal-settings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-personal-settings.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
'OCP\\Constants' => $baseDir . '/lib/public/Constants.php',
'OCP\\Contacts\\ContactsMenu\\IAction' => $baseDir . '/lib/public/Contacts/ContactsMenu/IAction.php',
'OCP\\Contacts\\ContactsMenu\\IActionFactory' => $baseDir . '/lib/public/Contacts/ContactsMenu/IActionFactory.php',
'OCP\\Contacts\\ContactsMenu\\IBulkProvider' => $baseDir . '/lib/public/Contacts/ContactsMenu/IBulkProvider.php',
'OCP\\Contacts\\ContactsMenu\\IContactsStore' => $baseDir . '/lib/public/Contacts/ContactsMenu/IContactsStore.php',
'OCP\\Contacts\\ContactsMenu\\IEntry' => $baseDir . '/lib/public/Contacts/ContactsMenu/IEntry.php',
'OCP\\Contacts\\ContactsMenu\\ILinkAction' => $baseDir . '/lib/public/Contacts/ContactsMenu/ILinkAction.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Constants' => __DIR__ . '/../../..' . '/lib/public/Constants.php',
'OCP\\Contacts\\ContactsMenu\\IAction' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IAction.php',
'OCP\\Contacts\\ContactsMenu\\IActionFactory' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IActionFactory.php',
'OCP\\Contacts\\ContactsMenu\\IBulkProvider' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IBulkProvider.php',
'OCP\\Contacts\\ContactsMenu\\IContactsStore' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IContactsStore.php',
'OCP\\Contacts\\ContactsMenu\\IEntry' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IEntry.php',
'OCP\\Contacts\\ContactsMenu\\ILinkAction' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/ILinkAction.php',
Expand Down
13 changes: 11 additions & 2 deletions lib/private/Contacts/ContactsMenu/ActionProviderStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OC\Contacts\ContactsMenu\Providers\LocalTimeProvider;
use OC\Contacts\ContactsMenu\Providers\ProfileProvider;
use OCP\AppFramework\QueryException;
use OCP\Contacts\ContactsMenu\IBulkProvider;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IServerContainer;
use OCP\IUser;
Expand All @@ -47,18 +48,26 @@ public function __construct(
}

/**
* @return IProvider[]
* @return list<IProvider|IBulkProvider>
* @throws Exception
*/
public function getProviders(IUser $user): array {
$appClasses = $this->getAppProviderClasses($user);
$providerClasses = $this->getServerProviderClasses();
$allClasses = array_merge($providerClasses, $appClasses);
/** @var list<IProvider|IBulkProvider> $providers */
$providers = [];

foreach ($allClasses as $class) {
try {
$providers[] = $this->serverContainer->get($class);
$provider = $this->serverContainer->get($class);
if ($provider instanceof IProvider || $provider instanceof IBulkProvider) {
$providers[] = $provider;
} else {
$this->logger->warning('Ignoring invalid contacts menu provider', [
'class' => $class,
]);
}
} catch (QueryException $ex) {
$this->logger->error(
'Could not load contacts menu action provider ' . $class,
Expand Down
2 changes: 2 additions & 0 deletions lib/private/Contacts/ContactsMenu/ContactsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ private function contactArrayToEntry(array $contact): Entry {
if (isset($contact['UID'])) {
$uid = $contact['UID'];
$entry->setId($uid);
$entry->setProperty('isUser', false);
if (isset($contact['isLocalSystemBook'])) {
$avatar = $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $uid, 'size' => 64]);
$entry->setProperty('isUser', true);
} elseif (isset($contact['FN'])) {
$avatar = $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $contact['FN'], 'size' => 64]);
} else {
Expand Down
Loading