复制项目
This commit is contained in:
197
pkg/rpclient/chat/chat.go
Normal file
197
pkg/rpclient/chat/chat.go
Normal file
@@ -0,0 +1,197 @@
|
||||
// Copyright © 2023 OpenIM open source community. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package chat
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.imall.cloud/openim/chat/pkg/protocol/chat"
|
||||
"git.imall.cloud/openim/chat/pkg/protocol/common"
|
||||
"github.com/openimsdk/tools/errs"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
)
|
||||
|
||||
func NewChatClient(client chat.ChatClient) *ChatClient {
|
||||
return &ChatClient{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
type ChatClient struct {
|
||||
client chat.ChatClient
|
||||
}
|
||||
|
||||
func (o *ChatClient) FindUserPublicInfo(ctx context.Context, userIDs []string) ([]*common.UserPublicInfo, error) {
|
||||
if len(userIDs) == 0 {
|
||||
return []*common.UserPublicInfo{}, nil
|
||||
}
|
||||
resp, err := o.client.FindUserPublicInfo(ctx, &chat.FindUserPublicInfoReq{UserIDs: userIDs})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Users, nil
|
||||
}
|
||||
|
||||
func (o *ChatClient) MapUserPublicInfo(ctx context.Context, userIDs []string) (map[string]*common.UserPublicInfo, error) {
|
||||
users, err := o.FindUserPublicInfo(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return datautil.SliceToMap(users, func(user *common.UserPublicInfo) string {
|
||||
return user.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (o *ChatClient) FindUserFullInfo(ctx context.Context, userIDs []string) ([]*common.UserFullInfo, error) {
|
||||
if len(userIDs) == 0 {
|
||||
return []*common.UserFullInfo{}, nil
|
||||
}
|
||||
resp, err := o.client.FindUserFullInfo(ctx, &chat.FindUserFullInfoReq{UserIDs: userIDs})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Users, nil
|
||||
}
|
||||
|
||||
func (o *ChatClient) MapUserFullInfo(ctx context.Context, userIDs []string) (map[string]*common.UserFullInfo, error) {
|
||||
users, err := o.FindUserFullInfo(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
userMap := make(map[string]*common.UserFullInfo)
|
||||
for i, user := range users {
|
||||
userMap[user.UserID] = users[i]
|
||||
}
|
||||
return userMap, nil
|
||||
}
|
||||
|
||||
func (o *ChatClient) GetUserFullInfo(ctx context.Context, userID string) (*common.UserFullInfo, error) {
|
||||
users, err := o.FindUserFullInfo(ctx, []string{userID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(users) == 0 {
|
||||
return nil, errs.ErrRecordNotFound.WrapMsg("user id not found")
|
||||
}
|
||||
return users[0], nil
|
||||
}
|
||||
|
||||
func (o *ChatClient) GetUserPublicInfo(ctx context.Context, userID string) (*common.UserPublicInfo, error) {
|
||||
users, err := o.FindUserPublicInfo(ctx, []string{userID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(users) == 0 {
|
||||
return nil, errs.ErrRecordNotFound.WrapMsg("user id not found", "userID", userID)
|
||||
}
|
||||
return users[0], nil
|
||||
}
|
||||
|
||||
func (o *ChatClient) UpdateUser(ctx context.Context, req *chat.UpdateUserInfoReq) error {
|
||||
_, err := o.client.UpdateUserInfo(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o *ChatClient) CheckUserExist(ctx context.Context, req *chat.CheckUserExistReq) (resp *chat.CheckUserExistResp, err error) {
|
||||
resp, err = o.client.CheckUserExist(ctx, req)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (o *ChatClient) DelUserAccount(ctx context.Context, req *chat.DelUserAccountReq) (resp *chat.DelUserAccountResp, err error) {
|
||||
resp, err = o.client.DelUserAccount(ctx, req)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// ==================== 敏感词管理相关方法 ====================
|
||||
|
||||
func (o *ChatClient) AddSensitiveWord(ctx context.Context, req *chat.AddSensitiveWordReq) (*chat.AddSensitiveWordResp, error) {
|
||||
return o.client.AddSensitiveWord(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) UpdateSensitiveWord(ctx context.Context, req *chat.UpdateSensitiveWordReq) (*chat.UpdateSensitiveWordResp, error) {
|
||||
return o.client.UpdateSensitiveWord(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) DeleteSensitiveWord(ctx context.Context, req *chat.DeleteSensitiveWordReq) (*chat.DeleteSensitiveWordResp, error) {
|
||||
return o.client.DeleteSensitiveWord(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) GetSensitiveWord(ctx context.Context, req *chat.GetSensitiveWordReq) (*chat.GetSensitiveWordResp, error) {
|
||||
return o.client.GetSensitiveWord(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) SearchSensitiveWords(ctx context.Context, req *chat.SearchSensitiveWordsReq) (*chat.SearchSensitiveWordsResp, error) {
|
||||
return o.client.SearchSensitiveWords(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) BatchAddSensitiveWords(ctx context.Context, req *chat.BatchAddSensitiveWordsReq) (*chat.BatchAddSensitiveWordsResp, error) {
|
||||
return o.client.BatchAddSensitiveWords(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) BatchUpdateSensitiveWords(ctx context.Context, req *chat.BatchUpdateSensitiveWordsReq) (*chat.BatchUpdateSensitiveWordsResp, error) {
|
||||
return o.client.BatchUpdateSensitiveWords(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) BatchDeleteSensitiveWords(ctx context.Context, req *chat.BatchDeleteSensitiveWordsReq) (*chat.BatchDeleteSensitiveWordsResp, error) {
|
||||
return o.client.BatchDeleteSensitiveWords(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) AddSensitiveWordGroup(ctx context.Context, req *chat.AddSensitiveWordGroupReq) (*chat.AddSensitiveWordGroupResp, error) {
|
||||
return o.client.AddSensitiveWordGroup(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) UpdateSensitiveWordGroup(ctx context.Context, req *chat.UpdateSensitiveWordGroupReq) (*chat.UpdateSensitiveWordGroupResp, error) {
|
||||
return o.client.UpdateSensitiveWordGroup(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) DeleteSensitiveWordGroup(ctx context.Context, req *chat.DeleteSensitiveWordGroupReq) (*chat.DeleteSensitiveWordGroupResp, error) {
|
||||
return o.client.DeleteSensitiveWordGroup(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) GetSensitiveWordGroup(ctx context.Context, req *chat.GetSensitiveWordGroupReq) (*chat.GetSensitiveWordGroupResp, error) {
|
||||
return o.client.GetSensitiveWordGroup(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) GetAllSensitiveWordGroups(ctx context.Context, req *chat.GetAllSensitiveWordGroupsReq) (*chat.GetAllSensitiveWordGroupsResp, error) {
|
||||
return o.client.GetAllSensitiveWordGroups(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) GetSensitiveWordConfig(ctx context.Context, req *chat.GetSensitiveWordConfigReq) (*chat.GetSensitiveWordConfigResp, error) {
|
||||
return o.client.GetSensitiveWordConfig(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) UpdateSensitiveWordConfig(ctx context.Context, req *chat.UpdateSensitiveWordConfigReq) (*chat.UpdateSensitiveWordConfigResp, error) {
|
||||
return o.client.UpdateSensitiveWordConfig(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) GetSensitiveWordLogs(ctx context.Context, req *chat.GetSensitiveWordLogsReq) (*chat.GetSensitiveWordLogsResp, error) {
|
||||
return o.client.GetSensitiveWordLogs(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) DeleteSensitiveWordLogs(ctx context.Context, req *chat.DeleteSensitiveWordLogsReq) (*chat.DeleteSensitiveWordLogsResp, error) {
|
||||
return o.client.DeleteSensitiveWordLogs(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) GetSensitiveWordStats(ctx context.Context, req *chat.GetSensitiveWordStatsReq) (*chat.GetSensitiveWordStatsResp, error) {
|
||||
return o.client.GetSensitiveWordStats(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) GetSensitiveWordLogStats(ctx context.Context, req *chat.GetSensitiveWordLogStatsReq) (*chat.GetSensitiveWordLogStatsResp, error) {
|
||||
return o.client.GetSensitiveWordLogStats(ctx, req)
|
||||
}
|
||||
|
||||
func (o *ChatClient) GetUserLoginRecords(ctx context.Context, req *chat.GetUserLoginRecordsReq) (*chat.GetUserLoginRecordsResp, error) {
|
||||
return o.client.GetUserLoginRecords(ctx, req)
|
||||
}
|
||||
Reference in New Issue
Block a user