Esempio n. 1
0
    def chats(self):
        '''
		Aimed at the ChatService.
		Goal: return a sorted list of ChatServices for every participation of the current user , based on the date n time of the activity.
		Returns:a sorted list of ChatServices(id=participation.chat.id) for every participation of the current user if the current user is in the chat with an id = <identification>.
		'''
        return sorted(tuple(
            service.ChatService(id=participation.chat.id)
            for participation in self.__instance.participations.all()),
                      key=lambda chat: chat.activity_dnt,
                      reverse=True) if self.__instance else None
Esempio n. 2
0
    def establish_a_chat(self, name):
        '''
		Aimed at the ChatService.
		Goal: create a chat instance , by creating an instance of a ChatService.
		Arguments: identification:int.
		Actions: check if the current user's isinstance exists and create a ChatService instance with provided data.
		If such instance has been successfully created return the ChatService instance 
		Returns: return the instance of the ChatService - If the Actions are all valid and follow the conditions , otherwise - None
		'''
        return (chat if (chat := service.ChatService()).create(
            creator_id=self.__instance.id, name=name) else
                None) if self.__instance else None
Esempio n. 3
0
    def get_a_chat(self, identification):
        '''
		Aimed at the ChatService.
		Goal: return a ChatService instance.
		Arguments: identification:int.
		Actions:if the current user's instance exists, then try to find a participation with a chat_id = <identification>. If there is such a participation establish a ChatService with an id of provided identification.
		Returns: ChatService(id=<identification>) if the current user is in the chat with an id = <identification>.
		Exceptions:
			Raises:
				TypeError - if the data type of the identification is not an integer.
		'''

        assert isinstance(
            identification,
            int), TypeError('Chat identification shall be an integer.')
        return service.ChatService(
            id=participation.chat_id) if self.__instance and (
                participation := self.__instance.participations.filter_by(
                    chat_id=identification).first()) else None
Esempio n. 4
0
    def join_a_chat(self, identification):
        '''
		Aimed at the ChatService.
		Goal: join an existing chat instance , by creating a Participant instance using the ParticipantService.
		Arguments: identification:int.
		Actions: check if the current user's isinstance exists, verify the existance of the chat with such id , after that check if the current user is not a participant of the chat, thus verifying the absence of any related participation.
		Then create a Participation instance using the ParticipationService.
		Returns: True - If the Actions are all valid and follow the conditions , otherwise - False
		Exceptions:
			Raises:
				ValueError - if the data type of the identification is not an integer.
		'''

        assert isinstance(
            identification,
            int), ValueError('Chat identification shall be an integer.')
        return True if self.__instance and (chat := service.ChatService(
            id=identification)).id == identification and (
                not self in chat) and (participation :=
                                       service.ParticipationService()).create(
                                           participant_id=self.__instance.id,
                                           chat_id=identification) else False
Esempio n. 5
0
	def chat(self):
		'''
		Goal:return the chat which contains current message.
		Returns:ChatService of the chat If the inner instance of the message exists else None
		'''
		return service.ChatService(id=self.__instance.chat_id) if self.__instance else None