Skip to content

Commit

Permalink
Change vote by rate
Browse files Browse the repository at this point in the history
  • Loading branch information
grunch committed May 1, 2023
1 parent 34ed4bc commit bf852ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/app/rate_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,21 @@ pub async fn update_user_reputation_action(
reputation.total_rating = new_rating;
}

// Check if the order is not voted by the message sender and in case update NIP
// Check if the order is not rated by the message sender and in case update NIP
let order_to_check_ratings = crate::db::find_order_by_id(pool, order.id).await?;
// Check what vote status needs update
let update_seller_vote = seller_rating && !order_to_check_ratings.seller_sent_rate;
let update_buyer_vote = buyer_rating && !order_to_check_ratings.buyer_sent_rate;
if update_buyer_vote && update_seller_vote {
// Check what rate status needs update
let update_seller_rate = seller_rating && !order_to_check_ratings.seller_sent_rate;
let update_buyer_rate = buyer_rating && !order_to_check_ratings.buyer_sent_rate;
if update_buyer_rate && update_seller_rate {
return Ok(());
};

if buyer_rating || seller_rating {
//Update db with vote flags
update_user_rating_event(
&counterpart,
update_buyer_vote,
update_seller_vote,
update_buyer_rate,
update_seller_rate,
reputation.as_json().unwrap(),
order.id,
my_keys,
Expand Down
4 changes: 2 additions & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub async fn update_order_event_id_status(
Ok(rows_affected > 0)
}

pub async fn update_order_event_seller_vote(
pub async fn update_order_event_seller_rate(
pool: &SqlitePool,
order_id: Uuid,
seller_sent_rate: bool,
Expand All @@ -252,7 +252,7 @@ pub async fn update_order_event_seller_vote(
Ok(rows_affected > 0)
}

pub async fn update_order_event_buyer_vote(
pub async fn update_order_event_buyer_rate(
pool: &SqlitePool,
order_id: Uuid,
buyer_sent_rate: bool,
Expand Down
4 changes: 2 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ pub async fn update_user_rating_event(
info!("Sending replaceable event: {event:#?}");
// We update the order vote status
if buyer_sent_rate {
crate::db::update_order_event_buyer_vote(pool, order_id, buyer_sent_rate).await?;
crate::db::update_order_event_buyer_rate(pool, order_id, buyer_sent_rate).await?;
}
if seller_sent_rate {
crate::db::update_order_event_seller_vote(pool, order_id, seller_sent_rate).await?;
crate::db::update_order_event_seller_rate(pool, order_id, seller_sent_rate).await?;
}

// Send event to relay
Expand Down

0 comments on commit bf852ee

Please sign in to comment.