diff --git a/scnserver/api/handler/compat.go b/scnserver/api/handler/compat.go index 108aa4e..9a7277f 100644 --- a/scnserver/api/handler/compat.go +++ b/scnserver/api/handler/compat.go @@ -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, - 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, - })) - } + return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{ + Success: true, + ErrorID: apierr.NO_ERROR, + ErrorHighlight: -1, + 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, + })) } } diff --git a/scnserver/api/handler/message.go b/scnserver/api/handler/message.go index 9d728fa..452e28e 100644 --- a/scnserver/api/handler/message.go +++ b/scnserver/api/handler/message.go @@ -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, - 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, - })) - } + return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{ + Success: true, + ErrorID: apierr.NO_ERROR, + ErrorHighlight: -1, + 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, + })) } } diff --git a/scnserver/db/impl/primary/users.go b/scnserver/db/impl/primary/users.go index 04f6e37..3ee2236 100644 --- a/scnserver/db/impl/primary/users.go +++ b/scnserver/db/impl/primary/users.go @@ -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 }