refactor: Making email_mirror independent of actions.

Moved truncate_body, truncate_content and truncate_topic
to message.py.
This commit is contained in:
Udit107710
2020-03-28 06:46:04 +00:00
committed by Tim Abbott
parent 16218d6de3
commit db30cf470c
4 changed files with 20 additions and 16 deletions

View File

@@ -51,6 +51,8 @@ from zerver.models import (
UserMessage,
Reaction,
get_usermessage_by_message_id,
MAX_MESSAGE_LENGTH,
MAX_TOPIC_NAME_LENGTH
)
from typing import Any, Dict, List, Optional, Set, Tuple, Sequence
@@ -81,6 +83,17 @@ UnreadMessagesResult = TypedDict('UnreadMessagesResult', {
# user has more older unread messages that were cut off.
MAX_UNREAD_MESSAGES = 50000
def truncate_content(content: str, max_length: int, truncation_message: str) -> str:
if len(content) > max_length:
content = content[:max_length - len(truncation_message)] + truncation_message
return content
def truncate_body(body: str) -> str:
return truncate_content(body, MAX_MESSAGE_LENGTH, "\n[message truncated]")
def truncate_topic(topic: str) -> str:
return truncate_content(topic, MAX_TOPIC_NAME_LENGTH, "...")
def messages_for_ids(message_ids: List[int],
user_message_flags: Dict[int, List[str]],
search_fields: Dict[int, Dict[str, str]],