mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: added subscription cancellation
This commit is contained in:
@ -517,6 +517,15 @@ where
|
||||
Ok(workspace_subscriptions)
|
||||
})
|
||||
}
|
||||
|
||||
fn cancel_workspace_subscription(&self, workspace_id: String) -> FutureResult<(), FlowyError> {
|
||||
let try_get_client = self.server.try_get_client();
|
||||
FutureResult::new(async move {
|
||||
let client = try_get_client?;
|
||||
client.cancel_subscription(&workspace_id).await?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_admin_client(client: &Arc<AFCloudClient>) -> FlowyResult<Client> {
|
||||
|
@ -281,6 +281,10 @@ pub trait UserCloudService: Send + Sync + 'static {
|
||||
fn get_workspace_subscriptions(&self) -> FutureResult<Vec<WorkspaceSubscription>, FlowyError> {
|
||||
FutureResult::new(async { Err(FlowyError::not_support()) })
|
||||
}
|
||||
|
||||
fn cancel_workspace_subscription(&self, workspace_id: String) -> FutureResult<(), FlowyError> {
|
||||
FutureResult::new(async { Err(FlowyError::not_support()) })
|
||||
}
|
||||
}
|
||||
|
||||
pub type UserUpdateReceiver = tokio::sync::mpsc::Receiver<UserUpdate>;
|
||||
|
@ -799,3 +799,14 @@ pub async fn get_workspace_subscriptions_handler(
|
||||
.collect::<Vec<_>>();
|
||||
data_result_ok(RepeatedWorkspaceSubscriptionPB { items: subs })
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip_all, err)]
|
||||
pub async fn cancel_workspace_subscription_handler(
|
||||
param: AFPluginData<UserWorkspaceIdPB>,
|
||||
manager: AFPluginState<Weak<UserManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let workspace_id = param.into_inner().workspace_id;
|
||||
let manager = upgrade_manager(manager)?;
|
||||
manager.cancel_workspace_subscription(workspace_id).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -74,6 +74,7 @@ pub fn init(user_manager: Weak<UserManager>) -> AFPlugin {
|
||||
// Billing
|
||||
.event(UserEvent::SubscribeWorkspace, subscribe_workspace_handler)
|
||||
.event(UserEvent::GetWorkspaceSubscriptions, get_workspace_subscriptions_handler)
|
||||
.event(UserEvent::CancelWorkspaceSubscription, cancel_workspace_subscription_handler)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
|
||||
@ -239,6 +240,9 @@ pub enum UserEvent {
|
||||
|
||||
#[event(output = "RepeatedWorkspaceSubscriptionPB")]
|
||||
GetWorkspaceSubscriptions = 52,
|
||||
|
||||
#[event(output = "UserWorkspaceIdPB")]
|
||||
CancelWorkspaceSubscription = 53,
|
||||
}
|
||||
|
||||
pub trait UserStatusCallback: Send + Sync + 'static {
|
||||
|
@ -431,6 +431,16 @@ impl UserManager {
|
||||
.await?;
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
#[instrument(level = "info", skip(self), err)]
|
||||
pub async fn cancel_workspace_subscription(&self, workspace_id: String) -> FlowyResult<()> {
|
||||
self
|
||||
.cloud_services
|
||||
.get_user_service()?
|
||||
.cancel_workspace_subscription(workspace_id)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save_user_workspaces(
|
||||
|
Reference in New Issue
Block a user