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)
def __init__(self, friendship: Models.Friendship = Models.Friendship()): """ :param senderUser: Models.user() :param recipUser: Models.user() :rtype: ResponseUnblockUser """ super().__init__() self.friendship = friendship
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!')
def blockUser(self): friendship = Models.Friendship() friendship.recipUser = self.currentContact friendship.accepted = 0 friendship.blocked = 1 self.controller.requestBlockUser(friendship)
def fromJson(self, dictObj: dict): super().fromJson(dictObj) self.friendship = Models.Friendship().fromJson(dictObj['friendship']) return self
def __init__(self, friendship: Models.Friendship = Models.Friendship()): super().__init__() self.friendship = friendship
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
def __init__(self, friendship: Models.Friendship = Models.Friendship()): super().__init__() self.friendship = friendship self.senderUser = friendship.senderUser self.recipUser = friendship.recipUser
def requestRetrieveChat(self, friend: Models.user): friendship = Models.Friendship(self.currentUser, friend) self.clientHandler.requestRetrieveChat(friendship)