Repository: zulip/zulip

Issue:
Starred messages view shows messages in inaccessible streams
If you star a message in a stream and either:
1. Unsub from the stream.
2. Deactivate the stream.

The message will stay visible in the Starred messages view even though it shouldn't. E.g. in the screenshot below you can see messages I starred - first one in a deactivated stream, second one in a private stream I unsubscribed from.
![image](https://user-images.githubusercontent.com/45007152/103225499-51842180-492a-11eb-922c-544404150248.png)



Discussion:
@sahil839 Would you be interested in looking into this?
Sure, I will fix this.
@zulipbot claim.
@sahil839 , Are you still working on this? I would like to contribute too.

Yes I am working on this. 
I am busy with college work, so I am abandoning this for now. WIll get back to this when I get time (if this will not be solved till then). Anyone who is taking this can have a look on the discussion [here](https://chat.zulip.org/#narrow/stream/9-issues/topic/.2316971.20starred.20messages.20view). @zulipbot abandon
@Pranav2612000 you can take this if you want.
I have gone through the discussions on  Zulip Community , i think i can fix this 
@zulipbot claim.
Hello @deto-5420!

Thanks for your interest in Zulip! You have attempted to claim an issue without the labels "help wanted", "good first issue". Since you're a new contributor, you can only claim and submit pull requests for issues with the [help wanted](https://github.com/zulip/zulip/issues?q=is%3Aopen+is%3Aissue+no%3Aassignee+label%3A%22help+wanted%22) or [good first issue](https://github.com/zulip/zulip/issues?q=is%3Aopen+is%3Aissue+no%3Aassignee+label%3A%22good+first+issue%22) labels.

If this is your first time here, we recommend reading our [guide for new contributors](https://zulip.readthedocs.io/en/latest/overview/contributing.html) before getting started.
@deto-5420 are you working on this issue. Can I start working over it, if you haven't?
@zulipbot claim
Looks like there is some misconversation @m-e-l-u-h-a-n .I am working on it which I mentioned in Czo. Thanks in advance.
Will let you know if I dismiss it.
Actually I just looked into the thread mentioned by sahil above but couldn't find your message there, sorry if you have started over it(please confirm) I will unclaim it.
Ohh I think you clarified you are still working on it in above message itself. Sorry I will unclaim it.
Hi @aryanshridhar , I hope everything is going well. I suggest claiming the issue and assigning it to you so it would be clear someone is working on it.
@aryanshridhar are you still working on this, Can I take this up if you are busy?

Resolving patch:
diff --git a/zerver/openapi/python_examples.py b/zerver/openapi/python_examples.py
--- a/zerver/openapi/python_examples.py
+++ b/zerver/openapi/python_examples.py
@@ -424,19 +424,19 @@ def get_stream_id(client: Client) -> int:
 
 
 @openapi_test_function("/streams/{stream_id}:delete")
-def delete_stream(client: Client, stream_id: int) -> None:
+def archive_stream(client: Client, stream_id: int) -> None:
     result = client.add_subscriptions(
         streams=[
             {
-                "name": "stream to be deleted",
+                "name": "stream to be archived",
                 "description": "New stream for testing",
             },
         ],
     )
 
     # {code_example|start}
-    # Delete the stream named 'stream to be deleted'
-    stream_id = client.get_stream_id("stream to be deleted")["stream_id"]
+    # Archive the stream named 'stream to be archived'
+    stream_id = client.get_stream_id("stream to be archived")["stream_id"]
     result = client.delete_stream(stream_id)
     # {code_example|end}
     validate_against_openapi_schema(result, "/streams/{stream_id}", "delete", "200")
@@ -1368,7 +1368,7 @@ def test_streams(client: Client, nonadmin_client: Client) -> None:
     update_subscription_settings(client)
     update_notification_settings(client)
     get_stream_topics(client, 1)
-    delete_stream(client, stream_id)
+    archive_stream(client, stream_id)
 
     test_user_not_authorized_error(nonadmin_client)
     test_authorization_errors_fatal(client, nonadmin_client)
diff --git a/zproject/urls.py b/zproject/urls.py
--- a/zproject/urls.py
+++ b/zproject/urls.py
@@ -764,6 +764,11 @@
     template_name="zerver/documentation_main.html", path_template="/zerver/api/%s.md"
 )
 urls += [
+    # Redirects due to us having moved the docs:
+    path(
+        "help/delete-a-stream", RedirectView.as_view(url="/help/archive-a-stream", permanent=True)
+    ),
+    path("api/delete-stream", RedirectView.as_view(url="/api/archive-stream", permanent=True)),
     path("help/", help_documentation_view),
     path("help/<path:article>", help_documentation_view),
     path("api/", api_documentation_view),


Test patch:
diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js
--- a/frontend_tests/node_tests/stream_data.js
+++ b/frontend_tests/node_tests/stream_data.js
@@ -418,7 +418,7 @@ test("delete_sub", () => {
     assert(!stream_data.get_sub("Canada"));
     assert(!stream_data.get_sub_by_id(canada.stream_id));
 
-    blueslip.expect("warn", "Failed to delete stream 99999");
+    blueslip.expect("warn", "Failed to archive stream 99999");
     stream_data.delete_sub(99999);
 });
 
diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py
--- a/zerver/lib/test_helpers.py
+++ b/zerver/lib/test_helpers.py
@@ -496,6 +496,8 @@ def find_pattern(pattern: Any, prefixes: List[str]) -> None:
             "confirmation_key/",
             "node-coverage/(?P<path>.+)",
             "docs/(?P<path>.+)",
+            "help/delete-a-stream",
+            "api/delete-stream",
             "casper/(?P<path>.+)",
             "static/(?P<path>.+)",
             "flush_caches",
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py
--- a/zerver/tests/test_subs.py
+++ b/zerver/tests/test_subs.py
@@ -1305,17 +1305,17 @@ def test_stream_message_retention_days_on_stream_creation(self) -> None:
         self.assertEqual(result[1][2].name, "new_stream3")
         self.assertEqual(result[1][2].message_retention_days, None)
 
-    def set_up_stream_for_deletion(
+    def set_up_stream_for_archiving(
         self, stream_name: str, invite_only: bool = False, subscribed: bool = True
     ) -> Stream:
         """
-        Create a stream for deletion by an administrator.
+        Create a stream for archiving by an administrator.
         """
         user_profile = self.example_user("hamlet")
         self.login_user(user_profile)
         stream = self.make_stream(stream_name, invite_only=invite_only)
 
-        # For testing deleting streams you aren't on.
+        # For testing archiving streams you aren't on.
         if subscribed:
             self.subscribe(user_profile, stream_name)
 
@@ -1323,9 +1323,9 @@ def set_up_stream_for_deletion(
 
         return stream
 
-    def delete_stream(self, stream: Stream) -> None:
+    def archive_stream(self, stream: Stream) -> None:
         """
-        Delete the stream and assess the result.
+        Archive the stream and assess the result.
         """
         active_name = stream.name
         realm = stream.realm
@@ -1402,28 +1402,28 @@ def test_delete_public_stream(self) -> None:
         When an administrator deletes a public stream, that stream is not
         visible to users at all anymore.
         """
-        stream = self.set_up_stream_for_deletion("newstream")
-        self.delete_stream(stream)
+        stream = self.set_up_stream_for_archiving("newstream")
+        self.archive_stream(stream)
 
     def test_delete_private_stream(self) -> None:
         """
         Administrators can delete private streams they are on.
         """
-        stream = self.set_up_stream_for_deletion("newstream", invite_only=True)
-        self.delete_stream(stream)
+        stream = self.set_up_stream_for_archiving("newstream", invite_only=True)
+        self.archive_stream(stream)
 
-    def test_delete_streams_youre_not_on(self) -> None:
+    def test_archive_streams_youre_not_on(self) -> None:
         """
         Administrators can delete public streams they aren't on, including
         private streams in their realm.
         """
-        pub_stream = self.set_up_stream_for_deletion("pubstream", subscribed=False)
-        self.delete_stream(pub_stream)
+        pub_stream = self.set_up_stream_for_archiving("pubstream", subscribed=False)
+        self.archive_stream(pub_stream)
 
-        priv_stream = self.set_up_stream_for_deletion(
+        priv_stream = self.set_up_stream_for_archiving(
             "privstream", subscribed=False, invite_only=True
         )
-        self.delete_stream(priv_stream)
+        self.archive_stream(priv_stream)
 
     def attempt_unsubscribe_of_principal(
         self,
@@ -4369,7 +4369,7 @@ def test_gather_subscriptions_excludes_deactivated_streams(self) -> None:
             self.subscribe(non_admin_user, stream_name)
             self.subscribe(self.example_user("othello"), stream_name)
 
-        def delete_stream(stream_name: str) -> None:
+        def archive_stream(stream_name: str) -> None:
             stream_id = get_stream(stream_name, realm).id
             result = self.client_delete(f"/json/streams/{stream_id}")
             self.assert_json_success(result)
@@ -4379,7 +4379,7 @@ def delete_stream(stream_name: str) -> None:
         non_admin_before_delete = gather_subscriptions_helper(non_admin_user)
 
         # Delete our stream
-        delete_stream("stream1")
+        archive_stream("stream1")
 
         # Get subs after delete
         admin_after_delete = gather_subscriptions_helper(admin_user)