@@ -463,6 +463,55 @@ def close_poll(self, poll: typing.Union[Poll, int], conversation: typing.Union[C
463463 token = conversation .token if isinstance (conversation , Conversation ) else conversation
464464 return Poll (self ._session .ocs ("DELETE" , self ._ep_base + f"/api/v1/poll/{ token } /{ poll_id } " ), token )
465465
466+ def set_conversation_avatar (
467+ self ,
468+ conversation : typing .Union [Conversation , str ],
469+ avatar : typing .Union [bytes , tuple [str , typing .Union [str , None ]]],
470+ ) -> Conversation :
471+ """Set image or emoji as avatar for the conversation.
472+
473+ :param conversation: conversation token or :py:class:`~nc_py_api.talk.Conversation`.
474+ :param avatar: Squared image with mimetype equal to PNG or JPEG or a tuple with emoji and optional
475+ HEX color code(6 times ``0-9A-F``) without the leading ``#`` character.
476+
477+ .. note:: Color omit to fallback to the default bright/dark mode icon background color.
478+ """
479+ require_capabilities ("spreed.features.avatar" , self ._session .capabilities )
480+ token = conversation .token if isinstance (conversation , Conversation ) else conversation
481+ if isinstance (avatar , bytes ):
482+ r = self ._session .ocs ("POST" , self ._ep_base + f"/api/v1/room/{ token } /avatar" , files = {"file" : avatar })
483+ else :
484+ r = self ._session .ocs (
485+ "POST" ,
486+ self ._ep_base + f"/api/v1/room/{ token } /avatar/emoji" ,
487+ json = {
488+ "emoji" : avatar [0 ],
489+ "color" : avatar [1 ],
490+ },
491+ )
492+ return Conversation (r )
493+
494+ def delete_conversation_avatar (self , conversation : typing .Union [Conversation , str ]) -> Conversation :
495+ """Delete conversation avatar.
496+
497+ :param conversation: conversation token or :py:class:`~nc_py_api.talk.Conversation`.
498+ """
499+ require_capabilities ("spreed.features.avatar" , self ._session .capabilities )
500+ token = conversation .token if isinstance (conversation , Conversation ) else conversation
501+ return Conversation (self ._session .ocs ("DELETE" , self ._ep_base + f"/api/v1/room/{ token } /avatar" ))
502+
503+ def get_conversation_avatar (self , conversation : typing .Union [Conversation , str ], dark = False ) -> bytes :
504+ """Get conversation avatar (binary).
505+
506+ :param conversation: conversation token or :py:class:`~nc_py_api.talk.Conversation`.
507+ :param dark: boolean indicating should be or not avatar fetched for dark theme.
508+ """
509+ require_capabilities ("spreed.features.avatar" , self ._session .capabilities )
510+ token = conversation .token if isinstance (conversation , Conversation ) else conversation
511+ ep_suffix = "/dark" if dark else ""
512+ response = self ._session .ocs ("GET" , self ._ep_base + f"/api/v1/room/{ token } /avatar" + ep_suffix , not_parse = True )
513+ return response .content
514+
466515 @staticmethod
467516 def _get_token (message : typing .Union [TalkMessage , str ], conversation : typing .Union [Conversation , str ]) -> str :
468517 if not conversation and not isinstance (message , TalkMessage ):
0 commit comments