Skip to content
This repository was archived by the owner on Feb 17, 2023. It is now read-only.

feat(server:bots) getting cached User object by uid #1001

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,16 @@ object BotMessages {
override def readResponse(obj: Js.Obj): Response = readJs[Response](obj)
}

@key("GetUserById")
final case class GetUserById(
@beanGetter userId: Int
) extends RequestBody {
override type Response = FoundUsers
override val service: String = Services.Users

override def readResponse(obj: Js.Obj): Response = readJs[Response](obj)
}

final case class FoundUsers(users: Seq[User]) extends ResponseBody {
def getUsers = seqAsJavaList(users)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private[bot] final class UsersBotService(system: ActorSystem) extends BotService
case AddUserExtBool(userId, key, value) ⇒ addUserExtBool(userId, key, value).toWeak
case RemoveUserExt(userId, key) ⇒ removeUserExt(userId, key).toWeak
case FindUser(query) ⇒ findUser(query).toWeak
case GetUserById(userId) ⇒ getUserById(userId).toWeak
case IsAdmin(userId) ⇒ isAdmin(userId).toWeak
}

Expand Down Expand Up @@ -77,14 +78,22 @@ private[bot] final class UsersBotService(system: ActorSystem) extends BotService
private def findUser(query: String) = RequestHandler[FindUser, FindUser#Response] {
(botUserId, botAuthId, botAuthSid) ⇒
ifIsAdmin(botUserId) {

(for {
ids ← fromFuture(userExt.findUserIds(query))
users ← fromFuture(ftraverse(ids)(UserUtils.safeGetUser(_, botUserId, botAuthId))) map (_.flatten)
} yield FoundUsers(users)).value
}
}

private def getUserById(userId: Int) = RequestHandler[GetUserById, GetUserById#Response] {
(botUserId, botAuthId, botAuthSid) ⇒
ifIsAdmin(botUserId) {
(for {
users ← fromFuture(ftraverse(Seq(userId))(UserUtils.safeGetUser(_, botUserId, botAuthId))) map (_.flatten)
} yield FoundUsers(users)).value
}
}

private def isAdmin(userId: Int) = RequestHandler[IsAdmin, IsAdmin#Response] {
(botUserId, botAuthId, botAuthSid) ⇒
ifIsAdmin(botUserId) {
Expand Down
2 changes: 1 addition & 1 deletion actor-server/project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ object Build extends sbt.Build with Versioning with Releasing with Packaging {
settings = defaultSettingsServer ++
Seq(libraryDependencies ++= Dependencies.bots)
)
.dependsOn(actorCore, actorHttpApi, actorTestkit % "test")
.dependsOn(actorCore, actorHttpApi, actorBotsShared, actorTestkit % "test")

lazy val actorBotsShared = Project(
id = "actor-bots-shared",
Expand Down