Exemplo n.º 1
0
 def addMessage(self, sender, text):
     if sender.id in self.participants or sender == self.owner:
         message = Mess(sender, text, self.id)
         message.save()
         self.messages.append(message)
         return message
     else:
         print("Пользователь {} не является участником чата {}".format(sender.name, self.id))
Exemplo n.º 2
0
 def getChatByParticipants(cls, owner, participant):
     conn = pymysql.connect(host=HOST,
                            user=USER,
                            password=PASSWORD,
                            db=DB,
                            charset=CHARSET,
                            cursorclass=CURSORCLASS)
     cur = conn.cursor()
     cur.execute("""select c.owner, c.chatid, cp1.chatid, cp1.participant, cp2.participant from messenger.chat c
                 join messenger.chat_participants cp1 on c.chatid = cp1.chatid
                 join messenger.chat_participants cp2 on cp1.chatid = cp2.chatid
                 where %s = cp1.participant and %s = cp2.participant;""", (owner.id, participant.id))
     res = cur.fetchall()
     if res:
         chat = Chat(owner)
         chat.id = int(res[0]['chatid'])
         chat.owner = owner
         chat.participants = [res[0]['participant'], res[0]['cp2.participant']]
         chat.messages = Mess.getMessagesByChat(chat.id)
     else:
         chat = None
     return chat
Exemplo n.º 3
0
 def addMessage(self, sender, text):
     if sender in self.participants or sender == self.owner:
         message = Mess(sender, text, self.id)
         self.messages.append(message)
     else:
         print("Пользователь {} не является участником чата".format(sender.name))