You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
51 lines
1.6 KiB
package apiThird
|
|
|
|
import (
|
|
api "Open_IM/pkg/api_struct"
|
|
"Open_IM/pkg/common/db"
|
|
"Open_IM/pkg/common/log"
|
|
"Open_IM/pkg/common/tokenverify"
|
|
"Open_IM/pkg/utils"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
func SetAppBadge(c *gin.Context) {
|
|
var (
|
|
req api.SetAppBadgeReq
|
|
resp api.SetAppBadgeResp
|
|
)
|
|
if err := c.Bind(&req); err != nil {
|
|
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
return
|
|
}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
|
|
|
|
var ok bool
|
|
var errInfo, opUserID string
|
|
ok, opUserID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
|
if !ok {
|
|
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg)
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": errMsg})
|
|
return
|
|
}
|
|
if !tokenverify.CheckAccess(c, opUserID, req.FromUserID) {
|
|
log.NewError(req.OperationID, "CheckAccess false ", opUserID, req.FromUserID)
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "no permission"})
|
|
}
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req, opUserID)
|
|
err := db.DB.SetUserBadgeUnreadCountSum(req.FromUserID, int(req.AppUnreadCount))
|
|
if err != nil {
|
|
errMsg := req.OperationID + " " + "SetUserBadgeUnreadCountSum failed " + err.Error() + " token:" + c.Request.Header.Get("token")
|
|
log.NewError(req.OperationID, errMsg)
|
|
resp.ErrCode = 500
|
|
resp.ErrMsg = errMsg
|
|
c.JSON(http.StatusInternalServerError, resp)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, resp)
|
|
return
|
|
}
|