Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backend for conversation avatars #4737

Closed
wants to merge 12 commits into from
Closed
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
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m

]]></description>

<version>11.0.0-alpha.2</version>
<version>11.0.0-alpha.3</version>
<licence>agpl</licence>

<author>Daniel Calviño Sánchez</author>
Expand Down
28 changes: 28 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,5 +592,33 @@
'apiVersion' => 'v1',
],
],

/**
* Room avatar
*/
[
'name' => 'RoomAvatar#getAvatar',
'url' => '/api/{apiVersion}/avatar/{roomToken}/{size}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v3',
],
],
[
'name' => 'RoomAvatar#setAvatar',
'url' => '/api/{apiVersion}/avatar/{roomToken}',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v3',
],
],
[
'name' => 'RoomAvatar#deleteAvatar',
'url' => '/api/{apiVersion}/avatar/{roomToken}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v3',
],
],
],
];
1 change: 1 addition & 0 deletions docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ title: Capabilities
* `phonebook-search` - Is present when the server has the endpoint to search for phone numbers to find matches in the accounts list
* `raise-hand` - Participants can raise or lower hand, the state change is sent through signaling messages.
* `room-description` - A description can be get and set for conversations.
* `room-avatar` - A custom picture can be got and set for conversations.
* `config => chat => read-privacy` - See `chat-read-status`
* `config => previews => max-gif-size` - Maximum size in bytes below which a GIF can be embedded directly in the page at render time. Bigger files will be rendered statically using the preview endpoint instead. Can be set with `occ config:app:set spreed max-gif-size --value=X` where X is the new value in bytes. Defaults to 3 MB.
2 changes: 2 additions & 0 deletions docs/conversation.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
`name` | string | * | Name of the conversation (can also be empty)
`displayName` | string | * | `name` if non empty, otherwise it falls back to a list of participants
`description` | string | v3 | Description of the conversation (can also be empty) (only available with `room-description` capability)
`avatarId` | string | v3 | The type of the avatar ("custom", "user", "icon-public", "icon-contacts", "icon-mail", "icon-password", "icon-changelog", "icon-file") (only available with `room-avatar` capability)
`avatarVersion` | int | v3 | The version of the avatar (only available with `room-avatar` capability)
`participantType` | int | * | Permissions level of the current user
`attendeeId` | int | v3 | Unique attendee id
`attendeePin` | string | v3 | Unique dial-in authentication code for this user, when the conversation has SIP enabled (see `sipEnabled` attribute)
Expand Down
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
use OCA\Talk\Activity\Listener as ActivityListener;
use OCA\Talk\Avatar\Listener as AvatarListener;
use OCA\Talk\Capabilities;
use OCA\Talk\Chat\Changelog\Listener as ChangelogListener;
use OCA\Talk\Chat\ChatManager;
Expand Down Expand Up @@ -131,6 +132,7 @@ public function boot(IBootContext $context): void {
ChangelogListener::register($dispatcher);
ShareListener::register($dispatcher);
Operation::register($dispatcher);
AvatarListener::register($dispatcher);

$this->registerRoomActivityHooks($dispatcher);
$this->registerChatHooks($dispatcher);
Expand Down
84 changes: 84 additions & 0 deletions lib/Avatar/Listener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020, Daniel Calviño Sánchez (danxuliu@gmail.com)
*
* @author Daniel Calviño Sánchez <danxuliu@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\Talk\Avatar;

use OCA\Talk\Manager;
use OCA\Talk\Room;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
use Symfony\Component\EventDispatcher\GenericEvent;

class Listener {

/** @var Manager */
private $manager;

/**
* @param Manager $manager
*/
public function __construct(
Manager $manager) {
$this->manager = $manager;
}

public static function register(IEventDispatcher $dispatcher): void {
$listener = static function (GenericEvent $event) {
if ($event->getArgument('feature') !== 'avatar') {
return;
}

/** @var self $listener */
$listener = \OC::$server->query(self::class);
$listener->updateRoomAvatarsFromChangedUserAvatar($event->getSubject());
};
$dispatcher->addListener(IUser::class . '::changeUser', $listener);
}

/**
* Updates the associated room avatars from the changed user avatar
*
* The avatar versions of all the one-to-one conversations of that user are
* bumped.
*
* Note that the avatar seen by the user who has changed her avatar will not
* change, as she will get the avatar of the other user, but even if the
* avatar images are independent the avatar version is a shared value and
* needs to be bumped for both.
*
* @param IUser $user the user whose avatar changed
*/
public function updateRoomAvatarsFromChangedUserAvatar(IUser $user): void {
$rooms = $this->manager->getRoomsForUser($user->getUID());
foreach ($rooms as $room) {
if ($room->getType() !== Room::ONE_TO_ONE_CALL) {
continue;
}

$room->setAvatar($room->getAvatarId(), $room->getAvatarVersion() + 1);
}
}
}
Loading