Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from zulipterminal.config.symbols import STREAM_TOPIC_SEPARATOR
from zulipterminal.helper import initial_index, powerset
from zulipterminal.model import (
DIRECT_MESSAGE_TYPE_FEATURE_LEVEL,
MAX_MESSAGE_LENGTH,
MAX_STREAM_NAME_LENGTH,
MAX_TOPIC_NAME_LENGTH,
Expand Down Expand Up @@ -908,17 +909,34 @@ def test_send_typing_status_avoided_due_to_user_setting(
({"result": "some_failure"}, False),
],
)
# AFTER
@pytest.mark.parametrize("recipients", [[5179], [5179, 5180]])
@pytest.mark.parametrize(
"feature_level, expected_type",
[
(DIRECT_MESSAGE_TYPE_FEATURE_LEVEL, "direct"),
(DIRECT_MESSAGE_TYPE_FEATURE_LEVEL - 1, "private"),
],
ids=["feature_level:direct_type", "feature_level:private_type"],
)
def test_send_private_message(
self, mocker, model, recipients, response, return_value, content="hi!"
self,
mocker,
model,
recipients,
response,
return_value,
feature_level,
expected_type,
content="hi!",
):
model.server_feature_level = feature_level
self.client.send_message = mocker.Mock(return_value=response)

result = model.send_private_message(recipients, content)

req = dict(type="private", to=recipients, content=content, read_by_sender=True)
req = dict(
type=expected_type, to=recipients, content=content, read_by_sender=True
)
self.client.send_message.assert_called_once_with(req)

assert result == return_value
self.display_error_if_present.assert_called_once_with(response, self.controller)
if result == "success":
Expand Down
2 changes: 1 addition & 1 deletion zulipterminal/api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
###############################################################################
# Core message types (used in Composition and Message below)

DirectMessageString = Literal["private"]
DirectMessageString = Literal["private", "direct"]
StreamMessageString = Literal["stream"]

MessageType = Union[DirectMessageString, StreamMessageString]
Expand Down
12 changes: 10 additions & 2 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import zulip
from bs4 import BeautifulSoup
from typing_extensions import TypedDict
from typing_extensions import Literal, TypedDict

from zulipterminal import unicode_emojis
from zulipterminal.api_types import (
Expand Down Expand Up @@ -101,6 +101,9 @@ class UserSettings(TypedDict):
pm_content_in_desktop_notifications: bool


DIRECT_MESSAGE_TYPE_FEATURE_LEVEL = 174


class Model:
"""
A class responsible for storing the data to be displayed.
Expand Down Expand Up @@ -540,8 +543,13 @@ def send_typing_status_by_user_ids(

def send_private_message(self, recipients: List[int], content: str) -> bool:
if recipients:
direct_message_type: Literal["private", "direct"] = (
"direct"
if self.server_feature_level >= DIRECT_MESSAGE_TYPE_FEATURE_LEVEL
else "private"
)
composition = PrivateComposition(
type="private",
type=direct_message_type,
to=recipients,
content=content,
read_by_sender=True,
Expand Down
Loading