Skip to content

Commit

Permalink
pkg:makelint-openimsdk#779
Browse files Browse the repository at this point in the history
Signed-off-by: longyuqing112 <[email protected]>
  • Loading branch information
longyuqing112 committed Feb 24, 2024
1 parent 3c1d096 commit 5e680b4
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 42 deletions.
17 changes: 8 additions & 9 deletions pkg/common/cmd/msg_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

type MsgUtilsCmd struct {
cobra.Command
msgTool *tools.MsgTool
}

func (m *MsgUtilsCmd) AddUserIDFlag() {
Expand All @@ -38,19 +37,19 @@ func (m *MsgUtilsCmd) AddFixAllFlag() {
m.Command.PersistentFlags().BoolP("fixAll", "f", false, "openIM fix all seqs")
}

func (m *MsgUtilsCmd) getFixAllFlag(cmdLines *cobra.Command) bool {
/* func (m *MsgUtilsCmd) getFixAllFlag(cmdLines *cobra.Command) bool {
fixAll, _ := cmdLines.Flags().GetBool("fixAll")
return fixAll
}
} */

func (m *MsgUtilsCmd) AddClearAllFlag() {
m.Command.PersistentFlags().BoolP("clearAll", "c", false, "openIM clear all seqs")
}

func (m *MsgUtilsCmd) getClearAllFlag(cmdLines *cobra.Command) bool {
/* func (m *MsgUtilsCmd) getClearAllFlag(cmdLines *cobra.Command) bool {
clearAll, _ := cmdLines.Flags().GetBool("clearAll")
return clearAll
}
} */

func (m *MsgUtilsCmd) AddSuperGroupIDFlag() {
m.Command.PersistentFlags().StringP("superGroupID", "g", "", "openIM superGroupID")
Expand All @@ -65,19 +64,19 @@ func (m *MsgUtilsCmd) AddBeginSeqFlag() {
m.Command.PersistentFlags().Int64P("beginSeq", "b", 0, "openIM beginSeq")
}

func (m *MsgUtilsCmd) getBeginSeqFlag(cmdLines *cobra.Command) int64 {
/* func (m *MsgUtilsCmd) getBeginSeqFlag(cmdLines *cobra.Command) int64 {
beginSeq, _ := cmdLines.Flags().GetInt64("beginSeq")
return beginSeq
}
} */

func (m *MsgUtilsCmd) AddLimitFlag() {
m.Command.PersistentFlags().Int64P("limit", "l", 0, "openIM limit")
}

func (m *MsgUtilsCmd) getLimitFlag(cmdLines *cobra.Command) int64 {
/* func (m *MsgUtilsCmd) getLimitFlag(cmdLines *cobra.Command) int64 {
limit, _ := cmdLines.Flags().GetInt64("limit")
return limit
}
} */

func (m *MsgUtilsCmd) Execute() error {
return m.Command.Execute()
Expand Down
12 changes: 10 additions & 2 deletions pkg/common/convert/friend.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import (

func FriendPb2DB(friend *sdkws.FriendInfo) *relation.FriendModel {
dbFriend := &relation.FriendModel{}
utils.CopyStructFields(dbFriend, friend)
err := utils.CopyStructFields(dbFriend, friend)
if err != nil {
return nil
}
dbFriend.FriendUserID = friend.FriendUser.UserID
dbFriend.CreateTime = utils.UnixSecondToTime(friend.CreateTime)
return dbFriend
Expand Down Expand Up @@ -69,7 +72,11 @@ func FriendsDB2Pb(
}
for _, friend := range friendsDB {
friendPb := &sdkws.FriendInfo{FriendUser: &sdkws.UserInfo{}}
utils.CopyStructFields(friendPb, friend)
err := utils.CopyStructFields(friendPb, friend)
if err != nil {
return nil, err
}

friendPb.FriendUser.UserID = users[friend.FriendUserID].UserID
friendPb.FriendUser.Nickname = users[friend.FriendUserID].Nickname
friendPb.FriendUser.FaceURL = users[friend.FriendUserID].FaceURL
Expand All @@ -79,6 +86,7 @@ func FriendsDB2Pb(
friendsPb = append(friendsPb, friendPb)
}
return friendsPb, nil

}

func FriendRequestDB2Pb(
Expand Down
49 changes: 24 additions & 25 deletions pkg/common/db/cache/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package cache

import (
"context"
"errors"
"math/big"
"strings"
"time"
Expand Down Expand Up @@ -220,16 +219,16 @@ func (c *ConversationRedisCache) DelConversations(ownerUserID string, conversati
return cache
}

func (c *ConversationRedisCache) getConversationIndex(convsation *relationtb.ConversationModel, keys []string) (int, error) {
key := c.getConversationKey(convsation.OwnerUserID, convsation.ConversationID)
for _i, _key := range keys {
if _key == key {
return _i, nil
}
}
// func (c *ConversationRedisCache) getConversationIndex(convsation *relationtb.ConversationModel, keys []string) (int, error) {
// key := c.getConversationKey(convsation.OwnerUserID, convsation.ConversationID)
// for _i, _key := range keys {
// if _key == key {
// return _i, nil
// }
// }

return 0, errors.New("not found key:" + key + " in keys")
}
// return 0, errors.New("not found key:" + key + " in keys")
// }

func (c *ConversationRedisCache) GetConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*relationtb.ConversationModel, error) {
//var keys []string
Expand Down Expand Up @@ -333,29 +332,29 @@ func (c *ConversationRedisCache) DelSuperGroupRecvMsgNotNotifyUserIDsHash(groupI
return cache
}

func (c *ConversationRedisCache) getUserAllHasReadSeqsIndex(conversationID string, conversationIDs []string) (int, error) {
/* func (c *ConversationRedisCache) getUserAllHasReadSeqsIndex(conversationID string, conversationIDs []string) (int, error) {
for _i, _conversationID := range conversationIDs {
if _conversationID == conversationID {
return _i, nil
}
}
return 0, errors.New("not found key:" + conversationID + " in keys")
}
} */

//func (c *ConversationRedisCache) GetUserAllHasReadSeqs(ctx context.Context, ownerUserID string) (map[string]int64, error) {
// conversationIDs, err := c.GetUserConversationIDs(ctx, ownerUserID)
// if err != nil {
// return nil, err
// }
// var keys []string
// for _, conversarionID := range conversationIDs {
// keys = append(keys, c.getConversationHasReadSeqKey(ownerUserID, conversarionID))
// }
// return batchGetCacheMap(ctx, c.rcClient, keys, conversationIDs, c.expireTime, c.getUserAllHasReadSeqsIndex, func(ctx context.Context) (map[string]int64, error) {
// return c.conversationDB.GetUserAllHasReadSeqs(ctx, ownerUserID)
// })
//}
/* func (c *ConversationRedisCache) GetUserAllHasReadSeqs(ctx context.Context, ownerUserID string) (map[string]int64, error) {
conversationIDs, err := c.GetUserConversationIDs(ctx, ownerUserID)
if err != nil {
return nil, err
}
var keys []string
for _, conversarionID := range conversationIDs {
keys = append(keys, c.getConversationHasReadSeqKey(ownerUserID, conversarionID))
}
return batchGetCacheMap(ctx, c.rcClient, keys, conversationIDs, c.expireTime, c.getUserAllHasReadSeqsIndex, func(ctx context.Context) (map[string]int64, error) {
return c.conversationDB.GetUserAllHasReadSeqs(ctx, ownerUserID)
})
} */

func (c *ConversationRedisCache) DelUserAllHasReadSeqs(ownerUserID string, conversationIDs ...string) ConversationCache {
cache := c.NewCache()
Expand Down
1 change: 1 addition & 0 deletions pkg/common/db/controller/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformI
return "", err
}
}

claims := tokenverify.BuildClaims(userID, platformID, a.accessExpire)
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
tokenString, err := token.SignedString([]byte(a.accessSecret))
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/db/controller/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *conversationDatabase) SetUsersConversationFiledTx(ctx context.Context,
now := time.Now()
for _, v := range NotUserIDs {
temp := new(relationtb.ConversationModel)
if err := utils.CopyStructFields(temp, conversation); err != nil {
if err = utils.CopyStructFields(temp, conversation); err != nil {
return err
}
temp.OwnerUserID = v
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/db/controller/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ func (db *commonMsgDatabase) deleteMsgRecursion(ctx context.Context, conversatio
}
}
if len(delMsgIndexs) > 0 {
if err := db.msgDocDatabase.DeleteMsgsInOneDocByIndex(ctx, msgDocModel.DocID, delMsgIndexs); err != nil {
if err = db.msgDocDatabase.DeleteMsgsInOneDocByIndex(ctx, msgDocModel.DocID, delMsgIndexs); err != nil {
log.ZError(ctx, "deleteMsgRecursion DeleteMsgsInOneDocByIndex failed", err, "conversationID", conversationID, "index", index)
}
delStruct.minSeq = int64(msgDocModel.Msg[delMsgIndexs[len(delMsgIndexs)-1]].Msg.Seq)
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/db/s3/cont/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (c *Controller) InitiateUpload(ctx context.Context, hash string, size int64
partNumber++
}
if maxParts > 0 && partNumber > 0 && partNumber < maxParts {
return nil, errors.New(fmt.Sprintf("too many parts: %d", partNumber))
return nil, fmt.Errorf("too many parts: %d", partNumber)
}
if info, err := c.StatObject(ctx, c.HashPath(hash)); err == nil {
return nil, &HashAlreadyExistsError{Object: info}
Expand Down
4 changes: 2 additions & 2 deletions pkg/common/db/s3/cos/cos.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ const (
const successCode = http.StatusOK

const (
videoSnapshotImagePng = "png"
videoSnapshotImageJpg = "jpg"
// videoSnapshotImagePng = "png"
// videoSnapshotImageJpg = "jpg"
)

func NewCos() (s3.Interface, error) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/common/db/s3/minio/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ func (m *Minio) initMinio(ctx context.Context) error {
return fmt.Errorf("check bucket exists error: %w", err)
}
if !exists {
if err := m.core.Client.MakeBucket(ctx, conf.Bucket, minio.MakeBucketOptions{}); err != nil {
var err error
if err = m.core.Client.MakeBucket(ctx, conf.Bucket, minio.MakeBucketOptions{}); err != nil {
return fmt.Errorf("make bucket error: %w", err)
}
}
Expand Down

0 comments on commit 5e680b4

Please sign in to comment.