@@ -362,6 +362,9 @@ def __init__(self):
362
362
363
363
def save_message (self , guid , handle , signed_pubkey , encryption_pubkey , subject ,
364
364
message_type , message , timestamp , avatar_hash , signature , is_outgoing ):
365
+ """
366
+ Store message in database.
367
+ """
365
368
outgoing = 1 if is_outgoing else 0
366
369
msgID = digest (message + str (timestamp )).encode ("hex" )
367
370
cursor = self .db .cursor ()
@@ -372,13 +375,22 @@ def save_message(self, guid, handle, signed_pubkey, encryption_pubkey, subject,
372
375
self .db .commit ()
373
376
374
377
def get_messages (self , guid , message_type ):
378
+ """
379
+ Return all messages matching guid and message_type.
380
+ """
375
381
cursor = self .db .cursor ()
376
382
cursor .execute ('''SELECT guid, handle, signedPubkey, encryptionPubkey, subject, messageType, message,
377
383
timestamp, avatarHash, signature, outgoing, read FROM messages WHERE guid=? AND messageType=?''' ,
378
384
(guid , message_type ))
379
385
return cursor .fetchall ()
380
386
381
387
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."""
382
394
cursor = self .db .cursor ()
383
395
cursor .execute ('''SELECT DISTINCT guid FROM messages''' ,)
384
396
guids = cursor .fetchall ()
@@ -398,6 +410,9 @@ def get_conversations(self):
398
410
return ret
399
411
400
412
def get_unread (self ):
413
+ """
414
+ Get Counter of guids which have unread, incoming messages.
415
+ """
401
416
cursor = self .db .cursor ()
402
417
cursor .execute ('''SELECT guid FROM messages WHERE read=0 and outgoing=0''' ,)
403
418
ret = []
@@ -407,11 +422,17 @@ def get_unread(self):
407
422
return Counter (ret )
408
423
409
424
def mark_as_read (self , guid ):
425
+ """
426
+ Mark all messages for guid as read.
427
+ """
410
428
cursor = self .db .cursor ()
411
429
cursor .execute ('''UPDATE messages SET read=? WHERE guid=?;''' , (1 , guid ))
412
430
self .db .commit ()
413
431
414
432
def delete_message (self , guid ):
433
+ """
434
+ Delete all messages of type 'CHAT' for guid.
435
+ """
415
436
cursor = self .db .cursor ()
416
437
cursor .execute ('''DELETE FROM messages WHERE guid=? AND messageType="CHAT"''' , (guid , ))
417
438
self .db .commit ()
0 commit comments