Fix [TestQuotaExceededNoPro, TestQuotaExceededPro]

This commit is contained in:
Mike Schwörer 2023-06-17 20:16:02 +02:00
parent d9a4c4ffd6
commit 7121afab08
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 27 additions and 55 deletions

View File

@ -91,33 +91,18 @@ func (h MessageHandler) SendMessageCompat(g *gin.Context) ginresp.HTTPResponse {
if errResp != nil { if errResp != nil {
return *errResp return *errResp
} else { } else {
if okResp.MessageIsOld {
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{ return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
Success: true, Success: true,
ErrorID: apierr.NO_ERROR, ErrorID: apierr.NO_ERROR,
ErrorHighlight: -1, ErrorHighlight: -1,
Message: "Message already sent", Message: langext.Conditional(okResp.MessageIsOld, "Message already sent", "Message sent"),
SuppressSend: true, SuppressSend: okResp.MessageIsOld,
MessageCount: okResp.User.MessagesSent, MessageCount: okResp.User.MessagesSent,
Quota: okResp.User.QuotaUsedToday(), Quota: okResp.User.QuotaUsedToday(),
IsPro: okResp.User.IsPro, IsPro: okResp.User.IsPro,
QuotaMax: okResp.User.QuotaPerDay(), QuotaMax: okResp.User.QuotaPerDay(),
SCNMessageID: okResp.CompatMessageID, SCNMessageID: okResp.CompatMessageID,
})) }))
} else {
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
Success: true,
ErrorID: apierr.NO_ERROR,
ErrorHighlight: -1,
Message: "Message sent",
SuppressSend: false,
MessageCount: okResp.User.MessagesSent + 1,
Quota: okResp.User.QuotaUsedToday() + 1,
IsPro: okResp.User.IsPro,
QuotaMax: okResp.User.QuotaPerDay(),
SCNMessageID: okResp.CompatMessageID,
}))
}
} }
} }

View File

@ -98,33 +98,18 @@ func (h MessageHandler) SendMessage(g *gin.Context) ginresp.HTTPResponse {
if errResp != nil { if errResp != nil {
return *errResp return *errResp
} else { } else {
if okResp.MessageIsOld {
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{ return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
Success: true, Success: true,
ErrorID: apierr.NO_ERROR, ErrorID: apierr.NO_ERROR,
ErrorHighlight: -1, ErrorHighlight: -1,
Message: "Message already sent", Message: langext.Conditional(okResp.MessageIsOld, "Message already sent", "Message sent"),
SuppressSend: true, SuppressSend: okResp.MessageIsOld,
MessageCount: okResp.User.MessagesSent, MessageCount: okResp.User.MessagesSent,
Quota: okResp.User.QuotaUsedToday(), Quota: okResp.User.QuotaUsedToday(),
IsPro: okResp.User.IsPro, IsPro: okResp.User.IsPro,
QuotaMax: okResp.User.QuotaPerDay(), QuotaMax: okResp.User.QuotaPerDay(),
SCNMessageID: okResp.Message.MessageID, SCNMessageID: okResp.Message.MessageID,
})) }))
} else {
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
Success: true,
ErrorID: apierr.NO_ERROR,
ErrorHighlight: -1,
Message: "Message sent",
SuppressSend: false,
MessageCount: okResp.User.MessagesSent + 1,
Quota: okResp.User.QuotaUsedToday() + 1,
IsPro: okResp.User.IsPro,
QuotaMax: okResp.User.QuotaPerDay(),
SCNMessageID: okResp.Message.MessageID,
}))
}
} }
} }

View File

@ -115,7 +115,6 @@ func (db *Database) IncUserMessageCounter(ctx TxContext, user *models.User) erro
user.QuotaUsed = quota user.QuotaUsed = quota
user.QuotaUsedDay = langext.Ptr(scn.QuotaDayString()) user.QuotaUsedDay = langext.Ptr(scn.QuotaDayString())
user.TimestampLastSent = &now
_, err = tx.Exec(ctx, "UPDATE users SET timestamp_lastsent = :ts, messages_sent = messages_sent+1, quota_used = :qu, quota_used_day = :qd WHERE user_id = :uid", sq.PP{ _, err = tx.Exec(ctx, "UPDATE users SET timestamp_lastsent = :ts, messages_sent = messages_sent+1, quota_used = :qu, quota_used_day = :qd WHERE user_id = :uid", sq.PP{
"ts": time2DB(now), "ts": time2DB(now),
@ -127,6 +126,9 @@ func (db *Database) IncUserMessageCounter(ctx TxContext, user *models.User) erro
return err return err
} }
user.TimestampLastSent = &now
user.MessagesSent = user.MessagesSent + 1
return nil return nil
} }