예제 #1
0
 def read_message(self, msg_list):
     count = 0
     c = self.__conn.cursor()
     c.execute(
         "SELECT id,from_user,from_nick,from_remark,to_user,to_nick,content,recvtime,reply,sendtime,status FROM message WHERE status=0 ORDER BY id LIMIT 5"
     )
     rows = c.fetchall()
     if not rows:
         return count
     for row in rows:
         msg = Message()
         msg.id = row[0]
         msg.from_user = row[1]
         msg.from_nick = row[2]
         msg.from_remark = row[3]
         msg.to_user = row[4]
         msg.to_nick = row[5]
         msg.content = row[6]
         msg.recvtime = row[7]
         msg.reply = row[8]
         msg.sendtime = row[9]
         msg.status = row[10]
         msg_list.append(msg)
         count = count + 1
         print("read message id " + str(msg.id))
         if count > 10:
             break
     return count
예제 #2
0
def text_reply(msg):
    '''
    print "MsgType: " + str(msg.MsgType)
    print "MsgId: " + str(msg.MsgId)
    print "FromUserName: "******"ToUserName: "******"Content: " + msg.Content
    print "Message: " + msg.text
    print "Actual Nick Name: " + msg.actualNickName
    print "IsAt: " + str(msg.isAt)
    '''
    # if msg.isAt:
    print "New Message: " + msg.text
    m = Message()
    m.id = 0
    m.from_user = msg.FromUserName
    m.from_nick = msg.actualNickName
    m.from_remark = ChatDB.get_remark_by_userid(m.from_user)
    m.to_user = msg.ToUserName
    m.to_nick = ChatDB.get_nickname_by_userid(m.to_user)
    m.content = msg.Content
    m.recvtime = get_cur_time()
    m.status = 0
    ChatDB.save_new_message(m)
    # msg.user.send(u'@%s\u2005I received: %s' % (msg.actualNickName, msg.text))
    pass
 def all(self):
     messagers = []
     for id, data in self._db.items():
         m = Message(data['name'], data['message'])
         m.id = str(id)
         messagers.append(m)
     messagers.sort(key=lambda x: x.id)
     return messagers
예제 #4
0
def test_insert_message():
    for i in range(1, 2):
        msg = Message()
        msg.id = 0
        msg.from_user = "******"
        msg.from_nick = "常胜将军"
        msg.to_user = "******"
        msg.to_nick = "李四"
        msg.content = "1,大,200"
        # msg.content = "取消"
        msg.recvtime = get_cur_time()
        msg.status = 0
        last_id = ChatDB.save_new_message(msg)
        print("Message ID inserted is " + str(last_id))

        msg.id = last_id
        msg.reply = "success"
        msg.sendtime = get_cur_time()
        msg.status = 2
        # ChatDB.update_reply_message(msg)
    pass
예제 #5
0
 def _persist_message(self):
     if session.query(Message).filter(Message.id == self.messageid).count() != 0:
         print 'Message with ID = (' + self.messageid + ') has already been persisted.  Skipping.'
         raise Exception()
     m = Message()
     m.id = self.messageid
     m.inreplyto = self.inreplyto
     m.fromcontact_email = self.msgfrom['email']
     m.size = self.size
     m.subject = self.subject
     m.msgdate = self.date
     session.add(m)
     session.commit()
예제 #6
0
 def _persist_message(self):
     if session.query(Message).filter(
             Message.id == self.messageid).count() != 0:
         print 'Message with ID = (' + self.messageid + ') has already been persisted.  Skipping.'
         raise Exception()
     m = Message()
     m.id = self.messageid
     m.inreplyto = self.inreplyto
     m.fromcontact_email = self.msgfrom['email']
     m.size = self.size
     m.subject = self.subject
     m.msgdate = self.date
     session.add(m)
     session.commit()
예제 #7
0
파일: app.py 프로젝트: alongigi/DogsTinder
def send_message(json, methods=['GET', 'POST']):
    print('received my event: ' + str(json))
    sender_username = get_user_logged_in()
    # check if there is a receiver for the message before sending
    #if 'CHAT_ROOM' in session:
    #  receiver_username = session.get('CHAT_ROOM', None)
    if sender_username in chatClients:
        receiver_username = chatClients[sender_username].split("#")[1]
        content = json['message']
        sending_date = datetime.now()
        sending_date_formated = sending_date.strftime('%Y-%m-%d %H:%M:%S')

        print(
            f'message: {content} from { sender_username } to { receiver_username }'
        )

        # insert message to db
        msg = Message(sender_username, receiver_username, content,
                      sending_date_formated, 'False')
        msg.id = add_message_to_db(msg)

        if msg.id:
            print(f'Message {msg.id} was inserted')

            # get template of message
            msgArray = [[
                msg.id, msg.sender, msg.receiver, msg.content, sending_date
            ]]
            # approve message was sent to the client
            # if sender_username in chatClients and chatClients[sender_username].split("#")[1] == receiver_username:
            socketio.emit('message_received',
                          render_template('chatMessages.html',
                                          messages=msgArray),
                          room=chatClients[sender_username])

            # make sure receiver is in chat room with the sender
            if receiver_username in chatClients and chatClients[
                    receiver_username].split("#")[1] == sender_username:
                socketio.emit('message_received',
                              render_template('chatMessages.html',
                                              messages=msgArray,
                                              logged_in_user=msg.receiver),
                              room=chatClients[receiver_username])
        else:
            print('insertion failed')
    else:
        print('chat room wasnt open with the receiver')
예제 #8
0
파일: app.py 프로젝트: morbitton/DogsTinder
def send_message(msg: Message, include_sender:bool):
    # insert message to db
    msg.id = add_message_to_db(msg)

    # send message to client and reciever if insertion succeeded
    if msg.id:
        print(f'Message {msg.id} was inserted')

         # get template of message
        msgArray = [[msg.id, msg.sender, msg.receiver, msg.content, msg.date]]

        if include_sender:
            # approve message was sent to the client
            socketio.emit('message_received', render_template('chatMessages.html', messages=msgArray), room=chatClients[msg.sender])

        # make sure receiver is in chat room with the sender
        if msg.receiver in chatClients and chatClients[msg.receiver].split("#")[1] == msg.sender:
            socketio.emit('message_received', render_template('chatMessages.html', messages=msgArray, logged_in_user=msg.receiver), room=chatClients[msg.receiver])
    else:
        print('insertion failed')