comparison src/memory/memory.py @ 1955:633b5c21aefd

backend, frontend: messages refactoring (huge commit, not finished): /!\ database schema has been modified, do a backup before updating message have been refactored, here are the main changes: - languages are now handled - all messages have an uid (internal to SàT) - message updating is anticipated - subject is now first class - new naming scheme is used newMessage => messageNew, getHistory => historyGet, sendMessage => messageSend - minimal compatibility refactoring in quick_frontend/Primitivus, better refactoring should follow - threads handling - delayed messages are saved into history - info messages may also be saved in history (e.g. to keep track of people joining/leaving a room) - duplicate messages should be avoided - historyGet return messages in right order, no need to sort again - plugins have been updated to follow new features, some of them need to be reworked (e.g. OTR) - XEP-0203 (Delayed Delivery) is now fully handled in core, the plugin just handle disco and creation of a delay element - /!\ jp and Libervia are currently broken, as some features of Primitivus It has been put in one huge commit to avoid breaking messaging between changes. This is the main part of message refactoring, other commits will follow to take profit of the new features/behaviour.
author Goffi <goffi@goffi.org>
date Tue, 24 May 2016 22:11:04 +0200
parents 2daf7b4c6756
children a2bc5089c2eb
comparison
equal deleted inserted replaced
1943:ccfe45302a5c 1955:633b5c21aefd
508 d.addCallback(cleanMemory) 508 d.addCallback(cleanMemory)
509 return d 509 return d
510 510
511 ## History ## 511 ## History ##
512 512
513 def addToHistory(self, from_jid, to_jid, message, type_='chat', extra=None, timestamp=None, profile=C.PROF_KEY_NONE): 513 def addToHistory(self, client, data):
514 assert profile != C.PROF_KEY_NONE 514 return self.storage.addToHistory(data, client.profile)
515 if extra is None: 515
516 extra = {} 516 def historyGet(self, from_jid, to_jid, limit=C.HISTORY_LIMIT_NONE, between=True, search=None, profile=C.PROF_KEY_NONE):
517 return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile)
518
519 def getHistory(self, from_jid, to_jid, limit=C.HISTORY_LIMIT_NONE, between=True, search=None, profile=C.PROF_KEY_NONE):
520 """Retrieve messages in history 517 """Retrieve messages in history
518
521 @param from_jid (JID): source JID (full, or bare for catchall) 519 @param from_jid (JID): source JID (full, or bare for catchall)
522 @param to_jid (JID): dest JID (full, or bare for catchall) 520 @param to_jid (JID): dest JID (full, or bare for catchall)
523 @param limit (int): maximum number of messages to get: 521 @param limit (int): maximum number of messages to get:
524 - 0 for no message (returns the empty list) 522 - 0 for no message (returns the empty list)
525 - C.HISTORY_LIMIT_NONE or None for unlimited 523 - C.HISTORY_LIMIT_NONE or None for unlimited
526 - C.HISTORY_LIMIT_DEFAULT to use the HISTORY_LIMIT parameter value 524 - C.HISTORY_LIMIT_DEFAULT to use the HISTORY_LIMIT parameter value
527 @param between (bool): confound source and dest (ignore the direction) 525 @param between (bool): confound source and dest (ignore the direction)
528 @param search (str): pattern to filter the history results 526 @param search (str): pattern to filter the history results
529 @param profile (str): %(doc_profile)s 527 @param profile (str): %(doc_profile)s
530 @return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory 528 @return: list of message data as in [messageNew]
531 """ 529 """
532 assert profile != C.PROF_KEY_NONE 530 assert profile != C.PROF_KEY_NONE
533 if limit == C.HISTORY_LIMIT_DEFAULT: 531 if limit == C.HISTORY_LIMIT_DEFAULT:
534 limit = int(self.getParamA(C.HISTORY_LIMIT, 'General', profile_key=profile)) 532 limit = int(self.getParamA(C.HISTORY_LIMIT, 'General', profile_key=profile))
535 elif limit == C.HISTORY_LIMIT_NONE: 533 elif limit == C.HISTORY_LIMIT_NONE:
536 limit = None 534 limit = None
537 if limit == 0: 535 if limit == 0:
538 return defer.succeed([]) 536 return defer.succeed([])
539 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, search, profile) 537 return self.storage.historyGet(jid.JID(from_jid), jid.JID(to_jid), limit, between, search, profile)
540 538
541 ## Statuses ## 539 ## Statuses ##
542 540
543 def _getPresenceStatuses(self, profile_key): 541 def _getPresenceStatuses(self, profile_key):
544 ret = self.getPresenceStatuses(profile_key) 542 ret = self.getPresenceStatuses(profile_key)