fix: update mention count badge for channel acks (#769)
Signed-off-by: Zomatree <me@zomatree.live>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use revolt_config::configure;
|
use revolt_config::configure;
|
||||||
use revolt_database::DatabaseInfo;
|
use revolt_database::{DatabaseInfo, AMQP};
|
||||||
use revolt_result::Result;
|
use revolt_result::Result;
|
||||||
use tasks::{acks, file_deletion, prune_dangling_files, prune_members};
|
use tasks::{acks, file_deletion, prune_dangling_files, prune_members};
|
||||||
use tokio::try_join;
|
use tokio::try_join;
|
||||||
@@ -11,11 +11,13 @@ async fn main() -> Result<()> {
|
|||||||
configure!(crond);
|
configure!(crond);
|
||||||
|
|
||||||
let db = DatabaseInfo::Auto.connect().await.expect("database");
|
let db = DatabaseInfo::Auto.connect().await.expect("database");
|
||||||
|
let amqp = AMQP::new_auto().await;
|
||||||
|
|
||||||
try_join!(
|
try_join!(
|
||||||
file_deletion::task(db.clone()),
|
file_deletion::task(db.clone()),
|
||||||
prune_dangling_files::task(db.clone()),
|
prune_dangling_files::task(db.clone()),
|
||||||
prune_members::task(db.clone()),
|
prune_members::task(db.clone()),
|
||||||
acks::task(db.clone())
|
acks::task(db.clone(), amqp.clone()),
|
||||||
)
|
)
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ use lapin::{
|
|||||||
uri::{AMQPAuthority, AMQPQueryString, AMQPUri, AMQPUserInfo},
|
uri::{AMQPAuthority, AMQPQueryString, AMQPUri, AMQPUserInfo},
|
||||||
ConnectionBuilder, ConnectionProperties, ExchangeKind,
|
ConnectionBuilder, ConnectionProperties, ExchangeKind,
|
||||||
};
|
};
|
||||||
use log::info;
|
use log::{debug, info};
|
||||||
use redis_kiss::{get_connection, AsyncCommands, Conn as RedisConnection};
|
use redis_kiss::{get_connection, AsyncCommands, Conn as RedisConnection};
|
||||||
use revolt_config::config;
|
use revolt_config::config;
|
||||||
use revolt_database::{events::rabbit::AckEventPayload, Database};
|
use revolt_database::{events::rabbit::AckEventPayload, Database, AMQP};
|
||||||
use revolt_result::{Result, ToRevoltError};
|
use revolt_result::{Result, ToRevoltError};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
pub async fn task(db: Database) -> Result<()> {
|
pub async fn task(db: Database, amqp: AMQP) -> Result<()> {
|
||||||
let config = config().await;
|
let config = config().await;
|
||||||
|
|
||||||
let mut redis = get_connection()
|
let mut redis = get_connection()
|
||||||
@@ -94,12 +94,14 @@ pub async fn task(db: Database) -> Result<()> {
|
|||||||
|
|
||||||
while let Some(delivery) = consumer.next().await {
|
while let Some(delivery) = consumer.next().await {
|
||||||
if let Ok(delivery) = delivery {
|
if let Ok(delivery) = delivery {
|
||||||
let payload: std::result::Result<AckEventPayload, _> =
|
let payload = serde_json::from_slice::<AckEventPayload>(&delivery.data);
|
||||||
serde_json::from_slice(&delivery.data);
|
|
||||||
if let Ok(payload) = payload {
|
if let Ok(payload) = payload {
|
||||||
info!("{:?}", payload);
|
debug!("Received ack event: {payload:?}");
|
||||||
|
|
||||||
if let Err(e) = process_channel_ack(
|
if let Err(e) = process_channel_ack(
|
||||||
&db,
|
&db,
|
||||||
|
&amqp,
|
||||||
payload.user_id,
|
payload.user_id,
|
||||||
payload.channel_id.unwrap(),
|
payload.channel_id.unwrap(),
|
||||||
&mut redis,
|
&mut redis,
|
||||||
@@ -125,6 +127,7 @@ pub async fn task(db: Database) -> Result<()> {
|
|||||||
#[allow(clippy::disallowed_methods)]
|
#[allow(clippy::disallowed_methods)]
|
||||||
async fn process_channel_ack(
|
async fn process_channel_ack(
|
||||||
db: &Database,
|
db: &Database,
|
||||||
|
amqp: &AMQP,
|
||||||
user: String,
|
user: String,
|
||||||
channel: String,
|
channel: String,
|
||||||
redis: &mut RedisConnection,
|
redis: &mut RedisConnection,
|
||||||
@@ -135,28 +138,24 @@ async fn process_channel_ack(
|
|||||||
.to_internal_error()?;
|
.to_internal_error()?;
|
||||||
|
|
||||||
if let Some(message_id) = message_id {
|
if let Some(message_id) = message_id {
|
||||||
// This will be uncommented eventually, but we need to sort out the transition to lapin first. For now we'll simply disable the badge update logic.
|
let unread = db.fetch_unread(&user, &channel).await?;
|
||||||
// We also drop a db request as a bonus.
|
let updated = db.acknowledge_message(&channel, &user, &message_id).await?;
|
||||||
|
|
||||||
//let unread = db.fetch_unread(&user, &channel).await?;
|
|
||||||
let _updated = db.acknowledge_message(&channel, &user, &message_id).await?;
|
|
||||||
info!("Set new state for ack: {}:{}:{}", channel, user, message_id);
|
info!("Set new state for ack: {}:{}:{}", channel, user, message_id);
|
||||||
|
|
||||||
// if let (Some(before), Some(after)) = (unread, updated) {
|
if let (Some(before), Some(after)) = (unread, updated) {
|
||||||
// let before_mentions = before.mentions.unwrap_or_default().len();
|
let before_mentions = before.mentions.unwrap_or_default().len();
|
||||||
// let after_mentions = after.mentions.unwrap_or_default().len();
|
let after_mentions = after.mentions.unwrap_or_default().len();
|
||||||
|
|
||||||
// let mentions_acked = before_mentions - after_mentions;
|
if after_mentions < before_mentions {
|
||||||
|
if let Err(err) = amqp
|
||||||
// if mentions_acked > 0 {
|
.ack_notification_message(user.to_string(), channel.to_string(), message_id)
|
||||||
// if let Err(err) = amqp
|
.await
|
||||||
// .ack_message(user.to_string(), channel.to_string(), payload.message_id)
|
{
|
||||||
// .await
|
revolt_config::capture_error(&err);
|
||||||
// {
|
}
|
||||||
// revolt_config::capture_error(&err);
|
};
|
||||||
// }
|
}
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user