Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade dependencies #175

Merged
merged 7 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,18 @@ val mainLoop = mirrorEcho
The `updateState` method is a key piece here. Matrix API rely heavily on pagination to keep track of the state, it will by default return the whole state
for a client. By calling `updateState` we make sure to save our current pagination and only ask for newer events to the API.

The last step is to provide and environment to this effect, we are using the amazing [zio-magic](https://github.com/kitlangton/zio-magic) lib to help us with
the `ZLayer` configuration:

```scala
val loggingLayer = Logging.console(
logLevel = LogLevel.Info,
format = LogFormat.ColoredLogFormat()
) >>> Logging.withRootLoggerName("matrix-zio-sync")

mainLoop.inject(
ZEnv.live,
loggingLayer,
MatrixConfiguration.persistent(), // will read/write the configuration from a `bot.conf` file in the project's resources
Authentication.live, // A HTTP middleware that will take care of creating/checking validity of credential/token
AsyncHttpClientZioBackend.layer(), // STTP zio backend to perform HTTP queries
MatrixClient.live // The actual implementation of the client
)
.retry(Schedule.forever)
.exitCode
mainLoop
.withAutoRefresh.retry(Schedule.forever)
.exitCode
.provide(
SyncTokenConfiguration.persistent(),
MatrixConfiguration.live(),
Authentication.live,
HttpClientZioBackend.layer(): TaskLayer[SttpBackend[Task, Any]],
MatrixClient.live,
Matrix.make
)
```

## Examples
Expand Down
6 changes: 3 additions & 3 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import $ivy.`com.goyeau::mill-scalafix::0.3.2`
import com.goyeau.mill.scalafix.ScalafixModule

object Versions {
val zioLoggingVersion = "2.1.16"
val zioVersion = "2.0.20"
val zioLoggingVersion = "2.1.17"
val zioVersion = "2.0.21"
val zioJsonVersion = "0.6.2"
val zioConfigVersion = "3.0.7"
val zioConfigVersion = "4.0.1"
val sttpVersion = "3.9.5"
val scalafixModuleVersion = "0.6.0"
}
Expand Down
12 changes: 7 additions & 5 deletions core/src/com/bot4s/zmatrix/MatrixConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object MatrixConfiguration {
val DEFAULT_API_VERSION = "v3"
val DEFAULT_CONFIG_FILE = "bot.conf"

val configReader = descriptor[MatrixConfiguration]
val configReader = deriveConfig[MatrixConfiguration]

def from(filename: String): Task[MatrixConfiguration] =
fromFile(filename)
Expand All @@ -42,11 +42,13 @@ object MatrixConfiguration {
ConfigParseOptions.defaults.setAllowMissing(false)

private def fromHoconFile(url: URL) =
read(
configReader from ConfigSource.fromTypesafeConfig(
ZIO.attempt(ConfigFactory.parseURL(url, strictSettings.setClassLoader(null)))
ZIO
.attempt(ConfigFactory.parseURL(url, strictSettings.setClassLoader(null)))
.flatMap(config =>
read(
configReader from ConfigProvider.fromTypesafeConfig(config)
)
)
)

private def fromResource(filename: String) = {
val adapted = if (filename.startsWith("/")) filename else s"/$filename"
Expand Down
13 changes: 7 additions & 6 deletions core/src/com/bot4s/zmatrix/SyncTokenConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ object SyncTokenConfiguration {
def get: URIO[SyncTokenConfiguration, SyncToken] = ZIO.serviceWithZIO(_.get)
def set(config: SyncToken): URIO[SyncTokenConfiguration, Unit] = ZIO.serviceWithZIO(_.set(config))

val configReader = descriptor[SyncToken]
val configReader = deriveConfig[SyncToken]

private def refFromFile(filename: String): Task[Ref[SyncToken]] =
for {
file <- ZIO.attempt(new File(filename))
source = ConfigSource.fromHoconFile(file)
source = ConfigProvider.fromHoconFile(file)
config <- read(configReader from source)
result <- Ref.make(config)
} yield result
Expand Down Expand Up @@ -73,13 +73,14 @@ object SyncTokenConfiguration {
override def set(config: SyncToken): UIO[Unit] = {

val updateConf = for {
_ <- configRef.set(config)
file <- ZIO.attempt(new File(filename))
content <- ZIO.fromEither(write(configReader, config))
_ <- configRef.set(config)
file <- ZIO.attempt(new File(filename))
// zio-config 4.X removed the ability to write a config
content = s"""since="${config.since.mkString}""""
_ <-
ZIO.acquireReleaseWith(ZIO.attempt(new BufferedWriter(new FileWriter(file))))(bw =>
ZIO.succeed(bw.close)
)(c => ZIO.attempt(c.write(content.toHoconString)))
)(c => ZIO.attempt(c.write(content)))
} yield ()

updateConf.catchAll(_ => ZIO.succeed(()))
Expand Down
Loading