created chat table structure and added messagetypes
This commit is contained in:
parent
0fca124cd8
commit
f04829eca0
|
@ -392,6 +392,22 @@ class sqlThread(threading.Thread):
|
|||
' and removing the hash field.')
|
||||
self.cur.execute('''update settings set value=10 WHERE key='version';''')
|
||||
|
||||
# Add a new table: chat and chatdata for storing chating conversation
|
||||
item = '''SELECT value FROM settings WHERE key='version';'''
|
||||
parameters = ''
|
||||
self.cur.execute(item, parameters)
|
||||
currentVersion = int(self.cur.fetchall()[0][0])
|
||||
if currentVersion == 10:
|
||||
self.cur.execute('''DROP TABLE chat''')
|
||||
self.cur.execute(
|
||||
'''CREATE TABLE chat'''
|
||||
''' (msgid blob, senderaddress text, receiveraddress text, message text,'''
|
||||
''' senttime text, receivedtime text, image blob, audio blob, reference blob,'''
|
||||
''' UNIQUE(msgid) ON CONFLICT REPLACE)''')
|
||||
item = '''update settings set value=? WHERE key='version';'''
|
||||
parameters = (11,)
|
||||
self.cur.execute(item, parameters)
|
||||
|
||||
# Are you hoping to add a new option to the keys.dat file of existing
|
||||
# Bitmessage users or modify the SQLite database? Add it right
|
||||
# above this line!
|
||||
|
|
|
@ -20,7 +20,7 @@ class MsgBase(object): # pylint: disable=too-few-public-methods
|
|||
|
||||
def constructObject(data):
|
||||
"""Constructing an object"""
|
||||
whitelist = ["message"]
|
||||
whitelist = ["message", "chatmsg"]
|
||||
if data[""] not in whitelist:
|
||||
return None
|
||||
try:
|
||||
|
|
34
src/messagetypes/chatmsg.py
Normal file
34
src/messagetypes/chatmsg.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
import logging
|
||||
|
||||
from messagetypes import MsgBase
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
|
||||
logger = logging.getLogger('default')
|
||||
|
||||
|
||||
class Chatmsg(MsgBase):
|
||||
"""Encapsulate a chatmsg"""
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
|
||||
def decode(self, data):
|
||||
"""Decode a message"""
|
||||
# UTF-8 and variable type validator
|
||||
if isinstance(data["message"], str):
|
||||
# Unicode is depreciated
|
||||
self.message = data["message"]
|
||||
else:
|
||||
# Unicode is depreciated
|
||||
self.message = str(data["message"])
|
||||
|
||||
def encode(self, data):
|
||||
"""Encode a message"""
|
||||
super(Chatmsg, self).__init__()
|
||||
try:
|
||||
self.data["message"] = data["message"]
|
||||
except KeyError as e:
|
||||
logger.error("Missing key %s", e)
|
||||
return self.data
|
||||
|
||||
def process(self):
|
||||
"""Process a message"""
|
||||
logger.debug("Message: %i bytes", len(self.message))
|
23
src/tests/test_chatmsg.py
Normal file
23
src/tests/test_chatmsg.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
"""
|
||||
Test for chatmsg group
|
||||
"""
|
||||
import unittest
|
||||
from messagetypes.chatmsg import Chatmsg
|
||||
|
||||
|
||||
class TestCharMessage(unittest.TestCase):
|
||||
"""
|
||||
Test case for chat message group
|
||||
"""
|
||||
def test_decode(self):
|
||||
"""Test various types of decode method"""
|
||||
chat_obj = Chatmsg()
|
||||
import messagetypes
|
||||
result = messagetypes.constructObject({'': 'chatmsg', 'message': 'hello world'})
|
||||
self.assertTrue(isinstance(result.message, str))
|
||||
|
||||
|
||||
def test_encode(self):
|
||||
chat_obj = Chatmsg()
|
||||
result = chat_obj.encode({'message':'hello world'})
|
||||
self.assertTrue(True if result['message'] else False)
|
Reference in New Issue
Block a user