Merge branch '3.6.1-code-conventions' of https://github.com/FGadvancer/Open-IM-Server into 3.6.1-code-conventions

pull/2148/head
skiffer-git 2 years ago
commit 96c770863d

@ -2,8 +2,6 @@ module github.com/openimsdk/open-im-server/v3
go 1.21
toolchain go1.21.8
require (
firebase.google.com/go v3.13.0+incompatible
github.com/dtm-labs/rockscache v0.1.1
@ -16,7 +14,7 @@ require (
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect
github.com/mitchellh/mapstructure v1.5.0
github.com/openimsdk/localcache v0.0.1
github.com/openimsdk/protocol v0.0.58-google
github.com/openimsdk/protocol v0.0.58
github.com/openimsdk/tools v0.0.47-alpha.10
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.18.0

@ -257,8 +257,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/openimsdk/protocol v0.0.58-google h1:cGNUVaXO9LqcFgIb4NvrtEOrv0spGecoQKyN8YWhyZs=
github.com/openimsdk/protocol v0.0.58-google/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
github.com/openimsdk/protocol v0.0.58 h1:wxCZBty7zNOcBsiZmrZRQLtaLPv4UpGyxLZp1GGrwic=
github.com/openimsdk/protocol v0.0.58/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
github.com/openimsdk/tools v0.0.47-alpha.10 h1:bel44PB4xcC1uO+1y/LYhgsPmAGpxrlNd8JaFL4yc50=
github.com/openimsdk/tools v0.0.47-alpha.10/go.mod h1:mUsH+ANKbdmhUih43ijJHvuYcU8owm7X3kdFH7FsIec=
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=

@ -16,7 +16,6 @@ package api
import (
"context"
"errors"
"fmt"
"github.com/openimsdk/tools/db/redisutil"
"net"
@ -54,8 +53,7 @@ import (
func Start(ctx context.Context, config *config.GlobalConfig, port int, proPort int) error {
if port == 0 || proPort == 0 {
wrappedErr := errs.WrapMsg(errors.New("port or proPort is empty"), "validation error", "port", port, "proPort", proPort)
return wrappedErr
return errs.New("port or proPort is empty", "port", port, "proPort", proPort).Wrap()
}
rdb, err := redisutil.NewRedisClient(ctx, config.Redis.Build())
if err != nil {

@ -16,7 +16,6 @@ package msggateway
import (
"context"
"errors"
"fmt"
"runtime/debug"
"sync"
@ -34,10 +33,10 @@ import (
)
var (
ErrConnClosed = errors.New("conn has closed")
ErrNotSupportMessageProtocol = errors.New("not support message protocol")
ErrClientClosed = errors.New("client actively close the connection")
ErrPanic = errors.New("panic error")
ErrConnClosed = errs.New("conn has closed")
ErrNotSupportMessageProtocol = errs.New("not support message protocol")
ErrClientClosed = errs.New("client actively close the connection")
ErrPanic = errs.New("panic error")
)
const (
@ -187,7 +186,7 @@ func (c *Client) handleMessage(message []byte) error {
}
if binaryReq.SendID != c.UserID {
return errs.WrapMsg(errors.New("exception conn userID not same to req userID"), binaryReq.String())
return errs.New("exception conn userID not same to req userID", "binaryReq", binaryReq.String())
}
ctx := mcontext.WithMustInfoCtx(
@ -267,7 +266,7 @@ func (c *Client) replyMessage(ctx context.Context, binaryReq *Req, err error, re
}
if binaryReq.ReqIdentifier == WsLogoutMsg {
return errs.WrapMsg(errors.New("user logout"), "user requested logout", "operationID", binaryReq.OperationID)
return errs.New("user logout", "operationID", binaryReq.OperationID).Wrap()
}
return nil
}

@ -15,7 +15,6 @@
package msggateway
import (
"errors"
"net/http"
"time"
@ -99,9 +98,8 @@ func (d *GWebSocket) SetReadDeadline(timeout time.Duration) error {
}
func (d *GWebSocket) SetWriteDeadline(timeout time.Duration) error {
// TODO add error
if timeout <= 0 {
return errs.Wrap(errors.New("timeout must be greater than 0"))
return errs.New("timeout must be greater than 0")
}
// TODO SetWriteDeadline Future add error handling

@ -17,7 +17,6 @@ package msggateway
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
@ -59,13 +58,6 @@ type LongConnServer interface {
MessageHandler
}
// bufferPool is unused
// var bufferPool = sync.Pool{
// New: func() any {
// return make([]byte, 1024)
// },
// }
type WsServer struct {
globalConfig *config.GlobalConfig
port int
@ -128,10 +120,7 @@ func (ws *WsServer) UnRegister(c *Client) {
ws.unregisterChan <- c
}
func (ws *WsServer) Validate(s any) error {
if s == nil {
return errs.WrapMsg(errors.New("input cannot be nil"), "Validate: input is nil", "action", "validate", "dataType", "any")
}
func (ws *WsServer) Validate(_ any) error {
return nil
}
@ -372,7 +361,7 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien
log.ZWarn(
newClient.ctx,
"m is nil",
errors.New("m is nil"),
errs.New("m is nil"),
"userID",
newClient.UserID,
"platformID",

@ -16,7 +16,6 @@ package msgtransfer
import (
"context"
"errors"
"fmt"
"github.com/openimsdk/tools/db/mongoutil"
"github.com/openimsdk/tools/db/redisutil"
@ -114,7 +113,7 @@ func NewMsgTransfer(kafkaConf *config.Kafka, msgDatabase controller.CommonMsgDat
func (m *MsgTransfer) Start(prometheusPort int, config *config.GlobalConfig, index int) error {
if prometheusPort <= 0 {
return errs.WrapMsg(errors.New("invalid prometheus port"), "prometheusPort validation failed", "providedPort", prometheusPort)
return errs.New("invalid prometheus port", "prometheusPort", prometheusPort)
}
m.ctx, m.cancel = context.WithCancel(context.Background())

@ -18,7 +18,6 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
"errors"
"strconv"
"sync"
"time"
@ -35,8 +34,8 @@ import (
)
var (
ErrTokenExpire = errors.New("token expire")
ErrUserIDEmpty = errors.New("userIDs is empty")
ErrTokenExpire = errs.New("token expire")
ErrUserIDEmpty = errs.New("userIDs is empty")
)
const (

@ -15,7 +15,7 @@
package body
import (
"errors"
"github.com/openimsdk/tools/errs"
"github.com/openimsdk/protocol/constant"
)
@ -39,7 +39,7 @@ func (p *Platform) Set(os string) error {
} else {
switch p.Os.(type) {
case string:
return errors.New("platform is all")
return errs.New("platform is all")
default:
}
}
@ -61,7 +61,7 @@ func (p *Platform) Set(os string) error {
p.osArry = append(p.osArry, os)
p.Os = p.osArry
default:
return errors.New("unknow platform")
return errs.New("unknow platform")
}
return nil
@ -74,7 +74,7 @@ func (p *Platform) SetPlatform(platform string) error {
case constant.IOSPlatformStr:
return p.SetIOS()
default:
return errors.New("platform err")
return errs.New("platform err")
}
}

@ -17,7 +17,7 @@ package push
import (
"context"
"encoding/json"
"errors"
"github.com/openimsdk/tools/errs"
"sync"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush"
@ -59,7 +59,7 @@ type Pusher struct {
groupRpcClient *rpcclient.GroupRpcClient
}
var errNoOfflinePusher = errors.New("no offlinePusher is configured")
var errNoOfflinePusher = errs.New("no offlinePusher is configured")
func NewPusher(config *config.GlobalConfig, discov discovery.SvcDiscoveryRegistry, offlinePusher offlinepush.OfflinePusher, database controller.PushDatabase,
groupLocalCache *rpccache.GroupLocalCache, conversationLocalCache *rpccache.ConversationLocalCache,

@ -16,7 +16,6 @@ package conversation
import (
"context"
"errors"
"github.com/openimsdk/tools/db/redisutil"
"sort"
@ -315,12 +314,7 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver
// Get user IDs with "Do Not Disturb" enabled in super large groups.
func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(ctx context.Context, req *pbconversation.GetRecvMsgNotNotifyUserIDsReq) (*pbconversation.GetRecvMsgNotNotifyUserIDsResp, error) {
// userIDs, err := c.conversationDatabase.FindRecvMsgNotNotifyUserIDs(ctx, req.GroupID)
// if err != nil {
// return nil, err
//}
// return &pbconversation.GetRecvMsgNotNotifyUserIDsResp{UserIDs: userIDs}, nil
return nil, errors.New("deprecated")
return nil, errs.New("deprecated")
}
// create conversation without notification for msg redis transfer.

@ -299,7 +299,6 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbgroup.CreateGroupR
}
}()
} else {
// s.Notification.GroupCreatedNotification(ctx, group, groupMembers, userMap)
tips := &sdkws.GroupCreatedTips{
Group: resp.GroupInfo,
OperationTime: group.CreateTime.UnixMilli(),
@ -333,7 +332,6 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbgroup.CreateGroupR
}
func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbgroup.GetJoinedGroupListReq) (*pbgroup.GetJoinedGroupListResp, error) {
resp := &pbgroup.GetJoinedGroupListResp{}
if err := authverify.CheckAccessV3(ctx, req.FromUserID, &s.config.Manager, &s.config.IMAdmin); err != nil {
return nil, err
}
@ -341,9 +339,10 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbgroup.GetJo
if err != nil {
return nil, err
}
var resp pbgroup.GetJoinedGroupListResp
resp.Total = uint32(total)
if len(members) == 0 {
return resp, nil
return &resp, nil
}
groupIDs := datautil.Slice(members, func(e *relationtb.GroupMemberModel) string {
return e.GroupID
@ -375,12 +374,10 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbgroup.GetJo
}
return convert.Db2PbGroupInfo(group, userID, groupMemberNum[group.GroupID])
})
return resp, nil
return &resp, nil
}
func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbgroup.InviteUserToGroupReq) (*pbgroup.InviteUserToGroupResp, error) {
resp := &pbgroup.InviteUserToGroupResp{}
if len(req.InvitedUserIDs) == 0 {
return nil, errs.ErrArgs.WrapMsg("user empty")
}
@ -453,7 +450,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbgroup.Invite
InviterUserID: request.InviterUserID,
})
}
return resp, nil
return &pbgroup.InviteUserToGroupResp{}, nil
}
}
}
@ -484,7 +481,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbgroup.Invite
return nil, err
}
s.Notification.MemberInvitedNotification(ctx, req.GroupID, req.Reason, req.InvitedUserIDs)
return resp, nil
return &pbgroup.InviteUserToGroupResp{}, nil
}
func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbgroup.GetGroupAllMemberReq) (*pbgroup.GetGroupAllMemberResp, error) {
@ -495,15 +492,14 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbgroup.GetGro
if err := s.PopulateGroupMember(ctx, members...); err != nil {
return nil, err
}
resp := &pbgroup.GetGroupAllMemberResp{}
var resp pbgroup.GetGroupAllMemberResp
resp.Members = datautil.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo {
return convert.Db2PbGroupMember(e)
})
return resp, nil
return &resp, nil
}
func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbgroup.GetGroupMemberListReq) (*pbgroup.GetGroupMemberListResp, error) {
resp := &pbgroup.GetGroupMemberListResp{}
var (
total int64
members []*relationtb.GroupMemberModel
@ -535,18 +531,19 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbgroup.GetGr
}
}
GMembers := datautil.Paginate(groupMembers, int(req.Pagination.GetPageNumber()), int(req.Pagination.GetShowNumber()))
resp.Members = datautil.Batch(convert.Db2PbGroupMember, GMembers)
resp.Total = uint32(total)
return resp, nil
members := datautil.Paginate(groupMembers, int(req.Pagination.GetPageNumber()), int(req.Pagination.GetShowNumber()))
return &pbgroup.GetGroupMemberListResp{
Total: uint32(total),
Members: datautil.Batch(convert.Db2PbGroupMember, members),
}, nil
}
resp.Total = uint32(total)
resp.Members = datautil.Batch(convert.Db2PbGroupMember, members)
return resp, nil
return &pbgroup.GetGroupMemberListResp{
Total: uint32(total),
Members: datautil.Batch(convert.Db2PbGroupMember, members),
}, nil
}
func (s *groupServer) KickGroupMember(ctx context.Context, req *pbgroup.KickGroupMemberReq) (*pbgroup.KickGroupMemberResp, error) {
resp := &pbgroup.KickGroupMemberResp{}
group, err := s.db.TakeGroup(ctx, req.GroupID)
if err != nil {
return nil, err
@ -652,11 +649,10 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbgroup.KickGrou
if err := CallbackKillGroupMember(ctx, killGroupMemberConfig, req); err != nil {
return nil, err
}
return resp, nil
return &pbgroup.KickGroupMemberResp{}, nil
}
func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbgroup.GetGroupMembersInfoReq) (*pbgroup.GetGroupMembersInfoResp, error) {
resp := &pbgroup.GetGroupMembersInfoResp{}
if len(req.UserIDs) == 0 {
return nil, errs.ErrArgs.WrapMsg("userIDs empty")
}
@ -670,10 +666,11 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbgroup.GetG
if err := s.PopulateGroupMember(ctx, members...); err != nil {
return nil, err
}
resp.Members = datautil.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo {
return &pbgroup.GetGroupMembersInfoResp{
Members: datautil.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo {
return convert.Db2PbGroupMember(e)
})
return resp, nil
}),
}, nil
}
// GetGroupApplicationList handles functions that get a list of group requests.
@ -739,7 +736,6 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbgroup.
}
func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbgroup.GetGroupsInfoReq) (*pbgroup.GetGroupsInfoResp, error) {
resp := &pbgroup.GetGroupsInfoResp{}
if len(req.GroupIDs) == 0 {
return nil, errs.ErrArgs.WrapMsg("groupID is empty")
}
@ -761,14 +757,15 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbgroup.GetGroupsI
ownerMap := datautil.SliceToMap(owners, func(e *relationtb.GroupMemberModel) string {
return e.GroupID
})
resp.GroupInfos = datautil.Slice(groups, func(e *relationtb.GroupModel) *sdkws.GroupInfo {
return &pbgroup.GetGroupsInfoResp{
GroupInfos: datautil.Slice(groups, func(e *relationtb.GroupModel) *sdkws.GroupInfo {
var ownerUserID string
if owner, ok := ownerMap[e.GroupID]; ok {
ownerUserID = owner.UserID
}
return convert.Db2PbGroupInfo(e, ownerUserID, groupMemberNumMap[e.GroupID])
})
return resp, nil
}),
}, nil
}
func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbgroup.GroupApplicationResponseReq) (*pbgroup.GroupApplicationResponseResp, error) {
@ -887,7 +884,6 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbgroup.JoinGroupReq)
return nil, err
}
log.ZInfo(ctx, "JoinGroup.groupInfo", "group", group, "eq", group.NeedVerification == constant.Directly)
resp = &pbgroup.JoinGroupResp{}
if group.NeedVerification == constant.Directly {
groupMember := &relationtb.GroupMemberModel{
GroupID: group.GroupID,
@ -914,7 +910,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbgroup.JoinGroupReq)
if err = CallbackAfterJoinGroup(ctx, afterJoinGroupConfig, req); err != nil {
return nil, err
}
return resp, nil
return &pbgroup.JoinGroupResp{}, nil
}
groupRequest := relationtb.GroupRequestModel{
UserID: req.InviterUserID,
@ -929,11 +925,10 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbgroup.JoinGroupReq)
return nil, err
}
s.Notification.JoinGroupApplicationNotification(ctx, req)
return resp, nil
return &pbgroup.JoinGroupResp{}, nil
}
func (s *groupServer) QuitGroup(ctx context.Context, req *pbgroup.QuitGroupReq) (*pbgroup.QuitGroupResp, error) {
resp := &pbgroup.QuitGroupResp{}
if req.UserID == "" {
req.UserID = mcontext.GetOpUserID(ctx)
} else {
@ -968,7 +963,7 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbgroup.QuitGroupReq)
if err := CallbackQuitGroup(ctx, quitGroupConfig, req); err != nil {
return nil, err
}
return resp, nil
return &pbgroup.QuitGroupResp{}, nil
}
func (s *groupServer) deleteMemberAndSetConversationSeq(ctx context.Context, groupID string, userIDs []string) error {
@ -1011,7 +1006,6 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbgroup.SetGroupInf
if group.Status == constant.GroupStatusDismissed {
return nil, servererrs.ErrDismissedAlready.Wrap()
}
resp := &pbgroup.SetGroupInfoResp{}
count, err := s.db.FindGroupMemberNum(ctx, group.GroupID)
if err != nil {
@ -1026,7 +1020,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbgroup.SetGroupInf
}
update := UpdateGroupInfoMap(ctx, req.GroupInfoForSet)
if len(update) == 0 {
return resp, nil
return &pbgroup.SetGroupInfoResp{}, nil
}
if err := s.db.UpdateGroup(ctx, group.GroupID, update); err != nil {
return nil, err
@ -1076,11 +1070,10 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbgroup.SetGroupInf
if err := CallbackAfterSetGroupInfo(ctx, afterSetGroupInfoConfig, req); err != nil {
return nil, err
}
return resp, nil
return &pbgroup.SetGroupInfoResp{}, nil
}
func (s *groupServer) TransferGroupOwner(ctx context.Context, req *pbgroup.TransferGroupOwnerReq) (*pbgroup.TransferGroupOwnerResp, error) {
resp := &pbgroup.TransferGroupOwnerResp{}
group, err := s.db.TakeGroup(ctx, req.GroupID)
if err != nil {
return nil, err
@ -1128,16 +1121,15 @@ func (s *groupServer) TransferGroupOwner(ctx context.Context, req *pbgroup.Trans
return nil, err
}
s.Notification.GroupOwnerTransferredNotification(ctx, req)
return resp, nil
return &pbgroup.TransferGroupOwnerResp{}, nil
}
func (s *groupServer) GetGroups(ctx context.Context, req *pbgroup.GetGroupsReq) (*pbgroup.GetGroupsResp, error) {
resp := &pbgroup.GetGroupsResp{}
var (
group []*relationtb.GroupModel
err error
)
var resp pbgroup.GetGroupsResp
if req.GroupID != "" {
group, err = s.db.FindGroup(ctx, []string{req.GroupID})
resp.Total = uint32(len(group))
@ -1178,15 +1170,15 @@ func (s *groupServer) GetGroups(ctx context.Context, req *pbgroup.GetGroupsReq)
}
return convert.Db2PbCMSGroup(group, userID, username, groupMemberNumMap[group.GroupID])
})
return resp, nil
return &resp, nil
}
func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbgroup.GetGroupMembersCMSReq) (*pbgroup.GetGroupMembersCMSResp, error) {
resp := &pbgroup.GetGroupMembersCMSResp{}
total, members, err := s.db.SearchGroupMember(ctx, req.UserName, req.GroupID, req.Pagination)
if err != nil {
return nil, err
}
var resp pbgroup.GetGroupMembersCMSResp
resp.Total = uint32(total)
if err := s.PopulateGroupMember(ctx, members...); err != nil {
return nil, err
@ -1194,11 +1186,10 @@ func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbgroup.GetGr
resp.Members = datautil.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo {
return convert.Db2PbGroupMember(e)
})
return resp, nil
return &resp, nil
}
func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbgroup.GetUserReqApplicationListReq) (*pbgroup.GetUserReqApplicationListResp, error) {
resp := &pbgroup.GetUserReqApplicationListResp{}
user, err := s.User.GetPublicUserInfo(ctx, req.UserID)
if err != nil {
return nil, err
@ -1207,9 +1198,8 @@ func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbgrou
if err != nil {
return nil, err
}
resp.Total = uint32(total)
if len(requests) == 0 {
return resp, nil
return &pbgroup.GetUserReqApplicationListResp{Total: uint32(total)}, nil
}
groupIDs := datautil.Distinct(datautil.Slice(requests, func(e *relationtb.GroupRequestModel) string {
return e.GroupID
@ -1235,18 +1225,19 @@ func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbgrou
if err != nil {
return nil, err
}
resp.GroupRequests = datautil.Slice(requests, func(e *relationtb.GroupRequestModel) *sdkws.GroupRequest {
return &pbgroup.GetUserReqApplicationListResp{
Total: uint32(total),
GroupRequests: datautil.Slice(requests, func(e *relationtb.GroupRequestModel) *sdkws.GroupRequest {
var ownerUserID string
if owner, ok := ownerMap[e.GroupID]; ok {
ownerUserID = owner.UserID
}
return convert.Db2PbGroupRequest(e, user, convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerUserID, groupMemberNum[e.GroupID]))
})
return resp, nil
}),
}, nil
}
func (s *groupServer) DismissGroup(ctx context.Context, req *pbgroup.DismissGroupReq) (*pbgroup.DismissGroupResp, error) {
resp := &pbgroup.DismissGroupResp{}
owner, err := s.db.TakeGroupOwner(ctx, req.GroupID)
if err != nil {
return nil, err
@ -1303,11 +1294,10 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbgroup.DismissGrou
return nil, err
}
return resp, nil
return &pbgroup.DismissGroupResp{}, nil
}
func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbgroup.MuteGroupMemberReq) (*pbgroup.MuteGroupMemberResp, error) {
resp := &pbgroup.MuteGroupMemberResp{}
member, err := s.db.TakeGroupMember(ctx, req.GroupID, req.UserID)
if err != nil {
return nil, err
@ -1338,7 +1328,7 @@ func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbgroup.MuteGrou
return nil, err
}
s.Notification.GroupMemberMutedNotification(ctx, req.GroupID, req.UserID, req.MutedSeconds)
return resp, nil
return &pbgroup.MuteGroupMemberResp{}, nil
}
func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbgroup.CancelMuteGroupMemberReq) (*pbgroup.CancelMuteGroupMemberResp, error) {
@ -1376,7 +1366,6 @@ func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbgroup.Ca
}
func (s *groupServer) MuteGroup(ctx context.Context, req *pbgroup.MuteGroupReq) (*pbgroup.MuteGroupResp, error) {
resp := &pbgroup.MuteGroupResp{}
if err := s.CheckGroupAdmin(ctx, req.GroupID); err != nil {
return nil, err
}
@ -1384,11 +1373,10 @@ func (s *groupServer) MuteGroup(ctx context.Context, req *pbgroup.MuteGroupReq)
return nil, err
}
s.Notification.GroupMutedNotification(ctx, req.GroupID)
return resp, nil
return &pbgroup.MuteGroupResp{}, nil
}
func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbgroup.CancelMuteGroupReq) (*pbgroup.CancelMuteGroupResp, error) {
resp := &pbgroup.CancelMuteGroupResp{}
if err := s.CheckGroupAdmin(ctx, req.GroupID); err != nil {
return nil, err
}
@ -1396,11 +1384,10 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbgroup.CancelMu
return nil, err
}
s.Notification.GroupCancelMutedNotification(ctx, req.GroupID)
return resp, nil
return &pbgroup.CancelMuteGroupResp{}, nil
}
func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbgroup.SetGroupMemberInfoReq) (*pbgroup.SetGroupMemberInfoResp, error) {
resp := &pbgroup.SetGroupMemberInfoResp{}
if len(req.Members) == 0 {
return nil, errs.ErrArgs.WrapMsg("members empty")
}
@ -1530,11 +1517,10 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbgroup.SetGr
}
}
return resp, nil
return &pbgroup.SetGroupMemberInfoResp{}, nil
}
func (s *groupServer) GetGroupAbstractInfo(ctx context.Context, req *pbgroup.GetGroupAbstractInfoReq) (*pbgroup.GetGroupAbstractInfoResp, error) {
resp := &pbgroup.GetGroupAbstractInfoResp{}
if len(req.GroupIDs) == 0 {
return nil, errs.ErrArgs.WrapMsg("groupIDs empty")
}
@ -1557,15 +1543,15 @@ func (s *groupServer) GetGroupAbstractInfo(ctx context.Context, req *pbgroup.Get
if ids := datautil.Single(req.GroupIDs, datautil.Keys(groupUserMap)); len(ids) > 0 {
return nil, servererrs.ErrGroupIDNotFound.WrapMsg(fmt.Sprintf("group %s not found member", strings.Join(ids, ",")))
}
resp.GroupAbstractInfos = datautil.Slice(groups, func(group *relationtb.GroupModel) *pbgroup.GroupAbstractInfo {
return &pbgroup.GetGroupAbstractInfoResp{
GroupAbstractInfos: datautil.Slice(groups, func(group *relationtb.GroupModel) *pbgroup.GroupAbstractInfo {
users := groupUserMap[group.GroupID]
return convert.Db2PbGroupAbstractInfo(group.GroupID, users.MemberNum, users.Hash)
})
return resp, nil
}),
}, nil
}
func (s *groupServer) GetUserInGroupMembers(ctx context.Context, req *pbgroup.GetUserInGroupMembersReq) (*pbgroup.GetUserInGroupMembersResp, error) {
resp := &pbgroup.GetUserInGroupMembersResp{}
if len(req.GroupIDs) == 0 {
return nil, errs.ErrArgs.WrapMsg("groupIDs empty")
}
@ -1576,23 +1562,24 @@ func (s *groupServer) GetUserInGroupMembers(ctx context.Context, req *pbgroup.Ge
if err := s.PopulateGroupMember(ctx, members...); err != nil {
return nil, err
}
resp.Members = datautil.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo {
return &pbgroup.GetUserInGroupMembersResp{
Members: datautil.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo {
return convert.Db2PbGroupMember(e)
})
return resp, nil
}),
}, nil
}
func (s *groupServer) GetGroupMemberUserIDs(ctx context.Context, req *pbgroup.GetGroupMemberUserIDsReq) (resp *pbgroup.GetGroupMemberUserIDsResp, err error) {
resp = &pbgroup.GetGroupMemberUserIDsResp{}
resp.UserIDs, err = s.db.FindGroupMemberUserID(ctx, req.GroupID)
userIDs, err := s.db.FindGroupMemberUserID(ctx, req.GroupID)
if err != nil {
return nil, err
}
return resp, nil
return &pbgroup.GetGroupMemberUserIDsResp{
UserIDs: userIDs,
}, nil
}
func (s *groupServer) GetGroupMemberRoleLevel(ctx context.Context, req *pbgroup.GetGroupMemberRoleLevelReq) (*pbgroup.GetGroupMemberRoleLevelResp, error) {
resp := &pbgroup.GetGroupMemberRoleLevelResp{}
if len(req.RoleLevels) == 0 {
return nil, errs.ErrArgs.WrapMsg("RoleLevels empty")
}
@ -1603,20 +1590,20 @@ func (s *groupServer) GetGroupMemberRoleLevel(ctx context.Context, req *pbgroup.
if err := s.PopulateGroupMember(ctx, members...); err != nil {
return nil, err
}
resp.Members = datautil.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo {
return &pbgroup.GetGroupMemberRoleLevelResp{
Members: datautil.Slice(members, func(e *relationtb.GroupMemberModel) *sdkws.GroupMemberFullInfo {
return convert.Db2PbGroupMember(e)
})
return resp, nil
}),
}, nil
}
func (s *groupServer) GetGroupUsersReqApplicationList(ctx context.Context, req *pbgroup.GetGroupUsersReqApplicationListReq) (*pbgroup.GetGroupUsersReqApplicationListResp, error) {
resp := &pbgroup.GetGroupUsersReqApplicationListResp{}
requests, err := s.db.FindGroupRequests(ctx, req.GroupID, req.UserIDs)
if err != nil {
return nil, err
}
if len(requests) == 0 {
return resp, nil
return &pbgroup.GetGroupUsersReqApplicationListResp{}, nil
}
groupIDs := datautil.Distinct(datautil.Slice(requests, func(e *relationtb.GroupRequestModel) string {
return e.GroupID
@ -1645,13 +1632,14 @@ func (s *groupServer) GetGroupUsersReqApplicationList(ctx context.Context, req *
if err != nil {
return nil, err
}
resp.GroupRequests = datautil.Slice(requests, func(e *relationtb.GroupRequestModel) *sdkws.GroupRequest {
return &pbgroup.GetGroupUsersReqApplicationListResp{
Total: int64(len(requests)),
GroupRequests: datautil.Slice(requests, func(e *relationtb.GroupRequestModel) *sdkws.GroupRequest {
var ownerUserID string
if owner, ok := ownerMap[e.GroupID]; ok {
ownerUserID = owner.UserID
}
return convert.Db2PbGroupRequest(e, nil, convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerUserID, groupMemberNum[e.GroupID]))
})
resp.Total = int64(len(resp.GroupRequests))
return resp, nil
}),
}, nil
}

@ -1,31 +0,0 @@
// Copyright © 2023 OpenIM. 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 group
import (
"context"
"errors"
pbgroup "github.com/openimsdk/protocol/group"
"github.com/openimsdk/tools/errs"
)
func (s *groupServer) GetJoinedSuperGroupList(context.Context, *pbgroup.GetJoinedSuperGroupListReq) (*pbgroup.GetJoinedSuperGroupListResp, error) {
return nil, errs.WrapMsg(errors.New("GetJoinedSuperGroupList is deprecated"), "This feature is deprecated and no longer supported.")
}
func (s *groupServer) GetSuperGroupsInfo(context.Context, *pbgroup.GetSuperGroupsInfoReq) (resp *pbgroup.GetSuperGroupsInfoResp, err error) {
return nil, errs.WrapMsg(errors.New("GetSuperGroupsInfo is deprecated"), "This feature is deprecated and no longer supported.")
}

@ -16,7 +16,6 @@ package third
import (
"context"
"errors"
"fmt"
"strings"
"unicode/utf8"
@ -65,17 +64,17 @@ func (t *thirdServer) checkUploadName(ctx context.Context, name string) error {
func checkValidObjectNamePrefix(objectName string) error {
if len(objectName) > 1024 {
return errors.New("object name cannot be longer than 1024 characters")
return errs.New("object name cannot be longer than 1024 characters")
}
if !utf8.ValidString(objectName) {
return errors.New("object name with non UTF-8 strings are not supported")
return errs.New("object name with non UTF-8 strings are not supported")
}
return nil
}
func checkValidObjectName(objectName string) error {
if strings.TrimSpace(objectName) == "" {
return errors.New("object name cannot be empty")
return errs.New("object name cannot be empty")
}
return checkValidObjectNamePrefix(objectName)
}

@ -16,7 +16,6 @@ package user
import (
"context"
"errors"
"github.com/openimsdk/tools/db/redisutil"
"math/rand"
"strings"
@ -71,7 +70,7 @@ func Start(ctx context.Context, config *config.GlobalConfig, client registry.Svc
}
users := make([]*tablerelation.UserModel, 0)
if len(config.IMAdmin.UserID) != len(config.IMAdmin.Nickname) {
return errs.Wrap(errors.New("the count of ImAdmin.UserID is not equal to the count of ImAdmin.Nickname"))
return errs.New("the count of ImAdmin.UserID is not equal to the count of ImAdmin.Nickname").Wrap()
}
for k, v := range config.IMAdmin.UserID {
users = append(users, &tablerelation.UserModel{UserID: v, Nickname: config.IMAdmin.Nickname[k], AppMangerLevel: constant.AppNotificationAdmin})

@ -16,8 +16,6 @@ package cmd
import (
"context"
"errors"
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/open-im-server/v3/pkg/common/startrpc"
"github.com/openimsdk/protocol/constant"
@ -70,7 +68,7 @@ func (a *RpcCmd) Exec() error {
func (a *RpcCmd) StartSvr(name string, rpcFn func(ctx context.Context, config *config2.GlobalConfig, disCov discovery.SvcDiscoveryRegistry, server *grpc.Server) error) error {
if a.GetPortFlag() == 0 {
return errs.Wrap(errors.New("port is required"))
return errs.New("port is required").Wrap()
}
return startrpc.Start(a.ctx, a.GetPortFlag(), name, a.GetPrometheusPortFlag(), a.config, rpcFn)
}
@ -156,5 +154,5 @@ func (a *RpcCmd) GetRpcRegisterNameFromConfig() (string, error) {
case RpcUserServer:
return a.config.RpcRegisterName.OpenImUserName, nil
}
return "", errs.WrapMsg(errors.New("unrecognized RPC server name"), "providedName", a.Name, "hint", "Check if the server name is correctly configured")
return "", errs.New("unrecognized RPC server name", "rpcName", a.Name).Wrap()
}

@ -233,7 +233,7 @@ func (c *ConversationRedisCache) DelConversations(ownerUserID string, conversati
// }
// }
// return 0, errors.New("not found key:" + key + " in keys")
// return 0, errs.New("not found key:" + key + " in keys")
// }
func (c *ConversationRedisCache) GetConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*relationtb.ConversationModel, error) {
@ -338,30 +338,6 @@ func (c *ConversationRedisCache) DelSuperGroupRecvMsgNotNotifyUserIDsHash(groupI
return cache
}
/* 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) DelUserAllHasReadSeqs(ownerUserID string, conversationIDs ...string) ConversationCache {
cache := c.NewCache()
for _, conversationID := range conversationIDs {

@ -17,7 +17,6 @@ package cache
import (
"context"
"encoding/json"
"errors"
"fmt"
"time"
@ -35,7 +34,7 @@ const (
retryInterval = time.Millisecond * 100
)
var errIndex = errors.New("err index")
var errIndex = errs.New("err index")
type metaCache interface {
ExecDel(ctx context.Context, distinct ...bool) error

@ -17,7 +17,6 @@ package controller
import (
"context"
"encoding/json"
"errors"
"time"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
@ -363,10 +362,10 @@ func (db *commonMsgDatabase) BatchInsertChat2Cache(ctx context.Context, conversa
}
lenList := len(msgs)
if int64(lenList) > db.msg.GetSingleGocMsgNum() {
return 0, false, errs.WrapMsg(errors.New("message count exceeds limit"), "limit", db.msg.GetSingleGocMsgNum())
return 0, false, errs.New("message count exceeds limit", "limit", db.msg.GetSingleGocMsgNum()).Wrap()
}
if lenList < 1 {
return 0, false, errs.WrapMsg(errors.New("no messages to insert"), "minCount", 1)
return 0, false, errs.New("no messages to insert", "minCount", 1).Wrap()
}
if errs.Unwrap(err) == redis.Nil {
isNew = true

@ -16,7 +16,6 @@ package relation
import (
"context"
"errors"
"strconv"
"time"
@ -33,7 +32,7 @@ const (
NewestList = -1
)
var ErrMsgListNotExist = errors.New("user not have msg in mongoDB")
var ErrMsgListNotExist = errs.New("user not have msg in mongoDB")
type MsgDocModel struct {
DocID string `bson:"doc_id"`

@ -16,7 +16,6 @@ package direct
import (
"context"
"errors"
"fmt"
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
@ -108,7 +107,7 @@ func (cd *ConnDirect) GetConns(ctx context.Context,
}
if len(connections) == 0 {
return nil, errs.WrapMsg(errors.New("no connections found for service"), "serviceName", serviceName)
return nil, errs.New("no connections found for service", "serviceName", serviceName).Wrap()
}
return connections, nil
}
@ -119,7 +118,7 @@ func (cd *ConnDirect) GetConn(ctx context.Context, serviceName string, opts ...g
&cd.config.RpcPort, cd.config.LongConnSvr.OpenImMessageGatewayPort)
address, ok := addresses[serviceName]
if !ok {
return nil, errs.WrapMsg(errors.New("unknown service name"), "serviceName", serviceName)
return nil, errs.New("unknown service name", "serviceName", serviceName).Wrap()
}
var result string
for _, addr := range address {

@ -15,7 +15,6 @@
package discoveryregister
import (
"errors"
"os"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
@ -41,7 +40,6 @@ func NewDiscoveryRegister(config *config.GlobalConfig) (discovery.SvcDiscoveryRe
case "direct":
return direct.NewConnDirect(config)
default:
errMsg := "unsupported discovery type"
return nil, errs.WrapMsg(errors.New(errMsg), errMsg, "type", config.Envs.Discovery)
return nil, errs.New("unsupported discovery type", "type", config.Envs.Discovery).Wrap()
}
}

@ -92,12 +92,7 @@ func TestName(t *testing.T) {
defer wg.Done()
//t.Log(key)
fn(key, 10000, func() (string, error) {
//time.Sleep(time.Second * 3)
//t.Log(time.Now(), "key", key, "fetch")
//if rand.Uint32()%5 == 0 {
// return "value_" + key, nil
//}
//return "", errors.New("rand error")
return "value_" + key, nil
})
}()

@ -18,7 +18,6 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
@ -39,7 +38,7 @@ type Api struct {
func (a *Api) apiPost(ctx context.Context, path string, req any, resp any) error {
operationID, _ := ctx.Value("operationID").(string)
if operationID == "" {
return errors.New("call api operationID is empty")
return errs.New("call api operationID is empty")
}
reqBody, err := json.Marshal(req)
if err != nil {

Loading…
Cancel
Save