예제 #1
0
 def requestFriendshipAcepted(self, user: Models.user):
     # VERIFICAÇÃO FEITA:
     friendship = Models.Friendship()
     friendship.recipUser = self.currentUser
     friendship.accepted = 1
     friendship.blocked = 0
     friendship.senderUser = user
     self.clientHandler.requestFriendshipAcepted(friendship)
예제 #2
0
 def __init__(self, friendship: Models.Friendship = Models.Friendship()):
     """
     :param senderUser:  Models.user()
     :param recipUser:  Models.user()
     :rtype: ResponseUnblockUser
     """
     super().__init__()
     self.friendship = friendship
예제 #3
0
    def addFriend(self, senderUser: Models.user,
                  friendEmail: str) -> Models.Friendship or Exception:
        if self.searchUser(friendEmail) != None:
            recipUser = self.searchUser(friendEmail)
            if isinstance(recipUser, Exception):
                return recipUser
            elif recipUser is None:
                return Exception('Usuário não encontrado!')
            else:
                senderId = senderUser.idd
                recipId = recipUser.idd
                tableBlocks = 'blocks_' + str(recipId)
                sql = 'SELECT id_block FROM ' + tableBlocks + ' WHERE id_block = ' + str(
                    senderId) + ';'
                id = self.__execute_fetchone__(sql)
                # VERIFICA SE O REMETENTE DO PEDIDO DE AMIZADO ESTÁ BLOQUEADO PELO DESTINATÁRIO
                if id == None or id == 0:
                    registerDate = datetime.datetime.now()
                    # O contato é adcionado na tabela de amigos do usuário:
                    tableSender = 'friends_' + str(senderId)
                    tableRecip = 'friends_' + str(recipId)
                    sql1 = 'INSERT INTO ' + tableSender + '(id_friend, confirmation, showNotification) VALUES (' + str(
                        recipId) + ', 1, 1);'
                    sql2 = 'INSERT INTO ' + tableRecip + '(id_friend, confirmation, showNotification) VALUES (' + str(
                        senderId) + ', 0, 1);'

                    if recipId > senderId:
                        tableName = 'chat_' + str(recipId) + '_' + str(
                            senderId)
                    elif senderId > recipId:
                        tableName = 'chat_' + str(senderId) + '_' + str(
                            recipId)

                    sql3 = 'CREATE TABLE IF NOT EXISTS ' + tableName + '(id INTEGER PRIMARY KEY AUTOINCREMENT, id_dest INTEGER, id_remete INTEGER, data_hora datetime, conteudo TEXT, statusRead INTEGER, statusReceived INTEGER, FOREIGN KEY(id_dest) REFERENCES users(id), FOREIGN KEY(id_remete) REFERENCES users(id));'

                    commitFeedback = self.__execute_transaction__(sql1 + sql2 +
                                                                  sql3)
                    print('commitFeedback ' + str(commitFeedback))
                    if commitFeedback == 0:
                        friendship = Models.Friendship(senderUser, recipUser)
                        return friendship
                    elif isinstance(commitFeedback, Exception):
                        return commitFeedback
                elif int(id) == senderId:
                    #CASO CONSTE NA LISTA DE BLOQUEIOS:
                    return Exception('Usuário não encontrado!')
        else:
            return Exception('Usuário não encontrado!')
예제 #4
0
 def blockUser(self):
     friendship = Models.Friendship()
     friendship.recipUser = self.currentContact
     friendship.accepted = 0
     friendship.blocked = 1
     self.controller.requestBlockUser(friendship)
예제 #5
0
 def fromJson(self, dictObj: dict):
     super().fromJson(dictObj)
     self.friendship = Models.Friendship().fromJson(dictObj['friendship'])
     return self
예제 #6
0
 def __init__(self, friendship: Models.Friendship = Models.Friendship()):
     super().__init__()
     self.friendship = friendship
예제 #7
0
 def fromJson(self, dictObj: dict):
     super().fromJson(dictObj)
     self.friendship = Models.Friendship().fromJson(dictObj['friendship'])
     self.recipUser = Models.user().fromJson(dictObj['recipUser'])
     self.senderUser = Models.user().fromJson(dictObj['senderUser'])
     return self
예제 #8
0
 def __init__(self, friendship: Models.Friendship = Models.Friendship()):
     super().__init__()
     self.friendship = friendship
     self.senderUser = friendship.senderUser
     self.recipUser = friendship.recipUser
예제 #9
0
 def requestRetrieveChat(self, friend: Models.user):
     friendship = Models.Friendship(self.currentUser, friend)
     self.clientHandler.requestRetrieveChat(friendship)