From e7904a09aa7f6f8894e4b4c5d187fc26ddb29b16 Mon Sep 17 00:00:00 2001 From: yuanjay <2218773049@qq.com> Date: Wed, 15 Nov 2023 02:10:13 +0800 Subject: [PATCH] AcquireAesKey --- pkg/common/db/controller/aes_key.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/pkg/common/db/controller/aes_key.go b/pkg/common/db/controller/aes_key.go index 42b80670f..7ab999f23 100644 --- a/pkg/common/db/controller/aes_key.go +++ b/pkg/common/db/controller/aes_key.go @@ -3,7 +3,9 @@ package controller import ( "context" "crypto/md5" + "errors" "fmt" + "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/tools/tx" "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation" "sort" @@ -25,8 +27,26 @@ func newAesKeyDatabase(key relation.AesKeyModelInterface, tx tx.Tx) *aesKeyDatab } func (a *aesKeyDatabase) AcquireAesKey(ctx context.Context, conversationType int32, userId, friendId, groupId string) (key *relation.AesKeyModel, err error) { - //TODO implement me - panic("implement me") + var keyConversationsID string + switch conversationType { + case constant.SingleChatType: + if userId == "" || friendId == "" { + return nil, errors.New("userId or friendId is null") + } + keyConversationsID = a.generateKeyConversationsID(userId, friendId) + case constant.GroupChatType: + if userId == "" || groupId == "" { + return nil, errors.New("userId or groupId is null") + } + keyConversationsID = a.generateKeyConversationsID(groupId) + default: + return nil, errors.New("conversationType err") + } + aesKey, err := a.key.GetAesKey(ctx, keyConversationsID) + if err != nil { + //生成key,并插入 + } + return aesKey, nil } func (a *aesKeyDatabase) AcquireAesKeys(ctx context.Context, userId string) (key []*relation.AesKeyModel, err error) {