Add a name to notification channels

This name is supposed to be used by users to distinguish multiple channels.
This commit is contained in:
eikek
2022-01-17 14:15:07 +01:00
parent 44e599dc86
commit d41490dd88
13 changed files with 140 additions and 40 deletions

View File

@ -0,0 +1,11 @@
alter table "notification_channel_mail"
add column "name" varchar(254);
alter table "notification_channel_gotify"
add column "name" varchar(254);
alter table "notification_channel_matrix"
add column "name" varchar(254);
alter table "notification_channel_http"
add column "name" varchar(254);

View File

@ -0,0 +1,11 @@
alter table `notification_channel_mail`
add column `name` varchar(254);
alter table `notification_channel_gotify`
add column `name` varchar(254);
alter table `notification_channel_matrix`
add column `name` varchar(254);
alter table `notification_channel_http`
add column `name` varchar(254);

View File

@ -0,0 +1,11 @@
alter table "notification_channel_mail"
add column "name" varchar(254);
alter table "notification_channel_gotify"
add column "name" varchar(254);
alter table "notification_channel_matrix"
add column "name" varchar(254);
alter table "notification_channel_http"
add column "name" varchar(254);

View File

@ -70,7 +70,7 @@ trait MigrationTasks {
.map { rec =>
PeriodicDueItemsArgs(
old.account,
Right(Channel.Mail(Ident.unsafe(""), old.smtpConnection, rec)),
Right(Channel.Mail(Ident.unsafe(""), None, old.smtpConnection, rec)),
old.remindDays,
old.daysBack,
old.tagsInclude,

View File

@ -16,7 +16,9 @@ import doobie._
sealed trait RNotificationChannel {
def id: Ident
def id: Ident = fold(_.id, _.id, _.id, _.id)
def name: Option[String] = fold(_.name, _.name, _.name, _.name)
def fold[A](
f1: RNotificationChannelMail => A,
@ -24,7 +26,6 @@ sealed trait RNotificationChannel {
f3: RNotificationChannelMatrix => A,
f4: RNotificationChannelHttp => A
): A
}
object RNotificationChannel {
@ -37,8 +38,6 @@ object RNotificationChannel {
f3: RNotificationChannelMatrix => A,
f4: RNotificationChannelHttp => A
): A = f1(r)
val id = r.id
}
final case class Gotify(r: RNotificationChannelGotify) extends RNotificationChannel {
@ -48,8 +47,6 @@ object RNotificationChannel {
f3: RNotificationChannelMatrix => A,
f4: RNotificationChannelHttp => A
): A = f2(r)
val id = r.id
}
final case class Matrix(r: RNotificationChannelMatrix) extends RNotificationChannel {
@ -59,8 +56,6 @@ object RNotificationChannel {
f3: RNotificationChannelMatrix => A,
f4: RNotificationChannelHttp => A
): A = f3(r)
val id = r.id
}
final case class Http(r: RNotificationChannelHttp) extends RNotificationChannel {
@ -70,8 +65,6 @@ object RNotificationChannel {
f3: RNotificationChannelMatrix => A,
f4: RNotificationChannelHttp => A
): A = f4(r)
val id = r.id
}
def insert(r: RNotificationChannel): ConnectionIO[Int] =

View File

@ -18,6 +18,7 @@ import doobie.implicits._
final case class RNotificationChannelGotify(
id: Ident,
uid: Ident,
name: Option[String],
url: LenientUri,
appKey: Password,
priority: Option[Int],
@ -34,13 +35,14 @@ object RNotificationChannelGotify {
val id = Column[Ident]("id", this)
val uid = Column[Ident]("uid", this)
val name = Column[String]("name", this)
val url = Column[LenientUri]("url", this)
val appKey = Column[Password]("app_key", this)
val priority = Column[Int]("priority", this)
val created = Column[Timestamp]("created", this)
val all: NonEmptyList[Column[_]] =
NonEmptyList.of(id, uid, url, appKey, priority, created)
NonEmptyList.of(id, uid, name, url, appKey, priority, created)
}
val T: Table = Table(None)
@ -54,7 +56,7 @@ object RNotificationChannelGotify {
DML.insert(
T,
T.all,
sql"${r.id},${r.uid},${r.url},${r.appKey},${r.priority},${r.created}"
sql"${r.id},${r.uid},${r.name},${r.url},${r.appKey},${r.priority},${r.created}"
)
def update(r: RNotificationChannelGotify): ConnectionIO[Int] =
@ -64,7 +66,8 @@ object RNotificationChannelGotify {
DML.set(
T.url.setTo(r.url),
T.appKey.setTo(r.appKey),
T.priority.setTo(r.priority)
T.priority.setTo(r.priority),
T.name.setTo(r.name)
)
)

View File

@ -18,6 +18,7 @@ import doobie.implicits._
final case class RNotificationChannelHttp(
id: Ident,
uid: Ident,
name: Option[String],
url: LenientUri,
created: Timestamp
) {
@ -32,11 +33,12 @@ object RNotificationChannelHttp {
val id = Column[Ident]("id", this)
val uid = Column[Ident]("uid", this)
val name = Column[String]("name", this)
val url = Column[LenientUri]("url", this)
val created = Column[Timestamp]("created", this)
val all: NonEmptyList[Column[_]] =
NonEmptyList.of(id, uid, url, created)
NonEmptyList.of(id, uid, name, url, created)
}
val T: Table = Table(None)
@ -47,10 +49,14 @@ object RNotificationChannelHttp {
run(select(T.all), from(T), T.id === id).query[RNotificationChannelHttp].option
def insert(r: RNotificationChannelHttp): ConnectionIO[Int] =
DML.insert(T, T.all, sql"${r.id},${r.uid},${r.url},${r.created}")
DML.insert(T, T.all, sql"${r.id},${r.uid},${r.name},${r.url},${r.created}")
def update(r: RNotificationChannelHttp): ConnectionIO[Int] =
DML.update(T, T.id === r.id && T.uid === r.uid, DML.set(T.url.setTo(r.url)))
DML.update(
T,
T.id === r.id && T.uid === r.uid,
DML.set(T.url.setTo(r.url), T.name.setTo(r.name))
)
def getByAccount(account: AccountId): ConnectionIO[Vector[RNotificationChannelHttp]] = {
val user = RUser.as("u")

View File

@ -19,6 +19,7 @@ import emil.MailAddress
final case class RNotificationChannelMail(
id: Ident,
uid: Ident,
name: Option[String],
connection: Ident,
recipients: List[MailAddress],
created: Timestamp
@ -34,12 +35,13 @@ object RNotificationChannelMail {
val id = Column[Ident]("id", this)
val uid = Column[Ident]("uid", this)
val name = Column[String]("name", this)
val connection = Column[Ident]("conn_id", this)
val recipients = Column[List[MailAddress]]("recipients", this)
val created = Column[Timestamp]("created", this)
val all: NonEmptyList[Column[_]] =
NonEmptyList.of(id, uid, connection, recipients, created)
NonEmptyList.of(id, uid, name, connection, recipients, created)
}
val T: Table = Table(None)
@ -49,7 +51,7 @@ object RNotificationChannelMail {
DML.insert(
T,
T.all,
sql"${r.id},${r.uid},${r.connection},${r.recipients},${r.created}"
sql"${r.id},${r.uid},${r.name},${r.connection},${r.recipients},${r.created}"
)
def update(r: RNotificationChannelMail): ConnectionIO[Int] =
@ -58,7 +60,8 @@ object RNotificationChannelMail {
T.id === r.id && T.uid === r.uid,
DML.set(
T.connection.setTo(r.connection),
T.recipients.setTo(r.recipients.toList)
T.recipients.setTo(r.recipients.toList),
T.name.setTo(r.name)
)
)

View File

@ -18,6 +18,7 @@ import doobie.implicits._
final case class RNotificationChannelMatrix(
id: Ident,
uid: Ident,
name: Option[String],
homeServer: LenientUri,
roomId: String,
accessToken: Password,
@ -34,6 +35,7 @@ object RNotificationChannelMatrix {
val id = Column[Ident]("id", this)
val uid = Column[Ident]("uid", this)
val name = Column[String]("name", this)
val homeServer = Column[LenientUri]("home_server", this)
val roomId = Column[String]("room_id", this)
val accessToken = Column[Password]("access_token", this)
@ -41,7 +43,16 @@ object RNotificationChannelMatrix {
val created = Column[Timestamp]("created", this)
val all: NonEmptyList[Column[_]] =
NonEmptyList.of(id, uid, homeServer, roomId, accessToken, messageType, created)
NonEmptyList.of(
id,
uid,
name,
homeServer,
roomId,
accessToken,
messageType,
created
)
}
val T: Table = Table(None)
def as(alias: String): Table = Table(Some(alias))
@ -50,7 +61,7 @@ object RNotificationChannelMatrix {
DML.insert(
T,
T.all,
sql"${r.id},${r.uid},${r.homeServer},${r.roomId},${r.accessToken},${r.messageType},${r.created}"
sql"${r.id},${r.uid},${r.name},${r.homeServer},${r.roomId},${r.accessToken},${r.messageType},${r.created}"
)
def update(r: RNotificationChannelMatrix): ConnectionIO[Int] =
@ -61,7 +72,8 @@ object RNotificationChannelMatrix {
T.homeServer.setTo(r.homeServer),
T.roomId.setTo(r.roomId),
T.accessToken.setTo(r.accessToken),
T.messageType.setTo(r.messageType)
T.messageType.setTo(r.messageType),
T.name.setTo(r.name)
)
)