Added timeago

This commit is contained in:
Rohan Sircar 2020-05-26 13:49:30 +05:30
parent 125fcb51b3
commit 0dc4e09960
2 changed files with 10 additions and 26 deletions

View File

@ -8,6 +8,7 @@ mainClass := Some("wow.doge.chatto.Application")
resolvers += "sfxcode-maven" at "https://bintray.com/sfxcode/maven/" resolvers += "sfxcode-maven" at "https://bintray.com/sfxcode/maven/"
resolvers += "javafx-markdown-renderer" at "https://sandec.bintray.com/repo" 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 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 // https://mvnrepository.com/artifact/org.jsoup/jsoup
libraryDependencies += "org.jsoup" % "jsoup" % "1.13.1" 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) enablePlugins(BuildInfoPlugin)
buildInfoPackage := "wow.doge.chatto" buildInfoPackage := "wow.doge.chatto"

View File

@ -63,6 +63,7 @@ import javafx.scene.control.SelectionMode
import scalafx.beans.property.BooleanProperty import scalafx.beans.property.BooleanProperty
import javafx.scene.control.ListCell import javafx.scene.control.ListCell
import java.time.Instant import java.time.Instant
import com.github.marlonlom.utilities.timeago.TimeAgo
class ChatController @Inject() ( class ChatController @Inject() (
userService: UserService, userService: UserService,
@ -218,39 +219,18 @@ class ChatController @Inject() (
logger.debug(s"Received Users: $maybeActiveUsers") logger.debug(s"Received Users: $maybeActiveUsers")
val maybeUserBoxes = maybeActiveUsers.map(users => { maybeActiveUsers.foreach(users => {
users.map(user => { users.foreach(user => {
val chatData = val chatData =
ChatData(user.userName, user, ObservableBuffer.empty[Message]) ChatData(user.userName, user, ObservableBuffer.empty[Message])
chatDataStore.put(user.userName, new ChatDataProperty(chatData)) 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 { onFX {
// maybeUserBoxes.foreach(userBoxes => {
// usersBuffer ++= userBoxes
// })
maybeActiveUsers.foreach(users => usersBuffer ++= users) 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 chatDataStore
.map { case (key, value) => value } .map { case (key, value) => value }
.foreach(cdp => { .foreach(cdp => {
@ -293,7 +273,7 @@ final case class ChatData(
) { ) {
lazy val lastActiveString = lazy val lastActiveString =
activeUser.lastActive activeUser.lastActive
.map(_.toString()) .map(time => TimeAgo.using(time.toInstant().toEpochMilli()))
.getOrElse("User has not logged in yet") .getOrElse("User has not logged in yet")
lazy val onlineString = activeUser.online.toString() lazy val onlineString = activeUser.online.toString()
} }