various integration fixes

parent f36712e6
......@@ -140,6 +140,9 @@ class PyreQT(QMainWindow):
self.app.quit()
def send(self):
# ===================
# TODO: NEEDS REWRITE
# ===================
messageBody = self.messageEdit.text()
to = self.toLabel.text()
self.signald.send(self.username, to, messageBody)
......@@ -149,7 +152,7 @@ class PyreQT(QMainWindow):
timestamp = int(time.time())
thread = to
self.dbConnector.addMessage(thread, name, self.username, messageBody, None, timestamp, timestamp)
self.dbConnector.addMessage(thread, self.username, messageBody, None, timestamp)
# clear message box
self.messageEdit.setText("")
......@@ -227,6 +230,9 @@ class PyreQT(QMainWindow):
@pyqtSlot(dict)
def inboundMessage(self, message):
# ===================
# TODO: NEEDS REWRITE
# ===================
if message.get("dataMessage") == None:
return
......@@ -254,7 +260,7 @@ class PyreQT(QMainWindow):
# TODO: we should check for an attachment and include it in the database
attachments = message["attachments"]
self.dbConnector.addMessage(thread, name, number, messageText, attachments, timestamp, serverTimestamp)
self.dbConnector.addMessage(thread, number, messageText, attachments, timestamp)
# show tray notification
self.trayIcon.showMessage("PyreQT: "+name, messageText, QIcon("pyreqt/res/icon.png"))
......
......@@ -55,45 +55,46 @@ class dbConnector():
self.cursor.execute(self.updateContact, (i["name"], i["number"], i["color"]))
def addAttachment(self, filepath, filetype, messageid):
self.cursor.execute(self.insertAttachment, filetype, filepath)
self.cursor.execute(self.getAttachmentId, filepath)
self.cursor.execute(self.insertAttachment, (filetype, filepath))
self.cursor.execute(self.getAttachmentId, (filepath,))
attachmentId = self.cursor.fetchone()
if attachmentId == None:
# Maybe assertionerror?
raise IndexError("Could retrieve attachment id from fresh store operation!")
self.cursor.execute(self.insertAttachmentMapping, messageid, candidateId)
self.cursor.execute(self.insertAttachmentMapping, (messageid, candidateId))
def getAttachmentById(self, attachmentId):
self.cursor.execute(self.selectAttachmentById, attachmentId)
self.cursor.execute(self.selectAttachmentById, (attachmentId,))
def getAttachmentFromMessageId(self, messageId):
self.cursor.execute(self.selectAttachmentIdsFromMessageId, messageId)
self.cursor.execute(self.selectAttachmentIdsFromMessageId, (messageId,))
return [ [self.getAttachmentById(i)] for i in self.cursor.fetchall() ]
# returns Message ID
def addMessage(self, thread, sender, message, attachments, timestamp):
self.cursor.execute(self.insertMessage, sender, thread, message, timestamp)
self.cursor.execute(self.selectMessageId, sender, thread, message)
self.cursor.execute(self.insertMessage, (sender, thread, message, timestamp))
self.cursor.execute(self.selectMessageId, (sender, thread, message))
messageId = self.cursor.fetchone()
if messageId == None:
# Maybe assertionerror?
raise IndexError("Couldnt retrieve message id from fresh store operation!")
for i in attachments:
self.addAttachment(i["storedFilepath"], i["contentType"], messageId)
if not attachments == None:
for i in attachments:
self.addAttachment(i["storedFilepath"], i["contentType"], messageId)
self.connection.commit()
return messageId
def getContactNameFromId(self, contactId):
self.cursor.execute(self.selectContactName, contactId)
self.cursor.execute(self.selectContactName, (contactId,))
def retrieveThread(self, thread):
self.cursor.execute(self.selectMessageThread, thread)
return [ [self.getContactNameFromId(i[0]) or "Anonymous"]+i for i in self.cursor.fetchall() ]
self.cursor.execute(self.selectMessageThread, (thread,))
return [ [self.getContactNameFromId(i[0]) or "Anonymous"]+list(i) for i in self.cursor.fetchall() ]
def sync(self):
self.connection.commit()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment