Update connected users' invite info when they are granted invite codes
This commit is contained in:
parent
6899eacf3d
commit
ce080e9520
2 changed files with 24 additions and 6 deletions
|
@ -88,8 +88,6 @@ async fn create_user(
|
||||||
Extension(app): Extension<Arc<AppState>>,
|
Extension(app): Extension<Arc<AppState>>,
|
||||||
Extension(rpc_server): Extension<Arc<rpc::Server>>,
|
Extension(rpc_server): Extension<Arc<rpc::Server>>,
|
||||||
) -> Result<Json<User>> {
|
) -> Result<Json<User>> {
|
||||||
println!("{:?}", params);
|
|
||||||
|
|
||||||
let user_id = if let Some(invite_code) = params.invite_code {
|
let user_id = if let Some(invite_code) = params.invite_code {
|
||||||
let invitee_id = app
|
let invitee_id = app
|
||||||
.db
|
.db
|
||||||
|
@ -133,15 +131,17 @@ async fn update_user(
|
||||||
Path(user_id): Path<i32>,
|
Path(user_id): Path<i32>,
|
||||||
Json(params): Json<UpdateUserParams>,
|
Json(params): Json<UpdateUserParams>,
|
||||||
Extension(app): Extension<Arc<AppState>>,
|
Extension(app): Extension<Arc<AppState>>,
|
||||||
|
Extension(rpc_server): Extension<Arc<rpc::Server>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let user_id = UserId(user_id);
|
||||||
|
|
||||||
if let Some(admin) = params.admin {
|
if let Some(admin) = params.admin {
|
||||||
app.db.set_user_is_admin(UserId(user_id), admin).await?;
|
app.db.set_user_is_admin(user_id, admin).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(invite_count) = params.invite_count {
|
if let Some(invite_count) = params.invite_count {
|
||||||
app.db
|
app.db.set_invite_count(user_id, invite_count).await?;
|
||||||
.set_invite_count(UserId(user_id), invite_count)
|
rpc_server.invite_count_updated(user_id).await.trace_err();
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -462,6 +462,24 @@ impl Server {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn invite_count_updated(self: &Arc<Self>, user_id: UserId) -> Result<()> {
|
||||||
|
if let Some(user) = self.app_state.db.get_user_by_id(user_id).await? {
|
||||||
|
if let Some(invite_code) = &user.invite_code {
|
||||||
|
let store = self.store().await;
|
||||||
|
for connection_id in store.connection_ids_for_user(user_id) {
|
||||||
|
self.peer.send(
|
||||||
|
connection_id,
|
||||||
|
proto::UpdateInviteInfo {
|
||||||
|
url: format!("{}{}", self.app_state.invite_link_prefix, invite_code),
|
||||||
|
count: user.invite_count as u32,
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn ping(
|
async fn ping(
|
||||||
self: Arc<Server>,
|
self: Arc<Server>,
|
||||||
_: TypedEnvelope<proto::Ping>,
|
_: TypedEnvelope<proto::Ping>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue