Repository: LemmyNet/lemmy (language: rust)

Issue:
[Bug]: The Moderator View of Communities doesn't work
### Requirements

- [x] Is this a bug report? For questions or discussions use https://lemmy.ml/c/lemmy_support
- [x] Did you check to see if this issue already exists?
- [x] Is this only a single bug? Do not put multiple bugs in one issue.
- [x] Do you agree to follow the rules in our [Code of Conduct](https://join-lemmy.org/docs/code_of_conduct.html)?
- [x] Is this a backend issue? Use the [lemmy-ui](https://github.com/LemmyNet/lemmy-ui) repo for UI / frontend issues.

### Summary

The ListCommunities API takes a parameter type_, which can be set to ModeratorView.  However, it doesn't appear to support this as it returns All communities instead of just the moderated ones.

### Steps to Reproduce

In the default Lemmy UI, using an account which moderates at least one community:
 
1. Click on Communities
2. Click on Moderator View
3. Observe that the list is the same as clicking on All

### Technical Details

The ListCommunities API takes a parameter type_, which can be set to ModeratorView.  However, it doesn't appear to support this as it returns All communities instead of just the moderated ones.  I've tested this through the API using Pythorhead, and the default Lemmy UI appears to do the same.  It appears that this is either unimplemented or has a bug which means it is returning the wrong list.

### Version

0.19.7

### Lemmy Instance URL

feddit.uk


Discussion / hints:
This feature works correctly for me on `lemmy.ml` (0.19.8). Maybe this bug only happens in specific circumstances, or got fixed in 0.19.8?
I've just tried on `lemmy.dbzer0.com` (which is on 0.19.8) and I'm getting exactly the same behaviour - Moderator View in Communities in the UI, and via the API, is giving the same list as All rather than the list of (one, in this case) moderated communities.

So it clearly isn't fixed on 0.19.8, but I'm not sure why it appears to work on lemmy.ml.

I've gone round and checked - from the UI only - the ModeratorView of Communities.  It isn't working on `feddit.uk`, `lemmy.dbzer0.com`, `lemm.ee`, `lemmings.world` or `lemmy.world`.  I don't have a mod account on any other server in order to test.
Ah, the _community list_ ModeratorView. Yeah, it doesn't work for me either. My apologies, I thought you meant the ModeratorView for the feed.

Fix patch:
diff --git a/crates/db_views/src/community/community_view.rs b/crates/db_views/src/community/community_view.rs
index 7ef746e539..fa9144c4b7 100644
--- a/crates/db_views/src/community/community_view.rs
+++ b/crates/db_views/src/community/community_view.rs
@@ -137,13 +137,18 @@ fn queries<'a>() -> Queries<
       NameDesc => query = query.order_by(lower(community::name).desc()),
     };
 
+    let is_subscribed = community_actions::follow_state.eq(Some(CommunityFollowerState::Accepted));
+
     if let Some(listing_type) = o.listing_type {
       query = match listing_type {
-        ListingType::Subscribed => {
-          query.filter(community_actions::follow_state.eq(Some(CommunityFollowerState::Accepted)))
+        ListingType::All => query.filter(community::hidden.eq(false).or(is_subscribed)),
+        ListingType::Subscribed => query.filter(is_subscribed),
+        ListingType::Local => query
+          .filter(community::local.eq(true))
+          .filter(community::hidden.eq(false).or(is_subscribed)),
+        ListingType::ModeratorView => {
+          query.filter(community_actions::became_moderator.is_not_null())
         }
-        ListingType::Local => query.filter(community::local.eq(true)),
-        _ => query,
       };
     }
 


Test patch: