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

Commit aace0c6

Browse files
committed
Merge pull request #159 from tcharding/datastore_docstring
Added doc strins to MessageStore
2 parents 8ca79f8 + 5d485b6 commit aace0c6

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
@@ -362,6 +362,9 @@ def __init__(self):
362362

363363
def save_message(self, guid, handle, signed_pubkey, encryption_pubkey, subject,
364364
message_type, message, timestamp, avatar_hash, signature, is_outgoing):
365+
"""
366+
Store message in database.
367+
"""
365368
outgoing = 1 if is_outgoing else 0
366369
msgID = digest(message + str(timestamp)).encode("hex")
367370
cursor = self.db.cursor()
@@ -372,13 +375,22 @@ def save_message(self, guid, handle, signed_pubkey, encryption_pubkey, subject,
372375
self.db.commit()
373376

374377
def get_messages(self, guid, message_type):
378+
"""
379+
Return all messages matching guid and message_type.
380+
"""
375381
cursor = self.db.cursor()
376382
cursor.execute('''SELECT guid, handle, signedPubkey, encryptionPubkey, subject, messageType, message,
377383
timestamp, avatarHash, signature, outgoing, read FROM messages WHERE guid=? AND messageType=?''',
378384
(guid, message_type))
379385
return cursor.fetchall()
380386

381387
def get_conversations(self):
388+
"""
389+
Get all 'conversations' composed of messages of type 'CHAT'.
390+
391+
Returns:
392+
Array of dictionaries, one element for each guid. Dictionaries
393+
include last message only."""
382394
cursor = self.db.cursor()
383395
cursor.execute('''SELECT DISTINCT guid FROM messages''',)
384396
guids = cursor.fetchall()
@@ -398,6 +410,9 @@ def get_conversations(self):
398410
return ret
399411

400412
def get_unread(self):
413+
"""
414+
Get Counter of guids which have unread, incoming messages.
415+
"""
401416
cursor = self.db.cursor()
402417
cursor.execute('''SELECT guid FROM messages WHERE read=0 and outgoing=0''',)
403418
ret = []
@@ -407,11 +422,17 @@ def get_unread(self):
407422
return Counter(ret)
408423

409424
def mark_as_read(self, guid):
425+
"""
426+
Mark all messages for guid as read.
427+
"""
410428
cursor = self.db.cursor()
411429
cursor.execute('''UPDATE messages SET read=? WHERE guid=?;''', (1, guid))
412430
self.db.commit()
413431

414432
def delete_message(self, guid):
433+
"""
434+
Delete all messages of type 'CHAT' for guid.
435+
"""
415436
cursor = self.db.cursor()
416437
cursor.execute('''DELETE FROM messages WHERE guid=? AND messageType="CHAT"''', (guid, ))
417438
self.db.commit()

0 commit comments

Comments
 (0)