diff --git a/tests/ui_tools/test_popups.py b/tests/ui_tools/test_popups.py index 2c5ce92d84..c75b1ab745 100644 --- a/tests/ui_tools/test_popups.py +++ b/tests/ui_tools/test_popups.py @@ -1398,9 +1398,11 @@ def test_stream_info_content__email_copy_text( general_stream: Dict[str, Any], stream_email_present: bool, expected_copy_text: str, + mocker: MockerFixture, ) -> None: if not stream_email_present: del general_stream["email_address"] + self.controller.model.stream_copy_text.return_value = "" model = self.controller.model stream_id = general_stream["stream_id"] diff --git a/zulipterminal/model.py b/zulipterminal/model.py index 22988c609b..9086e1fd84 100644 --- a/zulipterminal/model.py +++ b/zulipterminal/model.py @@ -891,6 +891,30 @@ def topics_in_stream(self, stream_id: int) -> List[str]: return list(self.index["topics"][stream_id]) + def _fetch_stream_email_address(self, stream_id: int) -> str: + """ + Fetch stream's email address with specified stream_id and + returns stream_email_address as a String. + Endpoint added in Zulip 7.5 (ZFL 226) + """ + url = f"/streams/{stream_id}/email_address" + + response = self.client.call_endpoint(url, method="GET") + + if response.get("result") == "success": + email_address = response.get("email", "") + return str(email_address) + return "" + + def stream_copy_text(self, stream_id: int) -> str: + stream = self.stream_dict[stream_id] + stream_email = stream.get("email_address", None) + if stream_email is None: + stream_email = self._fetch_stream_email_address(stream_id) + if stream_email == "" or stream_email is None: + stream_email = "" + return stream_email + @staticmethod def exception_safe_result(future: "Future[str]") -> str: try: diff --git a/zulipterminal/ui_tools/views.py b/zulipterminal/ui_tools/views.py index a5a0221f41..5839555d6a 100644 --- a/zulipterminal/ui_tools/views.py +++ b/zulipterminal/ui_tools/views.py @@ -1381,11 +1381,13 @@ def __init__(self, controller: Any, stream_id: int) -> None: ) member_keys = ", ".join(map(repr, keys_for_command("STREAM_MEMBERS"))) - # FIXME: This field was removed from the subscription data in Zulip 7.5 / ZFL226 - # We should use the new /streams/{stream_id}/email_address endpoint instead - self._stream_email = stream.get("email_address", None) - if self._stream_email is None: + # This field was removed from the subscription data in Zulip 7.5 / ZFL226 + # Using the new /streams/{stream_id}/email_address endpoint + # if field isn't present in subscription data + self._stream_email = controller.model.stream_copy_text(stream_id) + if self._stream_email == "": stream_copy_text = "< Stream email is unavailable >" + self._stream_email = None else: email_keys = ", ".join(map(repr, keys_for_command("COPY_STREAM_EMAIL"))) stream_copy_text = f"Press {email_keys} to copy Stream email address"