fix unread count of compat msg API - closes veloce/lichobile#1561
messages that you never read end up being moved down the list by newer messages. stop counting them as unread after a while. Better fix: use the new inbox API and the lichess notification systempull/8238/head
parent
a8077f952c
commit
b46b9cedda
|
@ -60,7 +60,7 @@ final class Msg(
|
|||
def unreadCount =
|
||||
Auth { ctx => me =>
|
||||
JsonOk {
|
||||
env.msg.api unreadCount me
|
||||
env.msg.compat unreadCount me
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import lila.user.{ User, UserRepo }
|
|||
final class MsgApi(
|
||||
colls: MsgColls,
|
||||
userRepo: UserRepo,
|
||||
cacheApi: lila.memo.CacheApi,
|
||||
lightUserApi: lila.user.LightUserApi,
|
||||
relationApi: lila.relation.RelationApi,
|
||||
json: MsgJson,
|
||||
|
@ -203,15 +202,6 @@ final class MsgApi(
|
|||
notifier.deleteAllBy(threads, user)
|
||||
}
|
||||
|
||||
def unreadCount(me: User): Fu[Int] = unreadCountCache.get(me.id)
|
||||
|
||||
private val unreadCountCache = cacheApi[User.ID, Int](256, "message.unreadCount") {
|
||||
_.expireAfterWrite(10 seconds)
|
||||
.buildAsyncFuture[User.ID, Int] { userId =>
|
||||
colls.thread.countSel($doc("users" -> userId, "lastMsg.read" -> false, "lastMsg.user" $ne userId))
|
||||
}
|
||||
}
|
||||
|
||||
private val msgProjection = $doc("_id" -> false, "tid" -> false).some
|
||||
|
||||
private def threadMsgsFor(threadId: MsgThread.Id, me: User, before: Option[DateTime]): Fu[List[Msg]] =
|
||||
|
|
|
@ -3,17 +3,21 @@ package lila.msg
|
|||
import play.api.data._
|
||||
import play.api.data.Forms._
|
||||
import play.api.libs.json._
|
||||
import reactivemongo.api.ReadPreference
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import lila.common.config._
|
||||
import lila.common.Json.jodaWrites
|
||||
import lila.common.LightUser
|
||||
import lila.common.paginator._
|
||||
import lila.db.dsl._
|
||||
import lila.user.{ LightUserApi, User }
|
||||
|
||||
final class MsgCompat(
|
||||
api: MsgApi,
|
||||
colls: MsgColls,
|
||||
security: MsgSecurity,
|
||||
cacheApi: lila.memo.CacheApi,
|
||||
isOnline: lila.socket.IsOnline,
|
||||
lightUserApi: LightUserApi
|
||||
)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
@ -48,6 +52,25 @@ final class MsgCompat(
|
|||
}
|
||||
}
|
||||
|
||||
def unreadCount(me: User): Fu[Int] = unreadCountCache.get(me.id)
|
||||
|
||||
private val unreadCountCache = cacheApi[User.ID, Int](256, "message.unreadCount") {
|
||||
_.expireAfterWrite(10 seconds)
|
||||
.buildAsyncFuture[User.ID, Int] { userId =>
|
||||
colls.thread
|
||||
.aggregateOne(ReadPreference.secondaryPreferred) { framework =>
|
||||
import framework._
|
||||
Match($doc("users" -> userId)) -> List(
|
||||
Sort(Descending("lastMsg.date")),
|
||||
Limit(maxPerPage.value),
|
||||
Match($doc("lastMsg.read" -> false, "lastMsg.user" $ne userId)),
|
||||
Count("nb")
|
||||
)
|
||||
}
|
||||
.map(~_.flatMap(_.getAsOpt[Int]("nb")))
|
||||
}
|
||||
}
|
||||
|
||||
def thread(me: User, c: MsgConvo): JsObject =
|
||||
Json.obj(
|
||||
"id" -> c.contact.id,
|
||||
|
|
Loading…
Reference in New Issue