mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
Allow a custom message part for the periodic query task
This commit is contained in:
@ -1,7 +1,14 @@
|
||||
/*
|
||||
* Copyright 2020 Eike K. & Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.notification.impl
|
||||
|
||||
import docspell.notification.api.EventContext
|
||||
import docspell.common.Logger
|
||||
import docspell.notification.api.EventContext
|
||||
|
||||
import io.circe.Json
|
||||
|
||||
trait EventContextSyntax {
|
||||
@ -21,7 +28,9 @@ trait EventContextSyntax {
|
||||
case Left(err) => logError(logger)(err)
|
||||
}
|
||||
|
||||
def withDefaultBoth[F[_]](logger: Logger[F])(f: (String, String) => F[Unit]): F[Unit] =
|
||||
def withDefaultBoth[F[_]](
|
||||
logger: Logger[F]
|
||||
)(f: (String, String) => F[Unit]): F[Unit] =
|
||||
(for {
|
||||
md <- self.defaultBoth
|
||||
html <- self.defaultBothHtml
|
||||
|
@ -32,7 +32,9 @@ final case class DeleteFieldValueCtx(
|
||||
|
||||
val titleTemplate = Right(mustache"{{eventType}} (by *{{account.user}}*)")
|
||||
val bodyTemplate =
|
||||
Right(mustache"""{{#content}}{{#field.label}}*{{field.label}}* {{/field.label}}{{^field.label}}*{{field.name}}* {{/field.label}} was removed from {{#items}}{{^-first}}, {{/-first}}{{#itemUrl}}[`{{name}}`]({{{itemUrl}}}/{{{id}}}){{/itemUrl}}{{^itemUrl}}`{{name}}`{{/itemUrl}}{{/items}}.{{/content}}""")
|
||||
Right(
|
||||
mustache"""{{#content}}{{#field.label}}*{{field.label}}* {{/field.label}}{{^field.label}}*{{field.name}}* {{/field.label}} was removed from {{#items}}{{^-first}}, {{/-first}}{{#itemUrl}}[`{{name}}`]({{{itemUrl}}}/{{{id}}}){{/itemUrl}}{{^itemUrl}}`{{name}}`{{/itemUrl}}{{/items}}.{{/content}}"""
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
@ -19,39 +19,29 @@ import doobie._
|
||||
import io.circe.Encoder
|
||||
import io.circe.syntax._
|
||||
import yamusca.implicits._
|
||||
import yamusca.imports._
|
||||
|
||||
final case class ItemSelectionCtx(event: Event.ItemSelection, data: ItemSelectionCtx.Data)
|
||||
extends AbstractEventContext {
|
||||
|
||||
val content = data.asJson
|
||||
|
||||
val titleTemplate = Right(mustache"Your items")
|
||||
val bodyTemplate = Right(mustache"""
|
||||
Hello {{{ content.username }}},
|
||||
val bodyTemplate = event.contentStart match {
|
||||
case Some(cnt) =>
|
||||
mustache
|
||||
.parse(cnt)
|
||||
.leftMap { case (in, err) =>
|
||||
s"Error parsing template: $err! Near ${in.pos}: ${in.raw}."
|
||||
}
|
||||
.map(start => start ++ ItemSelectionCtx.basicBody)
|
||||
|
||||
this is Docspell informing you about your next items.
|
||||
case None =>
|
||||
Right(ItemSelectionCtx.basicBodyStart ++ ItemSelectionCtx.basicBody)
|
||||
}
|
||||
|
||||
{{#content}}
|
||||
{{#itemUrl}}
|
||||
{{#items}}
|
||||
- {{#overDue}}**(OVERDUE)** {{/overDue}}[{{name}}]({{itemUrl}}/{{id}}){{#dueDate}}, {{#overDue}}was {{/overDue}}due {{dueIn}} on *{{dueDate}}*{{/dueDate}}; {{#corrOrg}}from {{corrOrg}}{{/corrOrg}} received on {{date}} via {{source}}
|
||||
{{/items}}
|
||||
{{/itemUrl}}
|
||||
{{^itemUrl}}
|
||||
{{#items}}
|
||||
- {{#overDue}}**(OVERDUE)** {{/overDue}}*{{name}}*{{#dueDate}}, {{#overDue}}was {{/overDue}}due {{dueIn}} on *{{dueDate}}*{{/dueDate}}; {{#corrOrg}}from {{corrOrg}}{{/corrOrg}} received on {{date}} via {{source}}
|
||||
{{/items}}
|
||||
{{/itemUrl}}
|
||||
{{#more}}
|
||||
- … more have been left out for brevity
|
||||
{{/more}}
|
||||
{{/content}}
|
||||
|
||||
|
||||
Sincerely yours,
|
||||
|
||||
Docspell
|
||||
""")
|
||||
implicit final class TemplateOps(self: Template) {
|
||||
def ++(next: Template) = Template(self.els ++ next.els)
|
||||
}
|
||||
}
|
||||
|
||||
object ItemSelectionCtx {
|
||||
@ -113,4 +103,26 @@ object ItemSelectionCtx {
|
||||
account.user.id
|
||||
)
|
||||
}
|
||||
|
||||
private val basicBodyStart = mustache"""
|
||||
Hello {{{ content.username }}},
|
||||
|
||||
this is Docspell informing you about your next items."""
|
||||
|
||||
private val basicBody = mustache"""
|
||||
{{#content}}
|
||||
{{#itemUrl}}
|
||||
{{#items}}
|
||||
- {{#overDue}}**(OVERDUE)** {{/overDue}}[{{name}}]({{itemUrl}}/{{id}}){{#dueDate}}, {{#overDue}}was {{/overDue}}due {{dueIn}} on *{{dueDate}}*{{/dueDate}}; {{#corrOrg}}from {{corrOrg}}{{/corrOrg}} received on {{date}} via {{source}}
|
||||
{{/items}}
|
||||
{{/itemUrl}}
|
||||
{{^itemUrl}}
|
||||
{{#items}}
|
||||
- {{#overDue}}**(OVERDUE)** {{/overDue}}*{{name}}*{{#dueDate}}, {{#overDue}}was {{/overDue}}due {{dueIn}} on *{{dueDate}}*{{/dueDate}}; {{#corrOrg}}from {{corrOrg}}{{/corrOrg}} received on {{date}} via {{source}}
|
||||
{{/items}}
|
||||
{{/itemUrl}}
|
||||
{{#more}}
|
||||
- … more have been left out for brevity
|
||||
{{/more}}
|
||||
{{/content}}"""
|
||||
}
|
||||
|
@ -23,7 +23,9 @@ final case class JobDoneCtx(event: Event.JobDone, data: JobDoneCtx.Data)
|
||||
val content = data.asJson
|
||||
|
||||
val titleTemplate = Right(mustache"{{eventType}} (by *{{account.user}}*)")
|
||||
val bodyTemplate = Right(mustache"""{{#content}}_'{{subject}}'_ finished {{/content}}""")
|
||||
val bodyTemplate = Right(
|
||||
mustache"""{{#content}}_'{{subject}}'_ finished {{/content}}"""
|
||||
)
|
||||
}
|
||||
|
||||
object JobDoneCtx {
|
||||
|
@ -24,7 +24,9 @@ final case class JobSubmittedCtx(event: Event.JobSubmitted, data: JobSubmittedCt
|
||||
|
||||
val titleTemplate = Right(mustache"{{eventType}} (by *{{account.user}}*)")
|
||||
val bodyTemplate =
|
||||
Right(mustache"""{{#content}}_'{{subject}}'_ submitted by {{submitter}} {{/content}}""")
|
||||
Right(
|
||||
mustache"""{{#content}}_'{{subject}}'_ submitted by {{submitter}} {{/content}}"""
|
||||
)
|
||||
}
|
||||
|
||||
object JobSubmittedCtx {
|
||||
|
@ -30,7 +30,9 @@ final case class SetFieldValueCtx(event: Event.SetFieldValue, data: SetFieldValu
|
||||
|
||||
val titleTemplate = Right(mustache"{{eventType}} (by *{{account.user}}*)")
|
||||
val bodyTemplate =
|
||||
Right(mustache"""{{#content}}{{#field.label}}*{{field.label}}* {{/field.label}}{{^field.label}}*{{field.name}}* {{/field.label}} was set to '{{value}}' on {{#items}}{{^-first}}, {{/-first}}{{#itemUrl}}[`{{name}}`]({{{itemUrl}}}/{{{id}}}){{/itemUrl}}{{^itemUrl}}`{{name}}`{{/itemUrl}}{{/items}}.{{/content}}""")
|
||||
Right(
|
||||
mustache"""{{#content}}{{#field.label}}*{{field.label}}* {{/field.label}}{{^field.label}}*{{field.name}}* {{/field.label}} was set to '{{value}}' on {{#items}}{{^-first}}, {{/-first}}{{#itemUrl}}[`{{name}}`]({{{itemUrl}}}/{{{id}}}){{/itemUrl}}{{^itemUrl}}`{{name}}`{{/itemUrl}}{{/items}}.{{/content}}"""
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,9 @@ final case class TagsChangedCtx(event: Event.TagsChanged, data: TagsChangedCtx.D
|
||||
|
||||
val titleTemplate = Right(mustache"{{eventType}} (by *{{account.user}}*)")
|
||||
val bodyTemplate =
|
||||
Right(mustache"""{{#content}}{{#added}}{{#-first}}Adding {{/-first}}{{^-first}}, {{/-first}}*{{name}}*{{/added}}{{#removed}}{{#added}}{{#-first}};{{/-first}}{{/added}}{{#-first}} Removing {{/-first}}{{^-first}}, {{/-first}}*{{name}}*{{/removed}} on {{#items}}{{^-first}}, {{/-first}}{{#itemUrl}}[`{{name}}`]({{{itemUrl}}}/{{{id}}}){{/itemUrl}}{{^itemUrl}}`{{name}}`{{/itemUrl}}{{/items}}.{{/content}}""")
|
||||
Right(
|
||||
mustache"""{{#content}}{{#added}}{{#-first}}Adding {{/-first}}{{^-first}}, {{/-first}}*{{name}}*{{/added}}{{#removed}}{{#added}}{{#-first}};{{/-first}}{{/added}}{{#-first}} Removing {{/-first}}{{^-first}}, {{/-first}}*{{name}}*{{/removed}} on {{#items}}{{^-first}}, {{/-first}}{{#itemUrl}}[`{{name}}`]({{{itemUrl}}}/{{{id}}}){{/itemUrl}}{{^itemUrl}}`{{name}}`{{/itemUrl}}{{/items}}.{{/content}}"""
|
||||
)
|
||||
}
|
||||
|
||||
object TagsChangedCtx {
|
||||
|
@ -46,9 +46,9 @@ class TagsChangedCtxTest extends FunSuite {
|
||||
TagsChangedCtx.Data(account, List(item), List(tag), Nil, url.some.map(_.asString))
|
||||
)
|
||||
|
||||
assertEquals(ctx.defaultTitle, "TagsChanged (by *user2*)")
|
||||
assertEquals(ctx.defaultTitle.toOption.get, "TagsChanged (by *user2*)")
|
||||
assertEquals(
|
||||
ctx.defaultBody,
|
||||
ctx.defaultBody.toOption.get,
|
||||
"Adding *tag-red* on [`Report 2`](http://test/item-1)."
|
||||
)
|
||||
}
|
||||
@ -65,9 +65,9 @@ class TagsChangedCtxTest extends FunSuite {
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals(ctx.defaultTitle, "TagsChanged (by *user2*)")
|
||||
assertEquals(ctx.defaultTitle.toOption.get, "TagsChanged (by *user2*)")
|
||||
assertEquals(
|
||||
ctx.defaultBody,
|
||||
ctx.defaultBody.toOption.get,
|
||||
"Adding *tag-red*; Removing *tag-blue* on [`Report 2`](http://test/item-1)."
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user