mirror of
https://github.com/modrinth/code.git
synced 2026-08-31 03:55:59 +00:00
feat: direct email notification endpoint
This commit is contained in:
@@ -129,12 +129,11 @@ impl NotificationBuilder {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn insert_many(
|
||||
async fn insert_many_records(
|
||||
&self,
|
||||
users: Vec<DBUserId>,
|
||||
users: &[DBUserId],
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
redis: &RedisPool,
|
||||
) -> Result<(), DatabaseError> {
|
||||
) -> Result<Vec<i64>, DatabaseError> {
|
||||
let notification_ids =
|
||||
generate_many_notification_ids(users.len(), &mut *transaction)
|
||||
.await?;
|
||||
@@ -163,6 +162,20 @@ impl NotificationBuilder {
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
Ok(notification_ids)
|
||||
}
|
||||
|
||||
pub async fn insert_many(
|
||||
&self,
|
||||
users: Vec<DBUserId>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
redis: &RedisPool,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let notification_ids =
|
||||
self.insert_many_records(&users, transaction).await?;
|
||||
|
||||
let users_raw_ids = users.iter().map(|x| x.0).collect::<Vec<_>>();
|
||||
|
||||
let notification_types = notification_ids
|
||||
.iter()
|
||||
.map(|_| self.body.notification_type().as_str())
|
||||
@@ -181,6 +194,19 @@ impl NotificationBuilder {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Like [`insert_many`], but skips queuing deliveries so the caller can
|
||||
/// manually send the notifications.
|
||||
pub async fn insert_many_without_delivery(
|
||||
&self,
|
||||
users: Vec<DBUserId>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
redis: &RedisPool,
|
||||
) -> Result<(), DatabaseError> {
|
||||
self.insert_many_records(&users, transaction).await?;
|
||||
DBNotification::clear_user_notifications_cache(&users, redis).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn insert_many_deliveries(
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
redis: &RedisPool,
|
||||
|
||||
Reference in New Issue
Block a user