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

๐Ÿ–ผ๏ธ Conversation avatars API #8333

Merged
merged 49 commits into from
Dec 7, 2022
Merged

Conversation

vitormattos
Copy link
Contributor

@vitormattos vitormattos commented Nov 10, 2022

Fix #927

๐Ÿšง TODO

  • We need OCS API, suggestion: /api/{apiVersion}/room/{token}/image - Similar to https://github.com/nextcloud/spreed/blob/master/lib/Controller/TempAvatarController.php
    • POST a new image
      • Needs to validate the file is an image
      • Needs to validate the image is a square and of a supported type (check User avatar code for what we should allow)
      • File should be stored with OCP\Files\IAppData with conversation token + file type as name
    • DELETE to remove an image
    • GET which serves the image as FileDisplayResponse
      • Not sure if that works as OCSController, if it does not we need another Controller with another route.
      • If AppData does not have a file with the conversation name, we fall back to returning an icon based on the conversation type
      • If the conversation is a one-to-one conversation we fall back to the user avatar?
      • /dark URL for dark avatars
  • Add capability
  • Add integration tests
  • Adjust "icon url" usage in:
    • activities
    • notifications
    • search results
    • references
    • etc.

๐Ÿ Checklist

@vitormattos vitormattos added 2. developing feature: api ๐Ÿ› ๏ธ OCS API for conversations, chats and participants labels Nov 10, 2022
@vitormattos vitormattos added this to the ๐Ÿ’Ÿ Next Major (26) milestone Nov 10, 2022
@vitormattos vitormattos self-assigned this Nov 10, 2022
@vitormattos vitormattos changed the title Implement group avatar endpoints [WIP] Implement group avatar endpoints Nov 10, 2022
appinfo/routes/routesGroupAvatarController.php Outdated Show resolved Hide resolved
lib/Controller/GroupAvatarController.php Outdated Show resolved Hide resolved
lib/Controller/GroupAvatarController.php Outdated Show resolved Hide resolved
lib/Controller/GroupAvatarController.php Outdated Show resolved Hide resolved
lib/Controller/GroupAvatarController.php Outdated Show resolved Hide resolved
lib/Controller/GroupAvatarController.php Outdated Show resolved Hide resolved
lib/Controller/GroupAvatarController.php Outdated Show resolved Hide resolved
lib/Controller/GroupAvatarController.php Outdated Show resolved Hide resolved
@nickvergessen nickvergessen changed the title [WIP] Implement group avatar endpoints ๐Ÿ–ผ๏ธ Conversation avatars API Nov 10, 2022
@nickvergessen
Copy link
Member

Added some todos in the PR description

@SystemKeeper
Copy link
Contributor

If this in renamed to a more general "AvatarController", would that supersede the "TempAvatarController" (temp-user-avatar-api capability) ?

@nickvergessen
Copy link
Member

would that supersede the "TempAvatarController" (temp-user-avatar-api capability) ?

No, as that is still an API that should not be in talk but in server

docs/conversation.md Outdated Show resolved Hide resolved
lib/Service/AvatarService.php Outdated Show resolved Hide resolved
lib/Service/AvatarService.php Outdated Show resolved Hide resolved
docs/conversation.md Outdated Show resolved Hide resolved
lib/Service/AvatarService.php Outdated Show resolved Hide resolved
lib/Chat/ChatManager.php Outdated Show resolved Hide resolved
lib/Controller/AvatarController.php Outdated Show resolved Hide resolved
lib/Controller/RoomController.php Outdated Show resolved Hide resolved
lib/Search/ConversationSearch.php Outdated Show resolved Hide resolved
lib/Service/AvatarService.php Outdated Show resolved Hide resolved
lib/Service/AvatarService.php Outdated Show resolved Hide resolved
src/components/ConversationIcon.vue Outdated Show resolved Hide resolved
tests/integration/features/chat/avatar.feature Outdated Show resolved Hide resolved
tests/integration/features/bootstrap/FeatureContext.php Outdated Show resolved Hide resolved
tests/integration/features/bootstrap/FeatureContext.php Outdated Show resolved Hide resolved
@vitormattos vitormattos marked this pull request as ready for review November 21, 2022 04:56
appinfo/info.xml Outdated Show resolved Hide resolved
docs/conversation.md Outdated Show resolved Hide resolved
lib/Activity/Listener.php Outdated Show resolved Hide resolved
lib/Chat/ChatManager.php Outdated Show resolved Hide resolved
lib/Activity/Listener.php Outdated Show resolved Hide resolved
lib/Search/ConversationSearch.php Outdated Show resolved Hide resolved
lib/Service/AvatarService.php Show resolved Hide resolved
lib/Service/AvatarService.php Outdated Show resolved Hide resolved
lib/Service/RoomService.php Show resolved Hide resolved
lib/Service/RoomService.php Show resolved Hide resolved
lib/Activity/Listener.php Outdated Show resolved Hide resolved
lib/Activity/Provider/Base.php Outdated Show resolved Hide resolved
lib/Activity/Provider/Base.php Outdated Show resolved Hide resolved
lib/Chat/ChatManager.php Outdated Show resolved Hide resolved
lib/Controller/RoomController.php Outdated Show resolved Hide resolved
lib/Service/AvatarService.php Outdated Show resolved Hide resolved
lib/Service/AvatarService.php Outdated Show resolved Hide resolved
lib/Service/AvatarService.php Outdated Show resolved Hide resolved
lib/Service/RoomService.php Outdated Show resolved Hide resolved
lib/Service/RoomService.php Outdated Show resolved Hide resolved
@@ -88,6 +88,7 @@
| `statusMessage` | string | v4 | | Optional: Only available for one-to-one conversations and when `includeStatus=true` is set |
| `participants` | array | v1 | v2 | **Removed** |
| `guestList` | string | v1 | v2 | **Removed** |
| `avatarUrl` | string | v4 | | Avatar URL of the conversation including a version flag `v=โ€ฆ` for easier expiration of the avatar in case a moderator updates it, since the avatar endpoint should be cached for 24 hours. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this parameter is a bit problematic. It will make the avatar look updated on the conversation list, but e.g. search results, notifications, etc still show the old one. So basically we would need to tell clients to track this value and when it is different, they should invalidate their avatar image cache.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @Ivansss @mahibi

Any idea what the best way would be? I'd like to have it similar to user avatars. They work without any additional information, you just need the userid (conversation token) and can make your URL. It's cached so can take some time until others see it. Should be fine, unless you did the change yourself.
Would you think it's okay to have it cached/old on the mobile apps when you changed it in the web? Or what would be a good way to handle this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user avatar also have a query string to expire with an incremental value called v too.
The endpoint /avatar/{userId}/{size} haven't this value because is only to expire and is send by query string.

When the backend delete the avatar, the version is incremented:
https://github.com/nextcloud/server/blob/master/lib/private/Avatar/UserAvatar.php#L194-L195
The same code is trigged when we set a new avatar:
https://github.com/nextcloud/server/blob/master/lib/private/Avatar/UserAvatar.php#L90-L96

The frontend every time get the version directly from userconfig:
https://github.com/nextcloud/server/blob/master/apps/settings/src/components/PersonalInfo/AvatarSection.vue#L149

The backend also retrieve the avatar version every time when is the current user that request:
https://github.com/nextcloud/server/blob/master/lib/private/TemplateLayout.php#L157
and when the current user need the avatar of other user:
https://github.com/nextcloud/server/blob/master/lib/private/Template/JSConfigHelper.php#L287-L290

Is a bit complex to identify this in the server repository because the code that do this is fragmented in a lot of places, but the server store and use the version number of avatar.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The frontend every time get the version directly from userconfig:

This is only for your very own avatar. It is not done for the avatar of others, see:
https://github.com/nextcloud/nextcloud-vue/blob/master/src/components/NcAvatar/NcAvatar.vue#L627-L647

But that is exactly the problem here. It's basically always the avatar of others ๐Ÿ˜ฌ

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this wont be a problem to Talk.

I already implemented to send the version of avatar in Room object, then, in all places that we need to display the current room avatar, will be possible.

In the places that we haven't the Room object, we will send the URL of avatar and we already have a contract to do this, have places in server that need a property called icon, other use iconUrl and we can do the same in Talk.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is exactly why I started the discussion here. We will NOT be able to add the avatar URL on all things. But anyway.

We can move this to a follow up issue so we can merge this PR

$file->delete();
}

$avatarName = $this->random->generate(10, ISecureRandom::CHAR_HUMAN_READABLE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add the file extension?

Suggested change
$avatarName = $this->random->generate(10, ISecureRandom::CHAR_HUMAN_READABLE);
$avatarName = $this->random->generate(6, ISecureRandom::CHAR_HUMAN_READABLE) . ($mimeType === 'image/jpeg' ? '.jpg' : '.png');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is possible, but we will need change the current implementation a bit to consider the extension.
For now, the name that we stored on database is only to have a token to expire the previous image. Now, if we send a request without the version, will get the room image too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant for readability on the filesystem (also user avatars have it). But sure if it works, let's keep it in the current format.
It could still work without it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will be more readable to save the filename with the extension.

Maybe we can change this approach in the future creating a table to store all room avatar, maybe room_avatar to make possible to have a gallery of room avatar. With room avatar gallery, we can maintain only the name with the 10 chars (without the extension) in room table following the current approach to store the current room avatar. In the table room_avatar we can store more details, by example, the full name of file in filesystem.

vitormattos and others added 9 commits December 7, 2022 15:02
If receive `@all` mention, will be necessary to get the avatar from room
object

Signed-off-by: Vitor Mattos <vitor@php.rio>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
@nickvergessen
Copy link
Member

Rebased to resolve conflicts from breakout rooms part1 merge

Otherwise the avatar can not be displayed but instead the browser downloads it

Signed-off-by: Joas Schilling <coding@schilljs.com>
Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a commit so the file can be viewed in the browser and does not trigger a download.

Other than that only the system messages are missing, but we can do that as a follow up.

@nickvergessen
Copy link
Member

Follow up in #8443

@nickvergessen nickvergessen merged commit e42f5d9 into master Dec 7, 2022
@nickvergessen nickvergessen deleted the feature/group-avatar branch December 7, 2022 18:58
vitormattos added a commit that referenced this pull request Feb 17, 2023
Signed-off-by: Vitor Mattos <vitor@php.rio>
vitormattos added a commit to nextcloud/server that referenced this pull request Mar 16, 2023
nextcloud/spreed#8333 introduced an optional `icon-url`
for the call objects in rich messages.

nextcloud/spreed#8389

Signed-off-by: Vitor Mattos <vitor@php.rio>
vitormattos added a commit that referenced this pull request Mar 16, 2023
#8333 introduced an optional `icon-url`
for the call objects in rich messages.

#8389

Signed-off-by: Vitor Mattos <vitor@php.rio>
vitormattos added a commit that referenced this pull request Mar 20, 2023
#8333 introduced an optional `icon-url`
for the call objects in rich messages.

#8389

Signed-off-by: Vitor Mattos <vitor@php.rio>
vitormattos added a commit that referenced this pull request Mar 20, 2023
#8333 introduced an optional `icon-url`
for the call objects in rich messages.

#8389

Signed-off-by: Vitor Mattos <vitor@php.rio>
nickvergessen pushed a commit that referenced this pull request Apr 4, 2023
#8333 introduced an optional `icon-url`
for the call objects in rich messages.

#8389

Signed-off-by: Vitor Mattos <vitor@php.rio>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release feature: api ๐Ÿ› ๏ธ OCS API for conversations, chats and participants
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

๐Ÿ–ผ๏ธ Conversation avatars
3 participants