diff --git a/actor-server/actor-bots-shared/src/main/scala/im/actor/bots/BotMessages.scala b/actor-server/actor-bots-shared/src/main/scala/im/actor/bots/BotMessages.scala index 41b25b906c..f964c04dd3 100644 --- a/actor-server/actor-bots-shared/src/main/scala/im/actor/bots/BotMessages.scala +++ b/actor-server/actor-bots-shared/src/main/scala/im/actor/bots/BotMessages.scala @@ -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) } diff --git a/actor-server/actor-bots/src/main/scala/im/actor/server/bot/services/UsersBotService.scala b/actor-server/actor-bots/src/main/scala/im/actor/server/bot/services/UsersBotService.scala index 917531353f..c36c795bcb 100644 --- a/actor-server/actor-bots/src/main/scala/im/actor/server/bot/services/UsersBotService.scala +++ b/actor-server/actor-bots/src/main/scala/im/actor/server/bot/services/UsersBotService.scala @@ -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 } @@ -77,7 +78,6 @@ 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) @@ -85,6 +85,15 @@ private[bot] final class UsersBotService(system: ActorSystem) extends BotService } } + 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) { diff --git a/actor-server/project/Build.scala b/actor-server/project/Build.scala index 7d27bc16d5..0ba815170a 100644 --- a/actor-server/project/Build.scala +++ b/actor-server/project/Build.scala @@ -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",