Fix websocket frame to user mapping

This commit is contained in:
eikek
2022-08-07 15:17:52 +02:00
parent e9e3e607d3
commit d9485355e9
4 changed files with 10 additions and 11 deletions

View File

@ -7,11 +7,10 @@
package docspell.restserver.conv
import cats.syntax.all._
import docspell.addons.AddonMeta
import docspell.backend.ops.AddonValidationError
import docspell.backend.ops.OAddons.AddonValidationResult
import docspell.common.Ident
import docspell.common.CollectiveId
import docspell.restserver.ws.{OutputEvent, OutputEventEncoder}
import docspell.store.records.RAddonArchive
@ -51,7 +50,7 @@ trait AddonValidationSupport {
}
def addonResultOutputEventEncoder(
collective: Ident
collective: CollectiveId
): OutputEventEncoder[AddonValidationResult[(RAddonArchive, AddonMeta)]] =
OutputEventEncoder.instance {
case Right((archive, _)) =>

View File

@ -34,7 +34,7 @@ object AddonArchiveRoutes extends AddonValidationSupport {
): HttpRoutes[F] = {
val dsl = new Http4sDsl[F] {}
import dsl._
implicit val wsOutputEnc = addonResultOutputEventEncoder(token.account.collective)
implicit val wsOutputEnc = addonResultOutputEventEncoder(token.account.collectiveId)
HttpRoutes.of {
case GET -> Root =>

View File

@ -34,7 +34,7 @@ object OutputEvent {
final case class JobSubmitted(group: Ident, task: Ident) extends OutputEvent {
def forCollective(token: AuthToken): Boolean =
token.account.collective == group
token.account.collectiveId.valueAsIdent == group
def asJson: Json =
Msg("job-submitted", task).asJson
@ -47,7 +47,7 @@ object OutputEvent {
result: Option[Json]
) extends OutputEvent {
def forCollective(token: AuthToken): Boolean =
token.account.collective == group
token.account.collectiveId.valueAsIdent == group
def asJson: Json =
Msg(
@ -56,23 +56,23 @@ object OutputEvent {
).asJson
}
final case class JobsWaiting(collective: Ident, count: Int) extends OutputEvent {
final case class JobsWaiting(collective: CollectiveId, count: Int) extends OutputEvent {
def forCollective(token: AuthToken): Boolean =
token.account.collective == collective
token.account.collectiveId == collective
def asJson: Json =
Msg("jobs-waiting", count).asJson
}
final case class AddonInstalled(
collective: Ident,
collective: CollectiveId,
message: String,
error: Option[AddonValidationError],
addonId: Option[Ident],
originalUrl: Option[LenientUri]
) extends OutputEvent {
def forCollective(token: AuthToken) =
token.account.collective == collective
token.account.collectiveId == collective
override def asJson =
Msg(

View File

@ -34,7 +34,7 @@ object WebSocketRoutes {
val init =
for {
jc <- backend.job.getUnfinishedJobCount(UserTaskScope(user.account))
msg = OutputEvent.JobsWaiting(user.account.collective, jc)
msg = OutputEvent.JobsWaiting(user.account.collectiveId, jc)
} yield Text(msg.encode)
val toClient: Stream[F, WebSocketFrame.Text] =