fix: ignore housing parameters if not in a housing zone
This commit is contained in:
parent
829bf354d8
commit
5ef3a8c6b4
|
@ -53,40 +53,75 @@ async fn logic(state: Arc<State>, id: i64, location: u32, query: GetLocationQuer
|
||||||
};
|
};
|
||||||
|
|
||||||
let location = location as i64;
|
let location = location as i64;
|
||||||
let mut messages = sqlx::query_as!(
|
let mut messages = if housing {
|
||||||
RetrievedMessage,
|
sqlx::query_as!(
|
||||||
// language=sqlite
|
RetrievedMessage,
|
||||||
r#"
|
// language=sqlite
|
||||||
select m.id,
|
r#"
|
||||||
m.x,
|
select m.id,
|
||||||
m.y,
|
m.x,
|
||||||
m.z,
|
m.y,
|
||||||
m.yaw,
|
m.z,
|
||||||
m.message,
|
m.yaw,
|
||||||
coalesce(sum(v.vote between 0 and 1), 0) as positive_votes,
|
m.message,
|
||||||
coalesce(sum(v.vote between -1 and 0), 0) as negative_votes,
|
coalesce(sum(v.vote between 0 and 1), 0) as positive_votes,
|
||||||
v2.vote as user_vote,
|
coalesce(sum(v.vote between -1 and 0), 0) as negative_votes,
|
||||||
m.glyph,
|
v2.vote as user_vote,
|
||||||
m.created,
|
m.glyph,
|
||||||
m.user,
|
m.created,
|
||||||
cast((julianday(current_timestamp) - julianday(u.last_seen)) * 1440 as int) as last_seen_minutes
|
m.user,
|
||||||
from messages m
|
cast((julianday(current_timestamp) - julianday(u.last_seen)) * 1440 as int) as last_seen_minutes
|
||||||
left join votes v on m.id = v.message
|
from messages m
|
||||||
left join votes v2 on m.id = v2.message and v2.user = ?
|
left join votes v on m.id = v.message
|
||||||
inner join users u on m.user = u.id
|
left join votes v2 on m.id = v2.message and v2.user = ?
|
||||||
where m.territory = ? and m.world is ? and m.ward is ? and m.plot is ?
|
inner join users u on m.user = u.id
|
||||||
group by m.id"#,
|
where m.territory = ? and m.world is ? and m.ward is ? and m.plot is ?
|
||||||
id,
|
group by m.id"#,
|
||||||
location,
|
id,
|
||||||
world,
|
location,
|
||||||
query.ward,
|
world,
|
||||||
query.plot,
|
query.ward,
|
||||||
)
|
query.plot,
|
||||||
.fetch_all(&state.db)
|
)
|
||||||
.await
|
.fetch_all(&state.db)
|
||||||
.context("could not get messages from database")
|
.await
|
||||||
.map_err(AnyhowRejection)
|
.context("could not get messages from database")
|
||||||
.map_err(warp::reject::custom)?;
|
.map_err(AnyhowRejection)
|
||||||
|
.map_err(warp::reject::custom)?
|
||||||
|
} else {
|
||||||
|
sqlx::query_as!(
|
||||||
|
RetrievedMessage,
|
||||||
|
// language=sqlite
|
||||||
|
r#"
|
||||||
|
select m.id,
|
||||||
|
m.x,
|
||||||
|
m.y,
|
||||||
|
m.z,
|
||||||
|
m.yaw,
|
||||||
|
m.message,
|
||||||
|
coalesce(sum(v.vote between 0 and 1), 0) as positive_votes,
|
||||||
|
coalesce(sum(v.vote between -1 and 0), 0) as negative_votes,
|
||||||
|
v2.vote as user_vote,
|
||||||
|
m.glyph,
|
||||||
|
m.created,
|
||||||
|
m.user,
|
||||||
|
cast((julianday(current_timestamp) - julianday(u.last_seen)) * 1440 as int) as last_seen_minutes
|
||||||
|
from messages m
|
||||||
|
left join votes v on m.id = v.message
|
||||||
|
left join votes v2 on m.id = v2.message and v2.user = ?
|
||||||
|
inner join users u on m.user = u.id
|
||||||
|
where m.territory = ?
|
||||||
|
group by m.id"#,
|
||||||
|
id,
|
||||||
|
location,
|
||||||
|
)
|
||||||
|
.fetch_all(&state.db)
|
||||||
|
.await
|
||||||
|
.context("could not get messages from database")
|
||||||
|
.map_err(AnyhowRejection)
|
||||||
|
.map_err(warp::reject::custom)?
|
||||||
|
};
|
||||||
|
|
||||||
filter_messages(&mut messages, id);
|
filter_messages(&mut messages, id);
|
||||||
Ok(warp::reply::json(&messages))
|
Ok(warp::reply::json(&messages))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue