pub fn delete_message(
    conn: &rusqlite::Connection,
    id: i64,
    user: &User,
    room: &Room,
) -> Result<Response, Rejection> {
    let mut auth_req = AuthorizationRequired { read: true, ..Default::default() };

    // Check to see if the message to be deleted is owned by someone else: if it is, we require
    // moderator access for the deletion.
    let mut st = conn
        .prepare_cached("SELECT COUNT(*) FROM messages WHERE room = ? AND id = ? AND user != ?")
        .map_err(db_error)?;

    match st.query_row(params![room.id, id, user.id], |row| row.get::<_, i64>(0)) {
        Ok(count) => {
            if count > 0 {
                auth_req.moderator = true;
            }
        }
        Err(rusqlite::Error::QueryReturnedNoRows) => {
            let response = json!({"status_code": StatusCode::NOT_FOUND.as_u16()});
            return Ok(warp::reply::json(&response).into_response());
        }
        Err(_) => return Err(Error::DatabaseFailedInternally.into()),
    };

    require_authorization(conn, user, room, auth_req)?;

    let mut del_st = conn
        .prepare_cached(
            "UPDATE messages SET data = NULL, data_size = NULL, signature = NULL WHERE id = ?",
        )
        .map_err(db_error)?;

    if let Err(e) = del_st.execute(params![id]) {
        error!("Couldn't delete message: {}.", e);
        return Err(Error::DatabaseFailedInternally.into());
    }

    let json = models::StatusCode { status_code: StatusCode::OK.as_u16() };
    Ok(warp::reply::json(&json).into_response())
}
/// Deletes the message with the given `id` from the database, if it's present.
Deletes the message with the given `id` from the database, if it's present.
Deletes the message with the given ` id ` from the database if it ' s present .
pub fn delete_message(
    conn: &rusqlite::Connection,
    id: i64,
    user: &User,
    room: &Room,
) -> Result<Response, Rejection> {
    let mut auth_req = AuthorizationRequired { read: true, ..Default::default() };
    // Check to see if the message to be deleted is owned by someone else: if it is, we require
    // moderator access for the deletion.
    let mut st = conn
        .prepare_cached("SELECT COUNT(*) FROM messages WHERE room = ? AND id = ? AND user != ?")
        .map_err(db_error)?;
    match st.query_row(params![room.id, id, user.id], |row| row.get::<_, i64>(0)) {
        Ok(count) => {
            if count > 0 {
                auth_req.moderator = true;
            }
        }
        Err(rusqlite::Error::QueryReturnedNoRows) => {
            let response = json!({"status_code": StatusCode::NOT_FOUND.as_u16()});
            return Ok(warp::reply::json(&response).into_response());
        }
        Err(_) => return Err(Error::DatabaseFailedInternally.into()),
    };
    require_authorization(conn, user, room, auth_req)?;
    let mut del_st = conn
        .prepare_cached(
            "UPDATE messages SET data = NULL, data_size = NULL, signature = NULL WHERE id = ?",
        )
        .map_err(db_error)?;
    if let Err(e) = del_st.execute(params![id]) {
        error!("Couldn't delete message: {}.", e);
        return Err(Error::DatabaseFailedInternally.into());
    }
    let json = models::StatusCode { status_code: StatusCode::OK.as_u16() };
    Ok(warp::reply::json(&json).into_response())
}
pub fn delete_message ( conn : & rusqlite :: Connection , id : i64 , user : & User , room : & Room , ) -> Result < Response , Rejection > { let mut auth_req = AuthorizationRequired { read : true , .. Default :: default ( ) } ; // Check to see if the message to be deleted is owned by someone else: if it is, we require // moderator access for the deletion. let mut st = conn . prepare_cached ( " " ) . map_err ( db_error ) ? ; match st . query_row ( params ! [ room id id user id ] , | row | row . get :: < _ , i64 > ( 0 ) ) { Ok ( count ) => { if count > 0 { auth_req . moderator = true ; } } Err ( rusqlite :: Error :: QueryReturnedNoRows ) => { let response = json ! ( { " " StatusCode NOT_FOUND as_u16 ( ) } ) ; return Ok ( warp :: reply :: json ( & response ) . into_response ( ) ) ; } Err ( _ ) => return Err ( Error :: DatabaseFailedInternally . into ( ) ) , } ; require_authorization ( conn , user , room , auth_req ) ? ; let mut del_st = conn . prepare_cached ( " " , ) . map_err ( db_error ) ? ; if let Err ( e ) = del_st . execute ( params ! [ id ] ) { error ! ( " " e ) ; return Err ( Error :: DatabaseFailedInternally . into ( ) ) ; } let json = models :: StatusCode { status_code : StatusCode :: OK . as_u16 ( ) } ; Ok ( warp :: reply :: json ( & json ) . into_response ( ) ) }
Deletes the message with the given `id` from the database, if it's present.
Deletes the message with the given ` id ` from the database if it ' s present .
conn
&rusqlite::Connection
id
i64
user
&User
room
&Room
conn
&rusqlite::Connection
id
i64
user
&User
room
&Room