Add message limit
This commit is contained in:
parent
b03c7c75a4
commit
f38c62e8db
2 changed files with 18 additions and 6 deletions
|
|
@ -7,7 +7,14 @@ class Messages():
|
|||
Message storage class which preserves thread hierarchy.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, message_limit=500):
|
||||
"""
|
||||
message_limit - maximum amount of messages that will be stored at a time
|
||||
None - no limit
|
||||
"""
|
||||
|
||||
self.message_limit = message_limit
|
||||
|
||||
self._by_id = {}
|
||||
self._by_parent = {}
|
||||
|
||||
|
|
@ -46,6 +53,9 @@ class Messages():
|
|||
if not mes.parent in self._by_parent:
|
||||
self._by_parent[mes.parent] = []
|
||||
self._by_parent[mes.parent].append(mes)
|
||||
|
||||
if self.message_limit and len(self._by_id) > self.message_limit:
|
||||
self.remove(self.get_oldest().id)
|
||||
|
||||
def remove(self, mid):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -26,11 +26,13 @@ class Room():
|
|||
sessions - session data has changed
|
||||
"""
|
||||
|
||||
def __init__(self, room, nick=None, password=None):
|
||||
def __init__(self, room, nick=None, password=None, message_limit=500):
|
||||
"""
|
||||
room - name of the room to connect to
|
||||
nick - nick to assume, None -> no nick
|
||||
password - room password (in case the room is private)
|
||||
room - name of the room to connect to
|
||||
nick - nick to assume, None -> no nick
|
||||
password - room password (in case the room is private)
|
||||
message_limit - maximum amount of messages that will be stored at a time
|
||||
None - no limit
|
||||
"""
|
||||
|
||||
self.room = room
|
||||
|
|
@ -46,7 +48,7 @@ class Room():
|
|||
self.ping_next = 0
|
||||
self.ping_offset = 0 # difference between server and local time
|
||||
|
||||
self._messages = messages.Messages()
|
||||
self._messages = messages.Messages(message_limit=message_limit)
|
||||
self._sessions = sessions.Sessions()
|
||||
self._callbacks = callbacks.Callbacks()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue