mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
Manage notification channels separately and migrate
It's more convenient to manage notification channels separately, as it is done with email settings. Notification hook and other forms are adopted to only select channels. Hooks can now use more than one channel.
This commit is contained in:
@ -7,7 +7,6 @@
|
||||
package docspell.joex.notify
|
||||
|
||||
import cats.data.NonEmptyList
|
||||
import cats.data.OptionT
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
|
||||
@ -24,7 +23,6 @@ import docspell.query.ItemQueryDsl._
|
||||
import docspell.store.qb.Batch
|
||||
import docspell.store.queries.ListItem
|
||||
import docspell.store.queries.{QItem, Query}
|
||||
import docspell.store.records.RUser
|
||||
|
||||
object PeriodicDueItemsTask {
|
||||
val taskName = PeriodicDueItemsArgs.taskName
|
||||
@ -51,11 +49,7 @@ object PeriodicDueItemsTask {
|
||||
def withChannel[F[_]: Sync](ctx: Context[F, Args], ops: ONotification[F])(
|
||||
cont: Vector[NotificationChannel] => F[Unit]
|
||||
): F[Unit] =
|
||||
OptionT(ctx.store.transact(RUser.findIdByAccount(ctx.args.account)))
|
||||
.semiflatMap(userId =>
|
||||
TaskOperations.withChannel(ctx.logger, ctx.args.channel, userId, ops)(cont)
|
||||
)
|
||||
.getOrElse(())
|
||||
TaskOperations.withChannel(ctx.logger, ctx.args.channels, ctx.args.account, ops)(cont)
|
||||
|
||||
def withItems[F[_]: Sync](ctx: Context[F, Args], limit: Int, now: Timestamp)(
|
||||
cont: Vector[ListItem] => F[Unit]
|
||||
|
@ -26,7 +26,6 @@ import docspell.store.queries.ListItem
|
||||
import docspell.store.queries.{QItem, Query}
|
||||
import docspell.store.records.RQueryBookmark
|
||||
import docspell.store.records.RShare
|
||||
import docspell.store.records.RUser
|
||||
|
||||
object PeriodicQueryTask {
|
||||
val taskName = PeriodicQueryArgs.taskName
|
||||
@ -53,11 +52,7 @@ object PeriodicQueryTask {
|
||||
def withChannel[F[_]: Sync](ctx: Context[F, Args], ops: ONotification[F])(
|
||||
cont: Vector[NotificationChannel] => F[Unit]
|
||||
): F[Unit] =
|
||||
OptionT(ctx.store.transact(RUser.findIdByAccount(ctx.args.account)))
|
||||
.semiflatMap(userId =>
|
||||
TaskOperations.withChannel(ctx.logger, ctx.args.channel, userId, ops)(cont)
|
||||
)
|
||||
.getOrElse(())
|
||||
TaskOperations.withChannel(ctx.logger, ctx.args.channels, ctx.args.account, ops)(cont)
|
||||
|
||||
private def queryString(q: ItemQuery.Expr) =
|
||||
ItemQueryParser.asString(q)
|
||||
|
@ -12,7 +12,7 @@ import cats.implicits._
|
||||
|
||||
import docspell.backend.ops.ONotification
|
||||
import docspell.common._
|
||||
import docspell.notification.api.ChannelOrRef
|
||||
import docspell.notification.api.ChannelRef
|
||||
import docspell.notification.api.Event
|
||||
import docspell.notification.api.EventContext
|
||||
import docspell.notification.api.NotificationChannel
|
||||
@ -23,19 +23,18 @@ trait TaskOperations {
|
||||
|
||||
def withChannel[F[_]: Sync](
|
||||
logger: Logger[F],
|
||||
channel: ChannelOrRef,
|
||||
userId: Ident,
|
||||
channelsIn: NonEmptyList[ChannelRef],
|
||||
accountId: AccountId,
|
||||
ops: ONotification[F]
|
||||
)(
|
||||
cont: Vector[NotificationChannel] => F[Unit]
|
||||
): F[Unit] = {
|
||||
val channels = channel match {
|
||||
case Right(ch) => ops.mkNotificationChannel(ch, userId)
|
||||
case Left(ref) => ops.findNotificationChannel(ref)
|
||||
}
|
||||
val channels =
|
||||
channelsIn.toList.toVector.flatTraverse(ops.findNotificationChannel(_, accountId))
|
||||
|
||||
channels.flatMap { ch =>
|
||||
if (ch.isEmpty)
|
||||
logger.error(s"No channels found for the given data: ${channel}")
|
||||
logger.error(s"No channels found for the given data: ${channelsIn}")
|
||||
else cont(ch)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user