Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mrDoctorWho/vk4xmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Smith <mrdoctorwho@helldev.net>2020-10-19 17:27:48 +0300
committerJohn Smith <mrdoctorwho@helldev.net>2020-10-19 17:27:48 +0300
commite8c4d095e1abf3a64583e5395f6d5a48922b0dd2 (patch)
tree7ea7727dab107b85f3a8eca7d48b89d0f6c6fdbe
parentc82b8d958cccdefb7e271871ac6a9491885ae627 (diff)
Fix RuntimeError in groupchats; Add limit to groupchats' users count
-rw-r--r--extensions/groupchats.README.md7
-rw-r--r--extensions/groupchats.py7
2 files changed, 11 insertions, 3 deletions
diff --git a/extensions/groupchats.README.md b/extensions/groupchats.README.md
index b08124e..8463702 100644
--- a/extensions/groupchats.README.md
+++ b/extensions/groupchats.README.md
@@ -1,13 +1,16 @@
Installation
====
-The extension “groupchats” requires up to 2 fields in the main config:
+The extension “groupchats” requires up to 3 fields in the main config:
1. ConferenceServer — the address of your (or not your?) conference server
Bear in mind that there can be limits on the jabber server for conference per jid. Read the wiki for more details.
-2. CHAT_LIFETIME_LIMIT — the limit of the time after that chat considered inactive and will be removed. Time must be formatted as text and contain the time measurement variables after the digits.
+2. CHAT_USERS_LIMIT — the limit of users per chat. 50 is the default.
+
+3. CHAT_LIFETIME_LIMIT — the limit of the time after that chat considered inactive and will be removed. Time must be formatted as text and contain the time measurement variables after the digits.
+
For example:
diff --git a/extensions/groupchats.py b/extensions/groupchats.py
index 86611ed..aa4fff1 100644
--- a/extensions/groupchats.py
+++ b/extensions/groupchats.py
@@ -30,6 +30,7 @@ CHAT_CLEANUP_DELAY = 86400 # 24 hours
MIN_CHAT_ID = 2000000000
OWNER_FALLBACK = 210700286
+
if not require("attachments") or not require("forwarded_messages"):
raise RuntimeError("extension 'groupchats' requires 'forwarded_messages' and 'attachments'")
@@ -406,6 +407,8 @@ class Chat(object):
Get vk chat by id
"""
chat = user.vk.method("messages.getChat", {"chat_id": id})
+ users = chat.get("users", [])
+ users = sorted(users[:CHAT_USERS_LIMIT])
if not chat:
raise RuntimeError("Unable to get a chat!")
return chat
@@ -448,7 +451,7 @@ class Chat(object):
@staticmethod
def getUserByID(id):
- for jid, user in Users.iteritems():
+ for user in Users.values():
if hasattr(user, "vk"):
if user.vk.getUserPreferences()[0] == id:
return user
@@ -556,6 +559,8 @@ def initChatExtension():
cleanTheChatsUp()
else:
logger.warning("not starting chats cleaner because CHAT_LIFETIME_LIMIT is not set")
+ if not isdef("CHAT_USERS_LIMIT"):
+ CHAT_USERS_LIMIT = 50
if isdef("ConferenceServer") and ConferenceServer: