Show current plan in user menu (#15513)

This PR updates the user menu to show the user's current plan.

Also adds a new RPC message to send this information down to the client
when Zed starts.

This is behind a feature flag.

Release Notes:

- N/A

---------

Co-authored-by: Max <max@zed.dev>
This commit is contained in:
Marshall Bowers 2024-07-30 17:38:16 -04:00 committed by GitHub
parent 161c6ca6a4
commit a7ffc2b6f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 95 additions and 11 deletions

View file

@ -1137,6 +1137,8 @@ impl Server {
.await?;
}
update_user_plan(user.id, session).await?;
let (contacts, dev_server_projects) = future::try_join(
self.app_state.db.get_contacts(user.id),
self.app_state.db.dev_server_projects_update(user.id),
@ -3535,6 +3537,27 @@ fn should_auto_subscribe_to_channels(version: ZedVersion) -> bool {
version.0.minor() < 139
}
async fn update_user_plan(user_id: UserId, session: &Session) -> Result<()> {
let db = session.db().await;
let active_subscriptions = db.get_active_billing_subscriptions(user_id).await?;
let plan = if session.is_staff() || !active_subscriptions.is_empty() {
proto::Plan::ZedPro
} else {
proto::Plan::Free
};
session
.peer
.send(
session.connection_id,
proto::UpdateUserPlan { plan: plan.into() },
)
.trace_err();
Ok(())
}
async fn subscribe_to_channels(_: proto::SubscribeToChannels, session: Session) -> Result<()> {
subscribe_user_to_channels(
session.user_id().ok_or_else(|| anyhow!("must be a user"))?,