Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 5d485b6

Browse files
committed
Added doc strins to MessageStore
1 parent 0596593 commit 5d485b6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

db/datastore.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@ def __init__(self):
356356

357357
def save_message(self, guid, handle, signed_pubkey, encryption_pubkey, subject,
358358
message_type, message, timestamp, avatar_hash, signature, is_outgoing):
359+
"""
360+
Store message in database.
361+
"""
359362
outgoing = 1 if is_outgoing else 0
360363
cursor = self.db.cursor()
361364
cursor.execute('''INSERT INTO messages(guid, handle, signedPubkey, encryptionPubkey, subject,
@@ -365,13 +368,22 @@ def save_message(self, guid, handle, signed_pubkey, encryption_pubkey, subject,
365368
self.db.commit()
366369

367370
def get_messages(self, guid, message_type):
371+
"""
372+
Return all messages matching guid and message_type.
373+
"""
368374
cursor = self.db.cursor()
369375
cursor.execute('''SELECT guid, handle, signedPubkey, encryptionPubkey, subject, messageType, message,
370376
timestamp, avatarHash, signature, outgoing, read FROM messages WHERE guid=? AND messageType=?''',
371377
(guid, message_type))
372378
return cursor.fetchall()
373379

374380
def get_conversations(self):
381+
"""
382+
Get all 'conversations' composed of messages of type 'CHAT'.
383+
384+
Returns:
385+
Array of dictionaries, one element for each guid. Dictionaries
386+
include last message only."""
375387
cursor = self.db.cursor()
376388
cursor.execute('''SELECT DISTINCT guid FROM messages''',)
377389
guids = cursor.fetchall()
@@ -391,6 +403,9 @@ def get_conversations(self):
391403
return ret
392404

393405
def get_unread(self):
406+
"""
407+
Get Counter of guids which have unread, incoming messages.
408+
"""
394409
cursor = self.db.cursor()
395410
cursor.execute('''SELECT guid FROM messages WHERE read=0 and outgoing=0''',)
396411
ret = []
@@ -400,11 +415,17 @@ def get_unread(self):
400415
return Counter(ret)
401416

402417
def mark_as_read(self, guid):
418+
"""
419+
Mark all messages for guid as read.
420+
"""
403421
cursor = self.db.cursor()
404422
cursor.execute('''UPDATE messages SET read=? WHERE guid=?;''', (1, guid))
405423
self.db.commit()
406424

407425
def delete_message(self, guid):
426+
"""
427+
Delete all messages of type 'CHAT' for guid.
428+
"""
408429
cursor = self.db.cursor()
409430
cursor.execute('''DELETE FROM messages WHERE guid=? AND messageType="CHAT"''', (guid, ))
410431
self.db.commit()

0 commit comments

Comments
 (0)