memory: add Parameter "Chat history limit"
This commit is contained in:
parent
4c61bf8fad
commit
4f339272b7
3 changed files with 50 additions and 18 deletions
|
|
@ -350,8 +350,25 @@ class Memory(object):
|
|||
extra = {}
|
||||
return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile)
|
||||
|
||||
def getHistory(self, from_jid, to_jid, limit=None, between=True, profile=C.PROF_KEY_NONE):
|
||||
def getHistory(self, from_jid, to_jid, limit=C.HISTORY_LIMIT_NONE, between=True, profile=C.PROF_KEY_NONE):
|
||||
"""Retrieve messages in history
|
||||
@param from_jid (JID): source JID (full, or bare for catchall)
|
||||
@param to_jid (JID): dest JID (full, or bare for catchall)
|
||||
@param limit (int): maximum number of messages to get:
|
||||
- 0 for no message (returns the empty list)
|
||||
- C.HISTORY_LIMIT_NONE or None for unlimited
|
||||
- C.HISTORY_LIMIT_DEFAULT to use the HISTORY_LIMIT parameter value
|
||||
@param between (bool): confound source and dest (ignore the direction)
|
||||
@param profile (str): %(doc_profile)s
|
||||
@return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory
|
||||
"""
|
||||
assert profile != C.PROF_KEY_NONE
|
||||
if limit == C.HISTORY_LIMIT_DEFAULT:
|
||||
limit = int(self.getParamA(C.HISTORY_LIMIT, 'General', profile_key=profile))
|
||||
elif limit == C.HISTORY_LIMIT_NONE:
|
||||
limit = None
|
||||
if limit == 0:
|
||||
return defer.succeed([])
|
||||
return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile)
|
||||
|
||||
def _getLastResource(self, jid_s, profile_key):
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from sat.core.i18n import _
|
||||
from sat.core.i18n import _, D_
|
||||
|
||||
from sat.core import exceptions
|
||||
from sat.core.constants import Const as C
|
||||
|
|
@ -44,6 +44,7 @@ class Params(object):
|
|||
<individual>
|
||||
<category name="General" label="%(category_general)s">
|
||||
<param name="Password" value="" type="password" />
|
||||
<param name="%(history_param)s" label="%(label_history)s" value="20" min="0" max="100" type="int" security="0" />
|
||||
</category>
|
||||
<category name="Connection" label="%(category_connection)s">
|
||||
<param name="JabberID" value="name@example.org/SàT" type="string" />
|
||||
|
|
@ -61,12 +62,14 @@ class Params(object):
|
|||
</individual>
|
||||
</params>
|
||||
""" % {
|
||||
'category_general': _("General"),
|
||||
'category_connection': _("Connection"),
|
||||
'label_NewAccount': _("Register new account"),
|
||||
'label_autoconnect': _('Connect on frontend startup'),
|
||||
'label_autodisconnect': _('Disconnect on frontend closure'),
|
||||
'category_misc': _("Misc"),
|
||||
'category_general': D_("General"),
|
||||
'category_connection': D_("Connection"),
|
||||
'history_param': C.HISTORY_LIMIT,
|
||||
'label_history': D_('Chat history limit'),
|
||||
'label_NewAccount': D_("Register new account"),
|
||||
'label_autoconnect': D_('Connect on frontend startup'),
|
||||
'label_autodisconnect': D_('Disconnect on frontend closure'),
|
||||
'category_misc': D_("Misc"),
|
||||
'force_server_param': C.FORCE_SERVER_PARAM,
|
||||
'force_port_param': C.FORCE_PORT_PARAM,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -265,10 +265,15 @@ class SqliteStorage(object):
|
|||
return d
|
||||
|
||||
def getHistory(self, from_jid, to_jid, limit=None, between=True, profile=None):
|
||||
"""Store a new message in history
|
||||
@param from_jid: source JID (full, or bare for catchall
|
||||
@param to_jid: dest JID (full, or bare for catchall
|
||||
@param size: maximum number of messages to get, or None for unlimited
|
||||
"""Retrieve messages in history
|
||||
@param from_jid (JID): source JID (full, or bare for catchall)
|
||||
@param to_jid (JID): dest JID (full, or bare for catchall)
|
||||
@param limit (int): maximum number of messages to get:
|
||||
- 0 for no message (returns the empty list)
|
||||
- None for unlimited
|
||||
@param between (bool): confound source and dest (ignore the direction)
|
||||
@param profile (str): %(doc_profile)s
|
||||
@return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory
|
||||
"""
|
||||
assert(profile)
|
||||
if limit == 0:
|
||||
|
|
|
|||
Loading…
Reference in a new issue