include if message is hidden
This commit is contained in:
parent
13cd2d143f
commit
e97afb83f7
1
server/src/consts.rs
Normal file
1
server/src/consts.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub const VOTE_THRESHOLD_HIDE: i32 = -1;
|
|
@ -19,6 +19,7 @@ mod message;
|
|||
mod web;
|
||||
mod util;
|
||||
mod config;
|
||||
mod consts;
|
||||
|
||||
static MIGRATOR: Migrator = sqlx::migrate!();
|
||||
|
||||
|
|
|
@ -64,3 +64,21 @@ pub struct RetrievedMessageTerritory {
|
|||
#[serde(skip)]
|
||||
pub created: NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct OwnMessage {
|
||||
pub id: String,
|
||||
pub territory: i64,
|
||||
pub x: f64,
|
||||
pub y: f64,
|
||||
pub z: f64,
|
||||
pub yaw: f64,
|
||||
pub message: String,
|
||||
pub positive_votes: i32,
|
||||
pub negative_votes: i32,
|
||||
pub user_vote: i64,
|
||||
pub glyph: i64,
|
||||
#[serde(skip)]
|
||||
pub created: NaiveDateTime,
|
||||
pub is_hidden: bool,
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ fn filter_messages(messages: &mut Vec<RetrievedMessage>, id: i64) {
|
|||
|
||||
// remove messages where the user has been offline for over 35 minutes
|
||||
// also remove messages with low score (that aren't the from the user)
|
||||
messages.drain_filter(|msg| msg.last_seen_minutes >= 35 || (msg.user != id_str && (msg.positive_votes - msg.negative_votes) < -1));
|
||||
messages.drain_filter(|msg| msg.last_seen_minutes >= 35 || (msg.user != id_str && (msg.positive_votes - msg.negative_votes) < crate::consts::VOTE_THRESHOLD_HIDE));
|
||||
|
||||
// shuffle messages since we'll be excluding later based on messages
|
||||
// that have already been included, so this will be more fair
|
||||
|
|
|
@ -5,7 +5,7 @@ use anyhow::Context;
|
|||
use warp::{Filter, Rejection, Reply};
|
||||
use warp::filters::BoxedFilter;
|
||||
|
||||
use crate::message::RetrievedMessageTerritory;
|
||||
use crate::message::OwnMessage;
|
||||
use crate::State;
|
||||
use crate::web::AnyhowRejection;
|
||||
|
||||
|
@ -26,7 +26,7 @@ async fn logic(state: Arc<State>, id: i64, extra: i64, mut query: HashMap<String
|
|||
.unwrap_or(1);
|
||||
|
||||
let mut messages = sqlx::query_as!(
|
||||
RetrievedMessageTerritory,
|
||||
OwnMessage,
|
||||
// language=sqlite
|
||||
r#"
|
||||
select m.id,
|
||||
|
@ -40,7 +40,8 @@ async fn logic(state: Arc<State>, id: i64, extra: i64, mut query: HashMap<String
|
|||
coalesce(sum(v.vote between -1 and 0), 0) as negative_votes,
|
||||
v2.vote as user_vote,
|
||||
m.glyph,
|
||||
m.created
|
||||
m.created,
|
||||
0 as "is_hidden: bool"
|
||||
from messages m
|
||||
left join votes v on m.id = v.message
|
||||
left join votes v2 on m.id = v2.message and v2.user = ?
|
||||
|
@ -58,13 +59,17 @@ async fn logic(state: Arc<State>, id: i64, extra: i64, mut query: HashMap<String
|
|||
messages.sort_by_key(|msg| msg.created);
|
||||
messages.reverse();
|
||||
|
||||
for msg in &mut messages {
|
||||
msg.is_hidden = msg.positive_votes - msg.negative_votes < crate::consts::VOTE_THRESHOLD_HIDE;
|
||||
}
|
||||
|
||||
if version == 1 {
|
||||
return Ok(warp::reply::json(&messages));
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct Mine {
|
||||
messages: Vec<RetrievedMessageTerritory>,
|
||||
messages: Vec<OwnMessage>,
|
||||
extra: i64,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user