This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
The following commit(s) were added to refs/heads/master by this push:
new 9487acb Make BODY_MAXLEN a config constant
9487acb is described below
commit 9487acb6483975d311888f7552f4e49cf6625a07
Author: Sebb <[email protected]>
AuthorDate: Sun Nov 14 17:21:35 2021 +0000
Make BODY_MAXLEN a config constant
---
server/endpoints/stats.py | 3 ++-
server/plugins/configuration.py | 1 +
server/plugins/messages.py | 8 +++-----
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/server/endpoints/stats.py b/server/endpoints/stats.py
index c243aaf..71fbe5c 100644
--- a/server/endpoints/stats.py
+++ b/server/endpoints/stats.py
@@ -47,7 +47,8 @@ async def process(
except AssertionError as e: # If defuzzer encounters syntax errors, it
will throw an AssertionError
return aiohttp.web.Response(headers={"content-type": "text/plain",},
status=500, text=str(e))
results = await plugins.messages.query(
- session, query_defuzzed, query_limit=server.config.database.max_hits,
shorten=True,
+ session, query_defuzzed, query_limit=server.config.database.max_hits,
+ body_max_len=server.config.ui.BODY_MAXLEN,
)
# statsOnly: Whether to only send statistical info (for n-grams etc), and
not the
diff --git a/server/plugins/configuration.py b/server/plugins/configuration.py
index 7fd47a5..8e0c444 100644
--- a/server/plugins/configuration.py
+++ b/server/plugins/configuration.py
@@ -41,6 +41,7 @@ class UIConfig:
mgmt_enabled: bool
focus_domain: str
fully_delete: bool
+ BODY_MAXLEN = 200 # largest body to show in thread display
def __init__(self, subyaml: dict):
self.wordcloud = bool(subyaml.get("wordcloud", False))
diff --git a/server/plugins/messages.py b/server/plugins/messages.py
index 404fa33..1884baf 100644
--- a/server/plugins/messages.py
+++ b/server/plugins/messages.py
@@ -45,8 +45,6 @@ ESCAPES_RE = re.compile(r'[\\"]') # Characters to escape
with backslash in make
mbox_cache_privacy: typing.Dict[str, bool] = {}
-BODY_MAXLEN = 200 # TODO: make this a config item
-
# Only these fields are returned by the API:
# (keep this list sorted)
USED_UI_FIELDS = [
@@ -351,7 +349,7 @@ async def query(
session: plugins.session.SessionObject,
query_defuzzed,
query_limit=10000,
- shorten=False,
+ body_max_len=None,
hide_deleted=True,
metadata_only=False,
epoch_order="desc"
@@ -388,8 +386,8 @@ async def query(
if not session.credentials:
doc = anonymize(doc)
if not metadata_only:
- if shorten and len(doc["body_short"] or "") > BODY_MAXLEN:
- doc["body"] = doc["body_short"][:BODY_MAXLEN] + '...'
+ if body_max_len and len(doc["body_short"] or "") >
body_max_len:
+ doc["body"] = doc["body_short"][:body_max_len] + '...'
else:
doc["body"] = doc["body_short"]
del doc["body_short"]