mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
Fixing broken websockets. (#2770)
* Fixing broken websockets. * Use cloned() for serde::Value
This commit is contained in:
parent
c9a94ccca8
commit
e6b27f07d7
@ -247,14 +247,18 @@ async fn parse_json_message(
|
||||
context: LemmyContext,
|
||||
) -> Result<String, LemmyError> {
|
||||
let json: Value = serde_json::from_str(&msg)?;
|
||||
let data = &json
|
||||
let data = json
|
||||
.get("data")
|
||||
.ok_or_else(|| LemmyError::from_message("missing data"))?
|
||||
.to_string();
|
||||
let op = &json
|
||||
.cloned()
|
||||
.ok_or_else(|| LemmyError::from_message("missing data"))?;
|
||||
|
||||
let missing_op_err = || LemmyError::from_message("missing op");
|
||||
|
||||
let op = json
|
||||
.get("op")
|
||||
.ok_or_else(|| LemmyError::from_message("missing op"))?
|
||||
.to_string();
|
||||
.ok_or_else(missing_op_err)?
|
||||
.as_str()
|
||||
.ok_or_else(missing_op_err)?;
|
||||
|
||||
// check if api call passes the rate limit, and generate future for later execution
|
||||
if let Ok(user_operation_crud) = UserOperationCrud::from_str(op) {
|
||||
@ -298,7 +302,7 @@ pub async fn match_websocket_operation_crud(
|
||||
context: LemmyContext,
|
||||
id: ConnectionId,
|
||||
op: UserOperationCrud,
|
||||
data: &str,
|
||||
data: Value,
|
||||
) -> result::Result<String, LemmyError> {
|
||||
match op {
|
||||
// User ops
|
||||
@ -391,13 +395,13 @@ async fn do_websocket_operation_crud<'a, 'b, Data>(
|
||||
context: LemmyContext,
|
||||
id: ConnectionId,
|
||||
op: UserOperationCrud,
|
||||
data: &str,
|
||||
data: Value,
|
||||
) -> result::Result<String, LemmyError>
|
||||
where
|
||||
Data: PerformCrud + SendActivity<Response = <Data as PerformCrud>::Response>,
|
||||
for<'de> Data: Deserialize<'de>,
|
||||
{
|
||||
let parsed_data: Data = serde_json::from_str(data)?;
|
||||
let parsed_data: Data = serde_json::from_value(data)?;
|
||||
let res = parsed_data
|
||||
.perform(&web::Data::new(context.clone()), Some(id))
|
||||
.await?;
|
||||
@ -409,7 +413,7 @@ pub async fn match_websocket_operation_apub(
|
||||
context: LemmyContext,
|
||||
id: ConnectionId,
|
||||
op: UserOperationApub,
|
||||
data: &str,
|
||||
data: Value,
|
||||
) -> result::Result<String, LemmyError> {
|
||||
match op {
|
||||
UserOperationApub::GetPersonDetails => {
|
||||
@ -435,13 +439,13 @@ async fn do_websocket_operation_apub<'a, 'b, Data>(
|
||||
context: LemmyContext,
|
||||
id: ConnectionId,
|
||||
op: UserOperationApub,
|
||||
data: &str,
|
||||
data: Value,
|
||||
) -> result::Result<String, LemmyError>
|
||||
where
|
||||
Data: PerformApub + SendActivity<Response = <Data as PerformApub>::Response>,
|
||||
for<'de> Data: Deserialize<'de>,
|
||||
{
|
||||
let parsed_data: Data = serde_json::from_str(data)?;
|
||||
let parsed_data: Data = serde_json::from_value(data)?;
|
||||
let res = parsed_data
|
||||
.perform(&web::Data::new(context.clone()), Some(id))
|
||||
.await?;
|
||||
@ -453,7 +457,7 @@ pub async fn match_websocket_operation(
|
||||
context: LemmyContext,
|
||||
id: ConnectionId,
|
||||
op: UserOperation,
|
||||
data: &str,
|
||||
data: Value,
|
||||
) -> result::Result<String, LemmyError> {
|
||||
match op {
|
||||
// User ops
|
||||
@ -610,13 +614,13 @@ async fn do_websocket_operation<'a, 'b, Data>(
|
||||
context: LemmyContext,
|
||||
id: ConnectionId,
|
||||
op: UserOperation,
|
||||
data: &str,
|
||||
data: Value,
|
||||
) -> result::Result<String, LemmyError>
|
||||
where
|
||||
Data: Perform + SendActivity<Response = <Data as Perform>::Response>,
|
||||
for<'de> Data: Deserialize<'de>,
|
||||
{
|
||||
let parsed_data: Data = serde_json::from_str(data)?;
|
||||
let parsed_data: Data = serde_json::from_value(data)?;
|
||||
let res = parsed_data
|
||||
.perform(&web::Data::new(context.clone()), Some(id))
|
||||
.await?;
|
||||
|
Loading…
Reference in New Issue
Block a user