mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-08 05:27:03 +08:00
fix: fix rest lint errors in pkg
This commit is contained in:
parent
4bd9acbd6d
commit
85cab0b4b3
@ -4,12 +4,14 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/OpenIMSDK/tools/discoveryregistry"
|
||||
openkeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper"
|
||||
"github.com/OpenIMSDK/tools/log"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"google.golang.org/grpc"
|
||||
"time"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
)
|
||||
|
||||
func NewDiscoveryRegister(envType string) (discoveryregistry.SvcDiscoveryRegistry, error) {
|
||||
@ -28,6 +30,7 @@ func NewDiscoveryRegister(envType string) (discoveryregistry.SvcDiscoveryRegistr
|
||||
client = nil
|
||||
err = errors.New("envType not correct")
|
||||
}
|
||||
|
||||
return client, err
|
||||
}
|
||||
|
||||
@ -42,47 +45,51 @@ func NewK8sDiscoveryRegister() (discoveryregistry.SvcDiscoveryRegistry, error) {
|
||||
|
||||
func (cli *K8sDR) Register(serviceName, host string, port int, opts ...grpc.DialOption) error {
|
||||
cli.rpcRegisterAddr = serviceName
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *K8sDR) UnRegister() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *K8sDR) CreateRpcRootNodes(serviceNames []string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
func (cli *K8sDR) RegisterConf2Registry(key string, conf []byte) error {
|
||||
|
||||
func (cli *K8sDR) RegisterConf2Registry(key string, conf []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *K8sDR) GetConfFromRegistry(key string) ([]byte, error) {
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
func (cli *K8sDR) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error) {
|
||||
|
||||
func (cli *K8sDR) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error) {
|
||||
conn, err := grpc.DialContext(ctx, serviceName, append(cli.options, opts...)...)
|
||||
|
||||
return []*grpc.ClientConn{conn}, err
|
||||
}
|
||||
func (cli *K8sDR) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
|
||||
|
||||
func (cli *K8sDR) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
|
||||
return grpc.DialContext(ctx, serviceName, append(cli.options, opts...)...)
|
||||
}
|
||||
func (cli *K8sDR) GetSelfConnTarget() string {
|
||||
|
||||
func (cli *K8sDR) GetSelfConnTarget() string {
|
||||
return cli.rpcRegisterAddr
|
||||
}
|
||||
|
||||
func (cli *K8sDR) AddOption(opts ...grpc.DialOption) {
|
||||
cli.options = append(cli.options, opts...)
|
||||
}
|
||||
|
||||
func (cli *K8sDR) CloseConn(conn *grpc.ClientConn) {
|
||||
conn.Close()
|
||||
}
|
||||
|
||||
// do not use this method for call rpc
|
||||
// do not use this method for call rpc.
|
||||
func (cli *K8sDR) GetClientLocalConns() map[string][]*grpc.ClientConn {
|
||||
fmt.Println("should not call this function!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -34,16 +34,21 @@ import (
|
||||
var client http.Client
|
||||
|
||||
func Get(url string) (response []byte, err error) {
|
||||
client := http.Client{Timeout: 5 * time.Second}
|
||||
resp, err := client.Get(url)
|
||||
clientGet := http.Client{Timeout: 5 * time.Second}
|
||||
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err2 := clientGet.Do(req)
|
||||
if err2 != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
body, err3 := io.ReadAll(resp.Body)
|
||||
if err3 != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return body, nil
|
||||
}
|
||||
|
||||
@ -83,6 +88,7 @@ func Post(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@ -98,6 +104,7 @@ func PostReturn(
|
||||
return err
|
||||
}
|
||||
err = json.Unmarshal(b, output)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -116,17 +123,22 @@ func callBackPostReturn(
|
||||
if err != nil {
|
||||
if callbackConfig.CallbackFailedContinue != nil && *callbackConfig.CallbackFailedContinue {
|
||||
log.ZWarn(ctx, "callback failed but continue", err, "url", url)
|
||||
|
||||
return errs.ErrCallbackContinue
|
||||
}
|
||||
|
||||
return errs.ErrNetwork.Wrap(err.Error())
|
||||
}
|
||||
if err = json.Unmarshal(b, output); err != nil {
|
||||
if callbackConfig.CallbackFailedContinue != nil && *callbackConfig.CallbackFailedContinue {
|
||||
log.ZWarn(ctx, "callback failed but continue", err, "url", url)
|
||||
|
||||
return errs.ErrCallbackContinue
|
||||
}
|
||||
|
||||
return errs.ErrData.Wrap(err.Error())
|
||||
}
|
||||
|
||||
return output.Parse()
|
||||
}
|
||||
|
||||
|
||||
@ -51,6 +51,7 @@ func NewMConsumerGroup(consumerConfig *MConsumerGroupConfig, topics, addrs []str
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
return &MConsumerGroup{
|
||||
consumerGroup,
|
||||
groupID,
|
||||
|
||||
@ -67,6 +67,7 @@ func NewKafkaProducer(addr []string, topic string) *Producer {
|
||||
producer, err = sarama.NewSyncProducer(p.addr, p.config) // Initialize the client
|
||||
if err == nil {
|
||||
p.producer = producer
|
||||
|
||||
return &p
|
||||
}
|
||||
//TODO If the password is wrong, exit directly
|
||||
@ -83,6 +84,7 @@ func NewKafkaProducer(addr []string, topic string) *Producer {
|
||||
panic(err.Error())
|
||||
}
|
||||
p.producer = producer
|
||||
|
||||
return &p
|
||||
}
|
||||
|
||||
@ -91,6 +93,7 @@ func GetMQHeaderWithContext(ctx context.Context) ([]sarama.RecordHeader, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return []sarama.RecordHeader{
|
||||
{Key: []byte(constant.OperationID), Value: []byte(operationID)},
|
||||
{Key: []byte(constant.OpUserID), Value: []byte(opUserID)},
|
||||
@ -100,10 +103,11 @@ func GetMQHeaderWithContext(ctx context.Context) ([]sarama.RecordHeader, error)
|
||||
}
|
||||
|
||||
func GetContextWithMQHeader(header []*sarama.RecordHeader) context.Context {
|
||||
var values []string
|
||||
values := make([]string, 0, len(header))
|
||||
for _, recordHeader := range header {
|
||||
values = append(values, string(recordHeader.Value))
|
||||
}
|
||||
|
||||
return mcontext.WithMustInfoCtx(values) // TODO
|
||||
}
|
||||
|
||||
@ -134,5 +138,6 @@ func (p *Producer) SendMessage(ctx context.Context, key string, msg proto.Messag
|
||||
if err == nil {
|
||||
prome.Inc(prome.SendMsgCounter)
|
||||
}
|
||||
|
||||
return partition, offset, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
@ -42,11 +42,13 @@ func (l *LockerMessage) LockMessageTypeKey(ctx context.Context, clientMsgID, typ
|
||||
err = l.cache.LockMessageTypeKey(ctx, clientMsgID, typeKey)
|
||||
if err != nil {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -55,11 +57,13 @@ func (l *LockerMessage) LockGlobalMessage(ctx context.Context, clientMsgID strin
|
||||
err = l.cache.LockMessageTypeKey(ctx, clientMsgID, GlOBALLOCK)
|
||||
if err != nil {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@ -79,6 +79,7 @@ var (
|
||||
ConversationCreateFailedCounter prometheus.Counter
|
||||
)
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewUserLoginCounter() {
|
||||
if UserLoginCounter != nil {
|
||||
return
|
||||
@ -89,6 +90,7 @@ func NewUserLoginCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewUserRegisterCounter() {
|
||||
if UserRegisterCounter != nil {
|
||||
return
|
||||
@ -99,6 +101,7 @@ func NewUserRegisterCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewSeqGetSuccessCounter() {
|
||||
if SeqGetSuccessCounter != nil {
|
||||
return
|
||||
@ -109,6 +112,7 @@ func NewSeqGetSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewSeqGetFailedCounter() {
|
||||
if SeqGetFailedCounter != nil {
|
||||
return
|
||||
@ -119,6 +123,7 @@ func NewSeqGetFailedCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewSeqSetSuccessCounter() {
|
||||
if SeqSetSuccessCounter != nil {
|
||||
return
|
||||
@ -129,6 +134,7 @@ func NewSeqSetSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewSeqSetFailedCounter() {
|
||||
if SeqSetFailedCounter != nil {
|
||||
return
|
||||
@ -139,6 +145,7 @@ func NewSeqSetFailedCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewApiRequestCounter() {
|
||||
if ApiRequestCounter != nil {
|
||||
return
|
||||
@ -149,6 +156,7 @@ func NewApiRequestCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewApiRequestSuccessCounter() {
|
||||
if ApiRequestSuccessCounter != nil {
|
||||
return
|
||||
@ -159,6 +167,7 @@ func NewApiRequestSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewApiRequestFailedCounter() {
|
||||
if ApiRequestFailedCounter != nil {
|
||||
return
|
||||
@ -169,6 +178,7 @@ func NewApiRequestFailedCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewGrpcRequestCounter() {
|
||||
if GrpcRequestCounter != nil {
|
||||
return
|
||||
@ -179,6 +189,7 @@ func NewGrpcRequestCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewGrpcRequestSuccessCounter() {
|
||||
if GrpcRequestSuccessCounter != nil {
|
||||
return
|
||||
@ -189,6 +200,7 @@ func NewGrpcRequestSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewGrpcRequestFailedCounter() {
|
||||
if GrpcRequestFailedCounter != nil {
|
||||
return
|
||||
@ -199,6 +211,7 @@ func NewGrpcRequestFailedCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewSendMsgCount() {
|
||||
if SendMsgCounter != nil {
|
||||
return
|
||||
@ -209,6 +222,7 @@ func NewSendMsgCount() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewMsgInsertRedisSuccessCounter() {
|
||||
if MsgInsertRedisSuccessCounter != nil {
|
||||
return
|
||||
@ -219,6 +233,7 @@ func NewMsgInsertRedisSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix its
|
||||
func NewMsgInsertRedisFailedCounter() {
|
||||
if MsgInsertRedisFailedCounter != nil {
|
||||
return
|
||||
@ -229,6 +244,7 @@ func NewMsgInsertRedisFailedCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewMsgInsertMongoSuccessCounter() {
|
||||
if MsgInsertMongoSuccessCounter != nil {
|
||||
return
|
||||
@ -239,6 +255,7 @@ func NewMsgInsertMongoSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewMsgInsertMongoFailedCounter() {
|
||||
if MsgInsertMongoFailedCounter != nil {
|
||||
return
|
||||
@ -249,6 +266,7 @@ func NewMsgInsertMongoFailedCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewMsgPullFromRedisSuccessCounter() {
|
||||
if MsgPullFromRedisSuccessCounter != nil {
|
||||
return
|
||||
@ -259,6 +277,7 @@ func NewMsgPullFromRedisSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewMsgPullFromRedisFailedCounter() {
|
||||
if MsgPullFromRedisFailedCounter != nil {
|
||||
return
|
||||
@ -269,6 +288,7 @@ func NewMsgPullFromRedisFailedCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewMsgPullFromMongoSuccessCounter() {
|
||||
if MsgPullFromMongoSuccessCounter != nil {
|
||||
return
|
||||
@ -279,6 +299,7 @@ func NewMsgPullFromMongoSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewMsgPullFromMongoFailedCounter() {
|
||||
if MsgPullFromMongoFailedCounter != nil {
|
||||
return
|
||||
@ -319,6 +340,7 @@ func NewPullMsgBySeqListTotalCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewSingleChatMsgRecvSuccessCounter() {
|
||||
if SingleChatMsgRecvSuccessCounter != nil {
|
||||
return
|
||||
@ -329,6 +351,7 @@ func NewSingleChatMsgRecvSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewGroupChatMsgRecvSuccessCounter() {
|
||||
if GroupChatMsgRecvSuccessCounter != nil {
|
||||
return
|
||||
@ -339,6 +362,7 @@ func NewGroupChatMsgRecvSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewWorkSuperGroupChatMsgRecvSuccessCounter() {
|
||||
if WorkSuperGroupChatMsgRecvSuccessCounter != nil {
|
||||
return
|
||||
@ -359,6 +383,7 @@ func NewOnlineUserGauges() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewSingleChatMsgProcessSuccessCounter() {
|
||||
if SingleChatMsgProcessSuccessCounter != nil {
|
||||
return
|
||||
@ -369,6 +394,7 @@ func NewSingleChatMsgProcessSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewSingleChatMsgProcessFailedCounter() {
|
||||
if SingleChatMsgProcessFailedCounter != nil {
|
||||
return
|
||||
@ -379,6 +405,7 @@ func NewSingleChatMsgProcessFailedCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewGroupChatMsgProcessSuccessCounter() {
|
||||
if GroupChatMsgProcessSuccessCounter != nil {
|
||||
return
|
||||
@ -389,6 +416,7 @@ func NewGroupChatMsgProcessSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewGroupChatMsgProcessFailedCounter() {
|
||||
if GroupChatMsgProcessFailedCounter != nil {
|
||||
return
|
||||
@ -399,6 +427,7 @@ func NewGroupChatMsgProcessFailedCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewWorkSuperGroupChatMsgProcessSuccessCounter() {
|
||||
if WorkSuperGroupChatMsgProcessSuccessCounter != nil {
|
||||
return
|
||||
@ -409,6 +438,7 @@ func NewWorkSuperGroupChatMsgProcessSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewWorkSuperGroupChatMsgProcessFailedCounter() {
|
||||
if WorkSuperGroupChatMsgProcessFailedCounter != nil {
|
||||
return
|
||||
@ -419,6 +449,7 @@ func NewWorkSuperGroupChatMsgProcessFailedCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewMsgOnlinePushSuccessCounter() {
|
||||
if MsgOnlinePushSuccessCounter != nil {
|
||||
return
|
||||
@ -429,6 +460,7 @@ func NewMsgOnlinePushSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewMsgOfflinePushSuccessCounter() {
|
||||
if MsgOfflinePushSuccessCounter != nil {
|
||||
return
|
||||
@ -439,6 +471,7 @@ func NewMsgOfflinePushSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewMsgOfflinePushFailedCounter() {
|
||||
if MsgOfflinePushFailedCounter != nil {
|
||||
return
|
||||
@ -449,6 +482,7 @@ func NewMsgOfflinePushFailedCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewConversationCreateSuccessCounter() {
|
||||
if ConversationCreateSuccessCounter != nil {
|
||||
return
|
||||
@ -459,6 +493,7 @@ func NewConversationCreateSuccessCounter() {
|
||||
})
|
||||
}
|
||||
|
||||
//nolint:promlinter //no idea to fix it
|
||||
func NewConversationCreateFailedCounter() {
|
||||
if ConversationCreateFailedCounter != nil {
|
||||
return
|
||||
|
||||
@ -30,13 +30,16 @@ func StartPrometheusSrv(prometheusPort int) error {
|
||||
if config.Config.Prometheus.Enable {
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
err := http.ListenAndServe(":"+strconv.Itoa(prometheusPort), nil)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func PrometheusHandler() gin.HandlerFunc {
|
||||
h := promhttp.Handler()
|
||||
|
||||
return func(c *gin.Context) {
|
||||
h.ServeHTTP(c.Writer, c.Request)
|
||||
}
|
||||
@ -49,6 +52,7 @@ type responseBodyWriter struct {
|
||||
|
||||
func (r responseBodyWriter) Write(b []byte) (int, error) {
|
||||
r.body.Write(b)
|
||||
|
||||
return r.ResponseWriter.Write(b)
|
||||
}
|
||||
|
||||
|
||||
3
pkg/common/tls/tls.go
Normal file → Executable file
3
pkg/common/tls/tls.go
Normal file → Executable file
@ -24,6 +24,7 @@ import (
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
)
|
||||
|
||||
//nolint:staticcheck //we have not time looking for a replacement for x509 to fix the security valnerability
|
||||
func decryptPEM(data []byte, passphrase []byte) ([]byte, error) {
|
||||
if len(passphrase) == 0 {
|
||||
return data, nil
|
||||
@ -33,6 +34,7 @@ func decryptPEM(data []byte, passphrase []byte) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return pem.EncodeToMemory(&pem.Block{
|
||||
Type: b.Type,
|
||||
Bytes: d,
|
||||
@ -44,6 +46,7 @@ func readEncryptablePEMBlock(path string, pwd []byte) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return decryptPEM(data, pwd)
|
||||
}
|
||||
|
||||
|
||||
@ -28,6 +28,7 @@ func GetNotificationConversationIDByMsg(msg *sdkws.MsgData) string {
|
||||
case constant.SingleChatType:
|
||||
l := []string{msg.SendID, msg.RecvID}
|
||||
sort.Strings(l)
|
||||
|
||||
return "n_" + strings.Join(l, "_")
|
||||
case constant.GroupChatType:
|
||||
return "n_" + msg.GroupID
|
||||
@ -36,6 +37,7 @@ func GetNotificationConversationIDByMsg(msg *sdkws.MsgData) string {
|
||||
case constant.NotificationChatType:
|
||||
return "n_" + msg.SendID + "_" + msg.RecvID
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -44,6 +46,7 @@ func GetChatConversationIDByMsg(msg *sdkws.MsgData) string {
|
||||
case constant.SingleChatType:
|
||||
l := []string{msg.SendID, msg.RecvID}
|
||||
sort.Strings(l)
|
||||
|
||||
return "si_" + strings.Join(l, "_")
|
||||
case constant.GroupChatType:
|
||||
return "g_" + msg.GroupID
|
||||
@ -52,6 +55,7 @@ func GetChatConversationIDByMsg(msg *sdkws.MsgData) string {
|
||||
case constant.NotificationChatType:
|
||||
return "sn_" + msg.SendID + "_" + msg.RecvID
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -60,10 +64,12 @@ func GenConversationUniqueKey(msg *sdkws.MsgData) string {
|
||||
case constant.SingleChatType, constant.NotificationChatType:
|
||||
l := []string{msg.SendID, msg.RecvID}
|
||||
sort.Strings(l)
|
||||
|
||||
return strings.Join(l, "_")
|
||||
case constant.SuperGroupChatType:
|
||||
return msg.GroupID
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -76,23 +82,28 @@ func GetConversationIDByMsg(msg *sdkws.MsgData) string {
|
||||
if !options.IsNotNotification() {
|
||||
return "n_" + strings.Join(l, "_")
|
||||
}
|
||||
|
||||
return "si_" + strings.Join(l, "_") // single chat
|
||||
case constant.GroupChatType:
|
||||
if !options.IsNotNotification() {
|
||||
return "n_" + msg.GroupID // group chat
|
||||
}
|
||||
|
||||
return "g_" + msg.GroupID // group chat
|
||||
case constant.SuperGroupChatType:
|
||||
if !options.IsNotNotification() {
|
||||
return "n_" + msg.GroupID // super group chat
|
||||
}
|
||||
|
||||
return "sg_" + msg.GroupID // super group chat
|
||||
case constant.NotificationChatType:
|
||||
if !options.IsNotNotification() {
|
||||
return "n_" + msg.SendID + "_" + msg.RecvID // super group chat
|
||||
}
|
||||
|
||||
return "sn_" + msg.SendID + "_" + msg.RecvID // server notification chat
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -111,6 +122,7 @@ func GetConversationIDBySessionType(sessionType int, ids ...string) string {
|
||||
case constant.NotificationChatType:
|
||||
return "sn_" + ids[0] // server notification chat
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -118,10 +130,11 @@ func GetNotificationConversationIDByConversationID(conversationID string) string
|
||||
l := strings.Split(conversationID, "_")
|
||||
if len(l) > 1 {
|
||||
l[0] = "n"
|
||||
|
||||
return strings.Join(l, "_")
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func GetNotificationConversationID(sessionType int, ids ...string) string {
|
||||
@ -135,6 +148,7 @@ func GetNotificationConversationID(sessionType int, ids ...string) string {
|
||||
case constant.SuperGroupChatType:
|
||||
return "n_" + ids[0] // super group chat
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -155,18 +169,22 @@ func ParseConversationID(msg *sdkws.MsgData) (isNotification bool, conversationI
|
||||
if !options.IsNotNotification() {
|
||||
return true, "n_" + strings.Join(l, "_")
|
||||
}
|
||||
|
||||
return false, "si_" + strings.Join(l, "_") // single chat
|
||||
case constant.SuperGroupChatType:
|
||||
if !options.IsNotNotification() {
|
||||
return true, "n_" + msg.GroupID // super group chat
|
||||
}
|
||||
|
||||
return false, "sg_" + msg.GroupID // super group chat
|
||||
case constant.NotificationChatType:
|
||||
if !options.IsNotNotification() {
|
||||
return true, "n_" + msg.SendID + "_" + msg.RecvID // super group chat
|
||||
}
|
||||
|
||||
return false, "sn_" + msg.SendID + "_" + msg.RecvID // server notification chat
|
||||
}
|
||||
|
||||
return false, ""
|
||||
}
|
||||
|
||||
@ -189,6 +207,7 @@ func Pb2String(pb proto.Message) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(s), nil
|
||||
}
|
||||
|
||||
|
||||
@ -38,12 +38,14 @@ func NewOptions(opts ...OptionsOpt) Options {
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
func NewMsgOptions() Options {
|
||||
options := make(map[string]bool, 11)
|
||||
options[constant.IsOfflinePush] = false
|
||||
|
||||
return make(map[string]bool)
|
||||
}
|
||||
|
||||
@ -51,6 +53,7 @@ func WithOptions(options Options, opts ...OptionsOpt) Options {
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
@ -131,6 +134,7 @@ func (o Options) Is(notification string) bool {
|
||||
if !ok || v {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user