Exemplo n.º 1
0
 async def _update_avatar(self,
                          user: '******',
                          photo: TypeChatPhoto,
                          sender: Optional['p.Puppet'] = None,
                          save: bool = False) -> bool:
     if isinstance(photo, (ChatPhoto, UserProfilePhoto)):
         loc = InputPeerPhotoFileLocation(
             peer=await self.get_input_entity(user),
             local_id=photo.photo_big.local_id,
             volume_id=photo.photo_big.volume_id,
             big=True)
         photo_id = (f"{loc.volume_id}-{loc.local_id}" if isinstance(
             photo, ChatPhoto) else photo.photo_id)
     elif isinstance(photo, Photo):
         loc, largest = self._get_largest_photo_size(photo)
         photo_id = f"{largest.location.volume_id}-{largest.location.local_id}"
     elif isinstance(
             photo,
         (UserProfilePhotoEmpty, ChatPhotoEmpty, PhotoEmpty, type(None))):
         photo_id = ""
         loc = None
     else:
         raise ValueError(f"Unknown photo type {type(photo)}")
     if self.peer_type == "user" and not photo_id and not config[
             "bridge.allow_avatar_remove"]:
         return False
     if self.photo_id != photo_id:
         if not photo_id:
             await self._try_set_state(
                 sender, EventType.ROOM_AVATAR,
                 RoomAvatarStateEventContent(url=None))
             self.photo_id = ""
             self.avatar_url = None
             if save:
                 await self.save()
             return True
         file = await util.transfer_file_to_matrix(user.client,
                                                   self.main_intent, loc)
         if file:
             await self._try_set_state(
                 sender, EventType.ROOM_AVATAR,
                 RoomAvatarStateEventContent(url=file.mxc))
             self.photo_id = photo_id
             self.avatar_url = file.mxc
             if save:
                 await self.save()
             return True
     return False
Exemplo n.º 2
0
 def set_room_avatar(self, room_id: RoomID,
                     avatar_url: Optional[ContentURI],
                     **kwargs) -> Awaitable[EventID]:
     return self.send_state_event(
         room_id, EventType.ROOM_AVATAR,
         RoomAvatarStateEventContent(url=avatar_url), **kwargs)