@@ -356,6 +356,9 @@ def __init__(self):
356
356
357
357
def save_message (self , guid , handle , signed_pubkey , encryption_pubkey , subject ,
358
358
message_type , message , timestamp , avatar_hash , signature , is_outgoing ):
359
+ """
360
+ Store message in database.
361
+ """
359
362
outgoing = 1 if is_outgoing else 0
360
363
cursor = self .db .cursor ()
361
364
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,
365
368
self .db .commit ()
366
369
367
370
def get_messages (self , guid , message_type ):
371
+ """
372
+ Return all messages matching guid and message_type.
373
+ """
368
374
cursor = self .db .cursor ()
369
375
cursor .execute ('''SELECT guid, handle, signedPubkey, encryptionPubkey, subject, messageType, message,
370
376
timestamp, avatarHash, signature, outgoing, read FROM messages WHERE guid=? AND messageType=?''' ,
371
377
(guid , message_type ))
372
378
return cursor .fetchall ()
373
379
374
380
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."""
375
387
cursor = self .db .cursor ()
376
388
cursor .execute ('''SELECT DISTINCT guid FROM messages''' ,)
377
389
guids = cursor .fetchall ()
@@ -391,6 +403,9 @@ def get_conversations(self):
391
403
return ret
392
404
393
405
def get_unread (self ):
406
+ """
407
+ Get Counter of guids which have unread, incoming messages.
408
+ """
394
409
cursor = self .db .cursor ()
395
410
cursor .execute ('''SELECT guid FROM messages WHERE read=0 and outgoing=0''' ,)
396
411
ret = []
@@ -400,11 +415,17 @@ def get_unread(self):
400
415
return Counter (ret )
401
416
402
417
def mark_as_read (self , guid ):
418
+ """
419
+ Mark all messages for guid as read.
420
+ """
403
421
cursor = self .db .cursor ()
404
422
cursor .execute ('''UPDATE messages SET read=? WHERE guid=?;''' , (1 , guid ))
405
423
self .db .commit ()
406
424
407
425
def delete_message (self , guid ):
426
+ """
427
+ Delete all messages of type 'CHAT' for guid.
428
+ """
408
429
cursor = self .db .cursor ()
409
430
cursor .execute ('''DELETE FROM messages WHERE guid=? AND messageType="CHAT"''' , (guid , ))
410
431
self .db .commit ()
0 commit comments