more things

This commit is contained in:
sam 2024-02-25 22:26:24 +01:00
parent b2c3a521e9
commit ad247ca0f4
7 changed files with 77 additions and 10 deletions

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use axum::{Extension, Json};
use foxchat::{
http::ApiError,
model::{http::guild::CreateGuildParams, user::PartialUser, Guild, channel::PartialChannel},
model::{channel::PartialChannel, http::guild::CreateGuildParams, user::PartialUser, Guild},
FoxError,
};
@ -39,8 +39,12 @@ pub async fn post_guilds(
instance: user.instance.domain,
},
default_channel: PartialChannel {
id: channel.id.0.clone(),
name: channel.name.clone(),
},
channels: Some(vec![PartialChannel {
id: channel.id.0,
name: channel.name,
}
}]),
}))
}

View file

@ -8,7 +8,7 @@ use axum::{
response::Response,
Extension,
};
use eyre::Result;
use eyre::{eyre, Error, Result};
use foxchat::{
s2s::{Dispatch, Payload},
signature::{parse_date, verify_signature},
@ -169,6 +169,28 @@ async fn read(
return;
};
let Ok(msg) = msg.to_text() else {
tx.send(Payload::Error {
message: "Invalid message".into(),
})
.await
.ok();
return;
};
let Ok(msg) = serde_json::from_str::<Payload>(msg) else {
tx.send(Payload::Error {
message: "Invalid message".into(),
})
.await
.ok();
return;
};
match msg {
Payload::Connect { user_id } => {}
}
// TODO: handle incoming payloads
}
}
@ -317,5 +339,35 @@ async fn filter_events(
}
return Ok((false, vec![]));
}
Dispatch::Ready { user, guilds: _ } => {
let user = sqlx::query!(
"SELECT remote_user_id FROM users WHERE id = $1",
user.id.clone()
)
.fetch_one(&app_state.pool)
.await?;
return Ok((true, vec![user.remote_user_id]));
}
}
}
async fn collect_ready(
app_state: Arc<AppState>,
socket_state: Arc<RwLock<SocketState>>,
user_id: String,
) -> Result<Payload> {
let Some(instance) = &socket_state.read().await.instance else {
return Err(eyre!("instance was None when it shouldn't be"));
};
let user = sqlx::query!(
"SELECT * FROM users WHERE instance_id = $1 AND remote_user_id = $2",
instance.id,
user_id
)
.fetch_one(&app_state.pool)
.await?;
todo!()
}