mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
refactor: Making email_mirror independent of actions.
Moved truncate_body, truncate_content and truncate_topic to message.py.
This commit is contained in:
@@ -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]],
|
||||
|
||||
Reference in New Issue
Block a user