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 {
return *errResp
} else {
if okResp.MessageIsOld {
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
Success: true,
ErrorID: apierr.NO_ERROR,
ErrorHighlight: -1,
Message: "Message already sent",
SuppressSend: true,
Message: langext.Conditional(okResp.MessageIsOld, "Message already sent", "Message sent"),
SuppressSend: okResp.MessageIsOld,
MessageCount: okResp.User.MessagesSent,
Quota: okResp.User.QuotaUsedToday(),
IsPro: okResp.User.IsPro,
QuotaMax: okResp.User.QuotaPerDay(),
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 {
return *errResp
} else {
if okResp.MessageIsOld {
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
Success: true,
ErrorID: apierr.NO_ERROR,
ErrorHighlight: -1,
Message: "Message already sent",
SuppressSend: true,
Message: langext.Conditional(okResp.MessageIsOld, "Message already sent", "Message sent"),
SuppressSend: okResp.MessageIsOld,
MessageCount: okResp.User.MessagesSent,
Quota: okResp.User.QuotaUsedToday(),
IsPro: okResp.User.IsPro,
QuotaMax: okResp.User.QuotaPerDay(),
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.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{
"ts": time2DB(now),
@ -127,6 +126,9 @@ func (db *Database) IncUserMessageCounter(ctx TxContext, user *models.User) erro
return err
}
user.TimestampLastSent = &now
user.MessagesSent = user.MessagesSent + 1
return nil
}