Skip to content

Commit

Permalink
refactor: model: Use Composition api types when sending messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
neiljp committed Feb 18, 2021
1 parent 4678ef4 commit 8c27df5
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@
from typing_extensions import Literal

from zulipterminal import unicode_emojis
from zulipterminal.api_types import Composition, EditPropagateMode, Event
from zulipterminal.api_types import (
Composition,
EditPropagateMode,
Event,
PrivateComposition,
StreamComposition,
)
from zulipterminal.config.keys import primary_key_for_command
from zulipterminal.helper import (
Message,
Expand Down Expand Up @@ -378,26 +384,26 @@ def send_typing_status_by_user_ids(self, recipient_user_ids: List[int],
def send_private_message(self, recipients: List[str],
content: str) -> bool:
if recipients:
request = {
'type': 'private',
'to': recipients,
'content': content,
}
response = self.client.send_message(request)
composition = PrivateComposition(
type='private',
to=recipients,
content=content,
)
response = self.client.send_message(composition)
display_error_if_present(response, self.controller)
return response['result'] == 'success'
else:
raise RuntimeError('Empty recipients list.')

def send_stream_message(self, stream: str, topic: str,
content: str) -> bool:
request = {
'type': 'stream',
'to': stream,
'subject': topic,
'content': content,
}
response = self.client.send_message(request)
composition = StreamComposition(
type='stream',
to=stream,
subject=topic,
content=content,
)
response = self.client.send_message(composition)
display_error_if_present(response, self.controller)
return response['result'] == 'success'

Expand Down

0 comments on commit 8c27df5

Please sign in to comment.