From 0dc4e0996042bd5072ef7dcfb78197942b6eede3 Mon Sep 17 00:00:00 2001 From: Rohan Sircar Date: Tue, 26 May 2020 13:49:30 +0530 Subject: [PATCH] Added timeago --- build.sbt | 4 +++ .../chatto/controller/ChatController.scala | 32 ++++--------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/build.sbt b/build.sbt index ac2ba3a..f08d3a6 100644 --- a/build.sbt +++ b/build.sbt @@ -8,6 +8,7 @@ mainClass := Some("wow.doge.chatto.Application") resolvers += "sfxcode-maven" at "https://bintray.com/sfxcode/maven/" resolvers += "javafx-markdown-renderer" at "https://sandec.bintray.com/repo" +resolvers += "marlonlon-timeago" at "https://dl.bintray.com/marlonlom/timeago" libraryDependencies += "org.specs2" %% "specs2-core" % "4.7.1" % Test @@ -70,6 +71,9 @@ libraryDependencies += "org.json4s" %% "json4s-ext" % "3.6.8" // https://mvnrepository.com/artifact/org.jsoup/jsoup libraryDependencies += "org.jsoup" % "jsoup" % "1.13.1" +// https://mvnrepository.com/artifact/com.github.marlonlom/timeago +libraryDependencies += "com.github.marlonlom" % "timeago" % "3.0.2" + enablePlugins(BuildInfoPlugin) buildInfoPackage := "wow.doge.chatto" diff --git a/src/main/scala/wow/doge/chatto/controller/ChatController.scala b/src/main/scala/wow/doge/chatto/controller/ChatController.scala index 5deffa2..5ad195f 100644 --- a/src/main/scala/wow/doge/chatto/controller/ChatController.scala +++ b/src/main/scala/wow/doge/chatto/controller/ChatController.scala @@ -63,6 +63,7 @@ import javafx.scene.control.SelectionMode import scalafx.beans.property.BooleanProperty import javafx.scene.control.ListCell import java.time.Instant +import com.github.marlonlom.utilities.timeago.TimeAgo class ChatController @Inject() ( userService: UserService, @@ -218,39 +219,18 @@ class ChatController @Inject() ( logger.debug(s"Received Users: $maybeActiveUsers") - val maybeUserBoxes = maybeActiveUsers.map(users => { - users.map(user => { + maybeActiveUsers.foreach(users => { + users.foreach(user => { val chatData = ChatData(user.userName, user, ObservableBuffer.empty[Message]) chatDataStore.put(user.userName, new ChatDataProperty(chatData)) - new UserBox2(user.userName, chatData) { - this.styleClass ++= Seq("text-white") - } }) }) - // val messageBox = ChatDataProperty.createMdMessageBox2( - // """**Hello world qefwew yeeehay bwergqwevqcqe** - // |**Hello world qefwew yeeehay bwergqwevqcqe** - // | - // | Hello World - // """.stripMargin - // ) + onFX { - // maybeUserBoxes.foreach(userBoxes => { - // usersBuffer ++= userBoxes - // }) maybeActiveUsers.foreach(users => usersBuffer ++= users) - chatListView.items() ++= Seq( - // messageBox, - // ChatDataProperty.createMdMessageBox2("hello"), - // ChatDataProperty.createMdMessageBox2( - // """ 1. Hello world qefwew yeeehay bwergqwevqcqe - // |1. Hello world qefwew yeeehay bwergqwevqcqe - // |1. Hello world qefwew yeeehay bwergqwevqcqe - // |1. Hello world qefwew yeeehay bwergqwevqcqe""".stripMargin - // ) - ) } + chatDataStore .map { case (key, value) => value } .foreach(cdp => { @@ -293,7 +273,7 @@ final case class ChatData( ) { lazy val lastActiveString = activeUser.lastActive - .map(_.toString()) + .map(time => TimeAgo.using(time.toInstant().toEpochMilli())) .getOrElse("User has not logged in yet") lazy val onlineString = activeUser.online.toString() }