chibenwa commented on code in PR #1275:
URL: https://github.com/apache/james-project/pull/1275#discussion_r1006682741


##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/QuotaChangesMethod.scala:
##########
@@ -74,26 +69,15 @@ class QuotaChangesMethod @Inject()(val metricFactory: 
MetricFactory,
 
 }
 
-case class QuotaChangesResolver(private var quotaManager: QuotaManager,
-                                private var quotaRootResolver: 
UserQuotaRootResolver) {
-
+case class QuotaChangesResolver(private val quotaManager: QuotaManager,
+                                private val quotaRootResolver: 
UserQuotaRootResolver) {
   private val jmapQuotaManagerWrapper: JmapQuotaManagerWrapper = 
JmapQuotaManagerWrapper(quotaManager, quotaRootResolver)
 
-  def getLatestState(username: Username, capabilities: 
Set[CapabilityIdentifier]): SMono[State] =
-    jmapQuotaManagerWrapper.retrieveQuotaRoot(username, capabilities)
-      .flatMap(quotaRoot => SMono(quotaManager.getQuotasReactive(quotaRoot)))
+  def getLatestState(username: Username, capabilities: 
Set[CapabilityIdentifier]): SMono[(UuidState, Seq[Id])] =
+    jmapQuotaManagerWrapper.list(username, capabilities)
       .collectSeq()
-      .map(quotasList => evaluateStateFromQuotas(username, capabilities, 
quotasList))
-
-
-  private def evaluateStateFromQuotas(username: Username, capabilities: 
Set[CapabilityIdentifier], quotasList: Seq[QuotaManager.Quotas]): State = {
-    if (!quotasList.exists(quotas => quotas.getMessageQuota.getLimit.isLimited 
|| quotas.getStorageQuota.getLimit.isLimited)) {
-      throw new CanNotCalculateChangesException("Quota is empty, hence we 
cannot calculate changes")
-    }
-
-    val usedTotal: Long = quotasList
-      .map(quotas => quotas.getMessageQuota.getUsed.asLong() + 
quotas.getStorageQuota.getUsed.asLong())
-      .sum
-    
State.of(UUID.nameUUIDFromBytes(s"${username.toString}:${capabilities.map(_.value).mkString("_")}:${usedTotal}".getBytes(StandardCharsets.UTF_8)))
-  }
+      .doOnNext(quotas => if (quotas.isEmpty) {
+        throw new CanNotCalculateChangesException("Quota is empty, hence we 
cannot calculate changes")
+      })

Review Comment:
   Why ?
   
   Technically `JmapQuota.correspondingState(quotas)` handles empty quotas, 
that are stable. 
   
   IMO drop this case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to