Skip to content

Commit e179f6e

Browse files
committed
Use HTML patching to adjust current user state
1 parent a740e58 commit e179f6e

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

backend/src/main/scala/com/github/opengrabeso/loctio/rest/UserRestAPIServer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class UserRestAPIServer(val userAuth: Main.GitHubAuthResult) extends UserRestAPI
102102

103103
def userRowHTML(row: common.model.UserRow) = {
104104
//language=HTML
105-
s"""<tr>
105+
s"""<tr data-user="${row.login}">
106106
<td>${getUserStatusIcon(row.currentState)}</td>
107107
<td class="username"><a href="https://www.github.com/${row.login}">${row.login}</a></td>
108108
<td>${row.location}</td>

tray-util/src/main/scala/com/github/opengrabeso/loctio/Start.scala

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ object Start extends SimpleSwingApplication {
276276
val iconName = s"/user-$state.ico"
277277
Tray.setImage(iconName)
278278
mainFrame.peer.setIconImages(iconImages(iconName))
279+
mainFrame.users.html = mainFrame.adjustCurrentUser(mainFrame.usersHtmlString)
280+
279281
}
280282

281283
private object Tray {
@@ -460,6 +462,7 @@ object Start extends SimpleSwingApplication {
460462
peer.addKeyListener(watchKeyboard)
461463

462464

465+
var usersHtmlString = ""
463466
val users = new HtmlPanel(serverUrl)
464467

465468
val notifications = new HtmlPanel(serverUrl) {
@@ -499,8 +502,9 @@ object Start extends SimpleSwingApplication {
499502
}
500503

501504
private def replaceTime(in: String, displayFunc: ZonedDateTime => String): String = {
505+
@scala.annotation.tailrec
502506
def recurse(s: String): String = {
503-
val Time = "(?s)(.*)<time>([^<]+)<\\/time>(.*)".r
507+
val Time = "(?s)(.*)<time>([^<]+)</time>(.*)".r
504508
s match {
505509
case Time(prefix, time, postfix) =>
506510
recurse(prefix + displayFunc(ZonedDateTime.parse(time)) + postfix)
@@ -511,8 +515,19 @@ object Start extends SimpleSwingApplication {
511515
recurse(in)
512516
}
513517

518+
def adjustCurrentUser(in: String): String = {
519+
val CurrentUserState = s"""(?s)(.*<tr data-user="$loginName">[^<]*<td>[^<]*<img[^>]*user-)([a-z]+)(.*)""".r
520+
in match {
521+
case CurrentUserState(prefix, _, postfix) =>
522+
prefix + cfg.state + postfix
523+
case _ =>
524+
in
525+
}
526+
}
527+
514528
def setUsers(usHTML: String, statusText: String): this.type = {
515-
users.html = replaceTime(usHTML, displayTime)
529+
usersHtmlString = replaceTime(usHTML, displayTime)
530+
users.html = adjustCurrentUser(usersHtmlString)
516531
reportTray(replaceTime(statusText, displayTime))
517532
this
518533
}

0 commit comments

Comments
 (0)