more things
This commit is contained in:
parent
b2c3a521e9
commit
ad247ca0f4
7 changed files with 77 additions and 10 deletions
|
@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||||
use axum::{Extension, Json};
|
use axum::{Extension, Json};
|
||||||
use foxchat::{
|
use foxchat::{
|
||||||
http::ApiError,
|
http::ApiError,
|
||||||
model::{http::guild::CreateGuildParams, user::PartialUser, Guild, channel::PartialChannel},
|
model::{channel::PartialChannel, http::guild::CreateGuildParams, user::PartialUser, Guild},
|
||||||
FoxError,
|
FoxError,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,8 +39,12 @@ pub async fn post_guilds(
|
||||||
instance: user.instance.domain,
|
instance: user.instance.domain,
|
||||||
},
|
},
|
||||||
default_channel: PartialChannel {
|
default_channel: PartialChannel {
|
||||||
|
id: channel.id.0.clone(),
|
||||||
|
name: channel.name.clone(),
|
||||||
|
},
|
||||||
|
channels: Some(vec![PartialChannel {
|
||||||
id: channel.id.0,
|
id: channel.id.0,
|
||||||
name: channel.name,
|
name: channel.name,
|
||||||
}
|
}]),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use axum::{
|
||||||
response::Response,
|
response::Response,
|
||||||
Extension,
|
Extension,
|
||||||
};
|
};
|
||||||
use eyre::Result;
|
use eyre::{eyre, Error, Result};
|
||||||
use foxchat::{
|
use foxchat::{
|
||||||
s2s::{Dispatch, Payload},
|
s2s::{Dispatch, Payload},
|
||||||
signature::{parse_date, verify_signature},
|
signature::{parse_date, verify_signature},
|
||||||
|
@ -169,6 +169,28 @@ async fn read(
|
||||||
return;
|
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
|
// TODO: handle incoming payloads
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,5 +339,35 @@ async fn filter_events(
|
||||||
}
|
}
|
||||||
return Ok((false, vec![]));
|
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!()
|
||||||
|
}
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::s2s::Dispatch;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(tag = "t", content = "d", rename_all = "SCREAMING_SNAKE_CASE")]
|
#[serde(tag = "t", content = "d", rename_all = "SCREAMING_SNAKE_CASE")]
|
||||||
pub enum Payload {
|
pub enum Payload {
|
||||||
|
#[serde(rename = "D")]
|
||||||
Dispatch {
|
Dispatch {
|
||||||
#[serde(rename = "e")]
|
#[serde(rename = "e")]
|
||||||
event: String,
|
event: Dispatch,
|
||||||
#[serde(rename = "s")]
|
#[serde(rename = "s")]
|
||||||
server: String,
|
server_id: String,
|
||||||
},
|
},
|
||||||
Error {
|
Error {
|
||||||
message: String,
|
message: String,
|
||||||
|
@ -19,4 +22,4 @@ pub enum Payload {
|
||||||
Identify {
|
Identify {
|
||||||
token: String,
|
token: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
pub mod event;
|
||||||
|
|
||||||
|
pub use event::Payload;
|
|
@ -8,7 +8,7 @@ pub struct Channel {
|
||||||
pub topic: Option<String>,
|
pub topic: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct PartialChannel {
|
pub struct PartialChannel {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
use super::{user::PartialUser, channel::PartialChannel};
|
use super::{channel::PartialChannel, user::PartialUser};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct Guild {
|
pub struct Guild {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub owner: PartialUser,
|
pub owner: PartialUser,
|
||||||
pub default_channel: PartialChannel,
|
pub default_channel: PartialChannel,
|
||||||
|
pub channels: Option<Vec<PartialChannel>>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
id::GuildType,
|
id::GuildType,
|
||||||
model::{user::PartialUser, Message},
|
model::{user::PartialUser, Guild, Message, User},
|
||||||
Id,
|
Id,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,6 +18,10 @@ pub enum Dispatch {
|
||||||
content: Option<String>,
|
content: Option<String>,
|
||||||
created_at: DateTime<Utc>,
|
created_at: DateTime<Utc>,
|
||||||
},
|
},
|
||||||
|
Ready {
|
||||||
|
user: User,
|
||||||
|
guilds: Vec<Guild>,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch {
|
impl Dispatch {
|
||||||
|
|
Loading…
Reference in a new issue