Merge remote-tracking branch 'upstream/main'

pull/534/head
wangchuxiao 1 year ago
commit 2607862544

@ -0,0 +1,37 @@
name: goreleaser
on:
push:
# run only against tags
tags:
- '*'
permissions:
contents: write
# packages: write
# issues: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v4
with:
go-version: stable
# More assembly might be required: Docker logins, GPG, etc. It all depends
# on your needs.
- uses: goreleaser/goreleaser-action@v4
with:
# either 'goreleaser' (default) or 'goreleaser-pro':
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro'
# distribution:
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}

1
.gitignore vendored

@ -391,3 +391,4 @@ Sessionx.vim
[._]*.un~ [._]*.un~
# End of https://www.toptal.com/developers/gitignore/api/go,git,vim,tags,test,emacs,backup,jetbrains # End of https://www.toptal.com/developers/gitignore/api/go,git,vim,tags,test,emacs,backup,jetbrains
.idea

@ -1,5 +1,16 @@
# Changelog # Changelog
- [Changelog](#changelog)
- [command](#command)
- [create next tag](#create-next-tag)
- [Release version logs](#release-version-logs)
- [Introduction](#introduction)
- [Naming Format](#naming-format)
- [Examples](#examples)
- [Version Modifiers](#version-modifiers)
- [Versioning Strategy](#versioning-strategy)
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
+ [https://github.com/OpenIMSDK/Open-IM-Server/releases](https://github.com/OpenIMSDK/Open-IM-Server/releases) + [https://github.com/OpenIMSDK/Open-IM-Server/releases](https://github.com/OpenIMSDK/Open-IM-Server/releases)
@ -35,3 +46,59 @@ git tag 2.0.0
+ [OpenIM CHANGELOG-V2.3](CHANGELOG-2.3.md) + [OpenIM CHANGELOG-V2.3](CHANGELOG-2.3.md)
+ [OpenIM CHANGELOG-V2.9](CHANGELOG-2.9.md) + [OpenIM CHANGELOG-V2.9](CHANGELOG-2.9.md)
+ [OpenIM CHANGELOG-V3.0](CHANGELOG-3.0.md) + [OpenIM CHANGELOG-V3.0](CHANGELOG-3.0.md)
## Introduction
In both the open-source and closed-source software development communities, it is important to follow a consistent and understandable versioning scheme for software projects. This ensures clear communication of changes, compatibility, and stability across different releases. One widely adopted naming convention is the Semantic Versioning 2.0.0.
## Naming Format
The most common format for version numbers is as follows:
```
major.minor[.patch[.build]]
```
Let's take a closer look at each component:
1. **Major Version**: This is the first number in the versioning scheme and indicates significant changes that may not be backward compatible (specific to each project).
2. **Minor Version**: The second number signifies the addition of new features while maintaining backward compatibility.
3. **Patch Version**: The third number represents bug fixes or code optimizations without introducing new features. It is generally backward compatible.
4. **Build Version**: Typically an automatically generated number that increments with each code commit.
## Examples
Here are a few examples to illustrate the versioning scheme:
1. `1.0`
2. `2.14.0.1478`
3. `3.2.1 build-354`
## Version Modifiers
Apart from the version numbers, there are also version modifiers used to indicate specific stages or statuses of a release. Some commonly used version modifiers include:
- **alpha**: An internal testing version with numerous known bugs. It is primarily used for communication among developers.
- **beta**: A testing version released to enthusiastic users for feedback and bug detection.
- **rc (release candidate)**: The final testing version before the official release.
- **ga (general availability)**: The initial stable release for public distribution.
- **r/release** (or no modifier at all): The final released version intended for general users.
- **lts (long-term support)**: Designates a version that will receive extended maintenance and bug fixes for a specified number of years.
## Versioning Strategy
To effectively manage version numbers, the following strategies are commonly employed:
- The initial version of a project can be either `0.1` or `1.0`.
- When fixing bugs, the patch version is incremented by 1.
- When adding new features, the minor version is incremented by 1, and the patch version is reset to 0.
- In the case of significant modifications, the major version is incremented by 1.
- The build version is usually automatically generated by the compilation process and follows a defined format. It does not require manual control.
By adhering to these strategies and guidelines, developers can maintain consistency and clarity in versioning their software projects. This enables users and collaborators to understand the nature of changes between different releases and ensure compatibility with their systems.
(Note: Markdown formatting has been used to structure this article. Markdown is a lightweight markup language used to format text on platforms like GitHub.)
------
**Note**: The above article is based on the given content and aims to provide a Markdown-formatted English article explaining the naming conventions for software project versions, specifically focusing on the Semantic Versioning 2.0.0.

@ -56,11 +56,14 @@ kafka:
topic: "offlineMsgToMongoMysql" #不建议修改 topic: "offlineMsgToMongoMysql" #不建议修改
msgToPush: msgToPush:
topic: "msgToPush" #不建议修改 topic: "msgToPush" #不建议修改
msgToModify:
topic: "msgToModify" #不建议修改
consumerGroupID: #消费者组,不建议修改 consumerGroupID: #消费者组,不建议修改
msgToRedis: redis # msgToRedis: redis #
msgToMongo: mongo # msgToMongo: mongo #
msgToMySql: mysql # msgToMySql: mysql #
msgToPush: push # msgToPush: push #
msgToModify: modify #
rpc: rpc:
@ -73,26 +76,41 @@ api:
listenIP: #默认为0.0.0.0 listenIP: #默认为0.0.0.0
object: object:
enable: "minio" #使用minio enable: minio #使用minio
apiURL: "http://127.0.0.1:10002/object/" apiURL: http://127.0.0.1:10002/third/object
minio: minio:
bucket: "openim" #不建议修改 tempBucket: "openim" #不建议修改
endpoint: "http://127.0.0.1:10005" #minio对外服务的ip和端口app要能访问此ip和端口 dataBucket: "openim" #不建议修改
accessKeyID: "root" #ID location: us-east-1 #不建议修改
secretAccessKey: "openIM123" #秘钥 endpoint: http://127.0.0.1:10005 #minio对外服务的ip和端口app要能访问此ip和端口
sessionToken: "" #token accessKeyID: root #ID
cos: #tencent cos secretAccessKey: openIM123 #秘钥
bucketURL: "https://temp-1252357374.cos.ap-chengdu.myqcloud.com" isDistributedMod: false #是否分布式多硬盘部署如果是多硬盘部署需要修改为true
secretID: "" tencent: #tencent cos
secretKey: "" appID:
sessionToken: "" region:
oss: #ali oss bucket:
endpoint: "https://oss-cn-chengdu.aliyuncs.com" secretID:
bucket: "demo-9999999" secretKey:
bucketURL: "https://demo-9999999.oss-cn-chengdu.aliyuncs.com" ali: #ali oss
accessKeyID: "" regionID:
accessKeySecret: "" accessKeyID:
sessionToken: "" accessKeySecret:
stsEndpoint:
ossEndpoint:
bucket:
finalHost:
stsDurationSeconds:
OssRoleArn:
aws:
accessKeyID:
accessKeySecret:
region:
bucket:
finalHost:
roleArn:
externalId:
roleSessionName:
rpcPort: #rpc服务端口不建议修改端口由脚本读取后传入程序如启动多个程序只需要填入多个端口用逗号隔开如 [10110, 10111] rpcPort: #rpc服务端口不建议修改端口由脚本读取后传入程序如启动多个程序只需要填入多个端口用逗号隔开如 [10110, 10111]
openImUserPort: [ 10110 ] openImUserPort: [ 10110 ]
@ -117,7 +135,7 @@ rpcRegisterName: #rpc注册服务名不建议修改
openImThirdName: Third openImThirdName: Third
log: log:
storageLocation: ../logs/ #存放目录 storageLocation: ../../../../../logs/ #TODO: 存放目录
rotationTime: 24 #日志旋转时间 rotationTime: 24 #日志旋转时间
remainRotationCount: 2 #日志数量 remainRotationCount: 2 #日志数量
remainLogLevel: 6 #日志级别 6表示全都打印 remainLogLevel: 6 #日志级别 6表示全都打印
@ -164,8 +182,7 @@ groupMessageHasReadReceiptEnable: true #群聊已读是否开
singleMessageHasReadReceiptEnable: true #单聊已读是否开启 singleMessageHasReadReceiptEnable: true #单聊已读是否开启
retainChatRecords: 365 #mongo保存离线消息时间 retainChatRecords: 365 #mongo保存离线消息时间
chatRecordsClearTime: "0 2 * * 3" #每周三凌晨2点清理mongo中的过期超过retainChatRecords时间消息这个删除是为了清理满足上个配置retainChatRecords的过期消息不会发送通知仅仅作为清理磁盘使用 chatRecordsClearTime: "0 2 * * 3" #每周三凌晨2点清理mongo中的过期超过retainChatRecords时间消息
msgDestructTime: "0 2 * * *" #消息自动删除时间每天凌晨2点删除过期消息这个删除是为了删除保留时间超过超过会话字段msg_destruct_time的消息。
secret: tuoyun #秘钥获取token时校验 secret: tuoyun #秘钥获取token时校验

@ -100,7 +100,7 @@ services:
openim_server: openim_server:
image: ghcr.io/openimsdk/openim-server:v3.0.0 image: ghcr.io/openimsdk/openim-server:v3.0.0-alpha.0
container_name: openim-server container_name: openim-server
volumes: volumes:
- ./logs:/Open-IM-Server/logs - ./logs:/Open-IM-Server/logs

@ -132,3 +132,6 @@ func (o *GroupApi) GetSuperGroupsInfo(c *gin.Context) {
func (o *GroupApi) GroupCreateCount(c *gin.Context) { func (o *GroupApi) GroupCreateCount(c *gin.Context) {
a2r.Call(group.GroupClient.GroupCreateCount, o.Client, c) a2r.Call(group.GroupClient.GroupCreateCount, o.Client, c)
} }
func (o *GroupApi) GetGroups(c *gin.Context) {
a2r.Call(group.GroupClient.GetGroups, o.Client, c)
}

@ -15,6 +15,7 @@
package api package api
import ( import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
@ -204,7 +205,7 @@ func (m *MessageApi) SendMessage(c *gin.Context) {
if err := mapstructure.WeakDecode(params.Content, &data); err != nil { if err := mapstructure.WeakDecode(params.Content, &data); err != nil {
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error())) apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error()))
return return
} else if err := m.validate.Struct(data); err != nil { } else if err := m.validate.Struct(params); err != nil {
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error())) apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error()))
return return
} }
@ -227,7 +228,107 @@ func (m *MessageApi) SendMessage(c *gin.Context) {
} }
func (m *MessageApi) ManagementBatchSendMsg(c *gin.Context) { func (m *MessageApi) ManagementBatchSendMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.SendMsg, m.Client, c) params := apistruct.ManagementBatchSendMsgReq{}
resp := apistruct.ManagementBatchSendMsgResp{}
var msgSendFailedFlag bool
if err := c.BindJSON(&params); err != nil {
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
return
}
if !tokenverify.IsAppManagerUid(c) {
apiresp.GinError(c, errs.ErrNoPermission.Wrap("only app manager can send message"))
return
}
var data interface{}
switch params.ContentType {
case constant.Text:
data = apistruct.TextElem{}
case constant.Picture:
data = apistruct.PictureElem{}
case constant.Voice:
data = apistruct.SoundElem{}
case constant.Video:
data = apistruct.VideoElem{}
case constant.File:
data = apistruct.FileElem{}
case constant.Custom:
data = apistruct.CustomElem{}
case constant.Revoke:
data = apistruct.RevokeElem{}
case constant.OANotification:
data = apistruct.OANotificationElem{}
params.SessionType = constant.NotificationChatType
case constant.CustomNotTriggerConversation:
data = apistruct.CustomElem{}
case constant.CustomOnlineOnly:
data = apistruct.CustomElem{}
default:
apiresp.GinError(c, errs.ErrArgs.WithDetail("not support err contentType").Wrap())
return
}
if err := mapstructure.WeakDecode(params.Content, &data); err != nil {
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error()))
return
} else if err := m.validate.Struct(params); err != nil {
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error()))
return
}
t := &apistruct.ManagementSendMsgReq{
SendID: params.SendID,
GroupID: params.GroupID,
SenderNickname: params.SenderNickname,
SenderFaceURL: params.SenderFaceURL,
SenderPlatformID: params.SenderPlatformID,
Content: params.Content,
ContentType: params.ContentType,
SessionType: params.SessionType,
IsOnlineOnly: params.IsOnlineOnly,
NotOfflinePush: params.NotOfflinePush,
OfflinePushInfo: params.OfflinePushInfo,
}
pbReq := m.newUserSendMsgReq(c, t)
var recvList []string
if params.IsSendAll {
req2 := &user.GetAllUserIDReq{}
resp2, err := m.Message.GetAllUserID(c, req2)
if err != nil {
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error()))
return
}
recvList = resp2.UserIDs
} else {
recvList = params.RecvIDList
}
for _, recvID := range recvList {
pbReq.MsgData.RecvID = recvID
rpcResp, err := m.Client.SendMsg(c, pbReq)
if err != nil {
resp.Data.FailedIDList = append(resp.Data.FailedIDList, recvID)
msgSendFailedFlag = true
continue
}
resp.Data.ResultList = append(resp.Data.ResultList, &apistruct.SingleReturnResult{
ServerMsgID: rpcResp.ServerMsgID,
ClientMsgID: rpcResp.ClientMsgID,
SendTime: rpcResp.SendTime,
RecvID: recvID,
})
}
var status int32
if msgSendFailedFlag {
status = constant.MsgSendFailed
} else {
status = constant.MsgSendSuccessed
}
_, err := m.Client.SetSendMsgStatus(c, &msg.SetSendMsgStatusReq{Status: status})
if err != nil {
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error()))
return
}
apiresp.GinSuccess(c, resp)
} }
func (m *MessageApi) CheckMsgIsSendSuccess(c *gin.Context) { func (m *MessageApi) CheckMsgIsSendSuccess(c *gin.Context) {
@ -245,3 +346,11 @@ func (m *MessageApi) GetActiveUser(c *gin.Context) {
func (m *MessageApi) GetActiveGroup(c *gin.Context) { func (m *MessageApi) GetActiveGroup(c *gin.Context) {
a2r.Call(msg.MsgClient.GetActiveGroup, m.Client, c) a2r.Call(msg.MsgClient.GetActiveGroup, m.Client, c)
} }
func (m *MessageApi) SearchMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.SearchMessage, m.Client, c)
}
func (m *MessageApi) ManagementMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.ManageMsg, m.Client, c)
}

@ -103,6 +103,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
groupRouterGroup.POST("/cancel_mute_group", g.CancelMuteGroup) groupRouterGroup.POST("/cancel_mute_group", g.CancelMuteGroup)
groupRouterGroup.POST("/set_group_member_info", g.SetGroupMemberInfo) groupRouterGroup.POST("/set_group_member_info", g.SetGroupMemberInfo)
groupRouterGroup.POST("/get_group_abstract_info", g.GetGroupAbstractInfo) groupRouterGroup.POST("/get_group_abstract_info", g.GetGroupAbstractInfo)
groupRouterGroup.POST("/get_groups", g.GetGroups)
} }
superGroupRouterGroup := r.Group("/super_group", ParseToken) superGroupRouterGroup := r.Group("/super_group", ParseToken)
{ {
@ -124,6 +125,8 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
thirdGroup.POST("/fcm_update_token", t.FcmUpdateToken) thirdGroup.POST("/fcm_update_token", t.FcmUpdateToken)
thirdGroup.POST("/set_app_badge", t.SetAppBadge) thirdGroup.POST("/set_app_badge", t.SetAppBadge)
thirdGroup.POST("/minio_upload", t.MinioUploadFile)
objectGroup := r.Group("/object", ParseToken) objectGroup := r.Group("/object", ParseToken)
objectGroup.POST("/part_limit", t.PartLimit) objectGroup.POST("/part_limit", t.PartLimit)
@ -138,10 +141,12 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
msgGroup := r.Group("/msg", ParseToken) msgGroup := r.Group("/msg", ParseToken)
{ {
msgGroup.POST("/newest_seq", m.GetSeq) msgGroup.POST("/newest_seq", m.GetSeq)
msgGroup.POST("/search_msg", m.SearchMsg)
msgGroup.POST("/send_msg", m.SendMessage) msgGroup.POST("/send_msg", m.SendMessage)
msgGroup.POST("/pull_msg_by_seq", m.PullMsgBySeqs) msgGroup.POST("/pull_msg_by_seq", m.PullMsgBySeqs)
msgGroup.POST("/revoke_msg", m.RevokeMsg) msgGroup.POST("/revoke_msg", m.RevokeMsg)
msgGroup.POST("/mark_msgs_as_read", m.MarkMsgsAsRead) msgGroup.POST("/mark_msgs_as_read", m.MarkMsgsAsRead)
msgGroup.POST("/manage_msg", m.ManagementMsg)
msgGroup.POST("/mark_conversation_as_read", m.MarkConversationAsRead) msgGroup.POST("/mark_conversation_as_read", m.MarkConversationAsRead)
msgGroup.POST("/get_conversations_has_read_and_max_seq", m.GetConversationsHasReadAndMaxSeq) msgGroup.POST("/get_conversations_has_read_and_max_seq", m.GetConversationsHasReadAndMaxSeq)
msgGroup.POST("/set_conversation_has_read_seq", m.SetConversationHasReadSeq) msgGroup.POST("/set_conversation_has_read_seq", m.SetConversationHasReadSeq)

@ -1,16 +1,23 @@
package api package api
import ( import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"github.com/minio/minio-go/v7"
"math/rand"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r" "github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/gin-gonic/gin"
"math/rand"
"net/http"
"strconv"
) )
type ThirdApi rpcclient.Third type ThirdApi rpcclient.Third
@ -82,3 +89,57 @@ func (o *ThirdApi) ObjectRedirect(c *gin.Context) {
} }
c.Redirect(http.StatusTemporaryRedirect, resp.Url) c.Redirect(http.StatusTemporaryRedirect, resp.Url)
} }
func (o *ThirdApi) MinioUploadFile(c *gin.Context) {
var (
req apistruct.MinioUploadFileReq
resp apistruct.MinioUploadFile
)
if err := c.Bind(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
switch req.FileType {
// videoType upload snapShot
case constant.VideoType:
snapShotFile, err := c.FormFile("snapShot")
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "missing snapshot arg: " + err.Error()})
return
}
snapShotFileObj, err := snapShotFile.Open()
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
snapShotNewName, snapShotNewType := utils.GetNewFileNameAndContentType(snapShotFile.Filename, constant.ImageType)
_, err = o.MinioClient.PutObject(c, config.Config.Object.Minio.Bucket, snapShotNewName, snapShotFileObj, snapShotFile.Size, minio.PutObjectOptions{ContentType: snapShotNewType})
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
resp.SnapshotURL = config.Config.Object.Minio.Endpoint + "/" + config.Config.Object.Minio.Bucket + "/" + snapShotNewName
resp.SnapshotNewName = snapShotNewName
}
file, err := c.FormFile("file")
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "missing file arg: " + err.Error()})
return
}
fileObj, err := file.Open()
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file path" + err.Error()})
return
}
newName, newType := utils.GetNewFileNameAndContentType(file.Filename, req.FileType)
_, err = o.MinioClient.PutObject(c, config.Config.Object.Minio.Bucket, newName, fileObj, file.Size, minio.PutObjectOptions{ContentType: newType})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "upload file error" + err.Error()})
return
}
resp.NewName = newName
resp.URL = config.Config.Object.Minio.Endpoint + "/" + config.Config.Object.Minio.Bucket + "/" + newName
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
return
}

@ -107,7 +107,7 @@ func (u *UserApi) GetUsersOnlineStatus(c *gin.Context) {
} }
if !flag { if !flag {
res.UserID = v1 res.UserID = v1
res.Status = constant.OnlineStatus res.Status = constant.OfflineStatus
} }
respResult = append(respResult, res) respResult = append(respResult, res)
} }

@ -21,13 +21,14 @@ import (
"runtime/debug" "runtime/debug"
"sync" "sync"
"google.golang.org/protobuf/proto"
"github.com/OpenIMSDK/Open-IM-Server/pkg/apiresp" "github.com/OpenIMSDK/Open-IM-Server/pkg/apiresp"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/protobuf/proto"
) )
var ErrConnClosed = errors.New("conn has closed") var ErrConnClosed = errors.New("conn has closed")
@ -80,7 +81,14 @@ func newClient(ctx *UserConnContext, conn LongConn, isCompress bool) *Client {
ctx: ctx, ctx: ctx,
} }
} }
func (c *Client) ResetClient(ctx *UserConnContext, conn LongConn, isBackground, isCompress bool, longConnServer LongConnServer, token string) {
func (c *Client) ResetClient(
ctx *UserConnContext,
conn LongConn,
isBackground, isCompress bool,
longConnServer LongConnServer,
token string,
) {
c.w = new(sync.Mutex) c.w = new(sync.Mutex)
c.conn = conn c.conn = conn
c.PlatformID = utils.StringToInt(ctx.GetPlatformID()) c.PlatformID = utils.StringToInt(ctx.GetPlatformID())
@ -161,7 +169,9 @@ func (c *Client) handleMessage(message []byte) error {
if binaryReq.SendID != c.UserID { if binaryReq.SendID != c.UserID {
return utils.Wrap(errors.New("exception conn userID not same to req userID"), binaryReq.String()) return utils.Wrap(errors.New("exception conn userID not same to req userID"), binaryReq.String())
} }
ctx := mcontext.WithMustInfoCtx([]string{binaryReq.OperationID, binaryReq.SendID, constant.PlatformIDToName(c.PlatformID), c.ctx.GetConnID()}) ctx := mcontext.WithMustInfoCtx(
[]string{binaryReq.OperationID, binaryReq.SendID, constant.PlatformIDToName(c.PlatformID), c.ctx.GetConnID()},
)
log.ZDebug(ctx, "gateway req message", "req", binaryReq.String()) log.ZDebug(ctx, "gateway req message", "req", binaryReq.String())
var messageErr error var messageErr error
var resp []byte var resp []byte
@ -179,7 +189,12 @@ func (c *Client) handleMessage(message []byte) error {
case WsSetBackgroundStatus: case WsSetBackgroundStatus:
resp, messageErr = c.setAppBackgroundStatus(ctx, binaryReq) resp, messageErr = c.setAppBackgroundStatus(ctx, binaryReq)
default: default:
return fmt.Errorf("ReqIdentifier failed,sendID:%s,msgIncr:%s,reqIdentifier:%d", binaryReq.SendID, binaryReq.MsgIncr, binaryReq.ReqIdentifier) return fmt.Errorf(
"ReqIdentifier failed,sendID:%s,msgIncr:%s,reqIdentifier:%d",
binaryReq.SendID,
binaryReq.MsgIncr,
binaryReq.ReqIdentifier,
)
} }
c.replyMessage(ctx, &binaryReq, messageErr, resp) c.replyMessage(ctx, &binaryReq, messageErr, resp)
return nil return nil

@ -5,6 +5,9 @@ import (
"sync" "sync"
"time" "time"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
@ -16,8 +19,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome"
openKeeper "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry/zookeeper" openKeeper "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry/zookeeper"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
) )
type MsgTransfer struct { type MsgTransfer struct {
@ -46,9 +47,18 @@ func StartTransfer(prometheusPort int) error {
if err := mongo.CreateMsgIndex(); err != nil { if err := mongo.CreateMsgIndex(); err != nil {
return err return err
} }
client, err := openKeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema, client, err := openKeeper.NewClient(
openKeeper.WithFreq(time.Hour), openKeeper.WithRoundRobin(), openKeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username, config.Config.Zookeeper.ZkAddr,
config.Config.Zookeeper.Password), openKeeper.WithTimeout(10), openKeeper.WithLogger(log.NewZkLogger())) config.Config.Zookeeper.Schema,
openKeeper.WithFreq(
time.Hour,
),
openKeeper.WithRoundRobin(),
openKeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username,
config.Config.Zookeeper.Password),
openKeeper.WithTimeout(10),
openKeeper.WithLogger(log.NewZkLogger()),
)
if err != nil { if err != nil {
return err return err
} }
@ -58,8 +68,9 @@ func StartTransfer(prometheusPort int) error {
client.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials())) client.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()))
msgModel := cache.NewMsgCacheModel(rdb) msgModel := cache.NewMsgCacheModel(rdb)
msgDocModel := unrelation.NewMsgMongoDriver(mongo.GetDatabase()) msgDocModel := unrelation.NewMsgMongoDriver(mongo.GetDatabase())
chatLogDatabase := controller.NewChatLogDatabase(relation.NewChatLogGorm(db)) msgMysModel := relation.NewChatLogGorm(db)
msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, msgModel) chatLogDatabase := controller.NewChatLogDatabase(msgMysModel)
msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, msgModel, msgMysModel)
conversationRpcClient := rpcclient.NewConversationRpcClient(client) conversationRpcClient := rpcclient.NewConversationRpcClient(client)
groupRpcClient := rpcclient.NewGroupRpcClient(client) groupRpcClient := rpcclient.NewGroupRpcClient(client)
msgTransfer := NewMsgTransfer(chatLogDatabase, msgDatabase, &conversationRpcClient, &groupRpcClient) msgTransfer := NewMsgTransfer(chatLogDatabase, msgDatabase, &conversationRpcClient, &groupRpcClient)
@ -70,8 +81,11 @@ func StartTransfer(prometheusPort int) error {
func NewMsgTransfer(chatLogDatabase controller.ChatLogDatabase, func NewMsgTransfer(chatLogDatabase controller.ChatLogDatabase,
msgDatabase controller.CommonMsgDatabase, msgDatabase controller.CommonMsgDatabase,
conversationRpcClient *rpcclient.ConversationRpcClient, groupRpcClient *rpcclient.GroupRpcClient) *MsgTransfer { conversationRpcClient *rpcclient.ConversationRpcClient, groupRpcClient *rpcclient.GroupRpcClient) *MsgTransfer {
return &MsgTransfer{persistentCH: NewPersistentConsumerHandler(chatLogDatabase), historyCH: NewOnlineHistoryRedisConsumerHandler(msgDatabase, conversationRpcClient, groupRpcClient), return &MsgTransfer{
historyMongoCH: NewOnlineHistoryMongoConsumerHandler(msgDatabase)} persistentCH: NewPersistentConsumerHandler(chatLogDatabase),
historyCH: NewOnlineHistoryRedisConsumerHandler(msgDatabase, conversationRpcClient, groupRpcClient),
historyMongoCH: NewOnlineHistoryMongoConsumerHandler(msgDatabase),
}
} }
func (m *MsgTransfer) initPrometheus() { func (m *MsgTransfer) initPrometheus() {

@ -38,9 +38,16 @@ type Pusher struct {
var errNoOfflinePusher = errors.New("no offlinePusher is configured") var errNoOfflinePusher = errors.New("no offlinePusher is configured")
func NewPusher(discov discoveryregistry.SvcDiscoveryRegistry, offlinePusher offlinepush.OfflinePusher, database controller.PushDatabase, func NewPusher(
groupLocalCache *localcache.GroupLocalCache, conversationLocalCache *localcache.ConversationLocalCache, discov discoveryregistry.SvcDiscoveryRegistry,
conversationRpcClient *rpcclient.ConversationRpcClient, groupRpcClient *rpcclient.GroupRpcClient, msgRpcClient *rpcclient.MessageRpcClient) *Pusher { offlinePusher offlinepush.OfflinePusher,
database controller.PushDatabase,
groupLocalCache *localcache.GroupLocalCache,
conversationLocalCache *localcache.ConversationLocalCache,
conversationRpcClient *rpcclient.ConversationRpcClient,
groupRpcClient *rpcclient.GroupRpcClient,
msgRpcClient *rpcclient.MessageRpcClient,
) *Pusher {
return &Pusher{ return &Pusher{
discov: discov, discov: discov,
database: database, database: database,
@ -87,7 +94,18 @@ func (p *Pusher) Push2User(ctx context.Context, userIDs []string, msg *sdkws.Msg
return err return err
} }
isOfflinePush := utils.GetSwitchFromOptions(msg.Options, constant.IsOfflinePush) isOfflinePush := utils.GetSwitchFromOptions(msg.Options, constant.IsOfflinePush)
log.ZDebug(ctx, "push_result", "ws push result", wsResults, "sendData", msg, "isOfflinePush", isOfflinePush, "push_to_userID", userIDs) log.ZDebug(
ctx,
"push_result",
"ws push result",
wsResults,
"sendData",
msg,
"isOfflinePush",
isOfflinePush,
"push_to_userID",
userIDs,
)
p.successCount++ p.successCount++
for _, userID := range userIDs { for _, userID := range userIDs {
if isOfflinePush && userID != msg.SendID { if isOfflinePush && userID != msg.SendID {
@ -138,7 +156,15 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws
} }
defer func(groupID string, userIDs []string) { defer func(groupID string, userIDs []string) {
if err := p.DeleteMemberAndSetConversationSeq(ctx, groupID, userIDs); err != nil { if err := p.DeleteMemberAndSetConversationSeq(ctx, groupID, userIDs); err != nil {
log.ZError(ctx, "MemberQuitNotification DeleteMemberAndSetConversationSeq", err, "groupID", groupID, "userIDs", userIDs) log.ZError(
ctx,
"MemberQuitNotification DeleteMemberAndSetConversationSeq",
err,
"groupID",
groupID,
"userIDs",
userIDs,
)
} }
}(groupID, []string{tips.QuitUser.UserID}) }(groupID, []string{tips.QuitUser.UserID})
pushToUserIDs = append(pushToUserIDs, tips.QuitUser.UserID) pushToUserIDs = append(pushToUserIDs, tips.QuitUser.UserID)
@ -147,10 +173,21 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws
if p.UnmarshalNotificationElem(msg.Content, &tips) != nil { if p.UnmarshalNotificationElem(msg.Content, &tips) != nil {
return err return err
} }
kickedUsers := utils.Slice(tips.KickedUserList, func(e *sdkws.GroupMemberFullInfo) string { return e.UserID }) kickedUsers := utils.Slice(
tips.KickedUserList,
func(e *sdkws.GroupMemberFullInfo) string { return e.UserID },
)
defer func(groupID string, userIDs []string) { defer func(groupID string, userIDs []string) {
if err := p.DeleteMemberAndSetConversationSeq(ctx, groupID, userIDs); err != nil { if err := p.DeleteMemberAndSetConversationSeq(ctx, groupID, userIDs); err != nil {
log.ZError(ctx, "MemberKickedNotification DeleteMemberAndSetConversationSeq", err, "groupID", groupID, "userIDs", userIDs) log.ZError(
ctx,
"MemberKickedNotification DeleteMemberAndSetConversationSeq",
err,
"groupID",
groupID,
"userIDs",
userIDs,
)
} }
}(groupID, kickedUsers) }(groupID, kickedUsers)
pushToUserIDs = append(pushToUserIDs, kickedUsers...) pushToUserIDs = append(pushToUserIDs, kickedUsers...)
@ -160,7 +197,16 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws
if p.UnmarshalNotificationElem(msg.Content, &tips) != nil { if p.UnmarshalNotificationElem(msg.Content, &tips) != nil {
return err return err
} }
log.ZInfo(ctx, "GroupDismissedNotificationInfo****", "groupID", groupID, "num", len(pushToUserIDs), "list", pushToUserIDs) log.ZInfo(
ctx,
"GroupDismissedNotificationInfo****",
"groupID",
groupID,
"num",
len(pushToUserIDs),
"list",
pushToUserIDs,
)
if len(config.Config.Manager.UserID) > 0 { if len(config.Config.Manager.UserID) > 0 {
ctx = mcontext.WithOpUserIDContext(ctx, config.Config.Manager.UserID[0]) ctx = mcontext.WithOpUserIDContext(ctx, config.Config.Manager.UserID[0])
} }
@ -224,9 +270,23 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws
log.ZError(ctx, "offlinePushMsg failed", err, "groupID", groupID, "msg", msg) log.ZError(ctx, "offlinePushMsg failed", err, "groupID", groupID, "msg", msg)
return err return err
} }
_, err := p.GetConnsAndOnlinePush(ctx, msg, utils.IntersectString(needOfflinePushUserIDs, WebAndPcBackgroundUserIDs)) _, err := p.GetConnsAndOnlinePush(
ctx,
msg,
utils.IntersectString(needOfflinePushUserIDs, WebAndPcBackgroundUserIDs),
)
if err != nil { if err != nil {
log.ZError(ctx, "offlinePushMsg failed", err, "groupID", groupID, "msg", msg, "userIDs", utils.IntersectString(needOfflinePushUserIDs, WebAndPcBackgroundUserIDs)) log.ZError(
ctx,
"offlinePushMsg failed",
err,
"groupID",
groupID,
"msg",
msg,
"userIDs",
utils.IntersectString(needOfflinePushUserIDs, WebAndPcBackgroundUserIDs),
)
return err return err
} }
} }
@ -234,7 +294,11 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws
return nil return nil
} }
func (p *Pusher) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData, pushToUserIDs []string) (wsResults []*msggateway.SingleMsgToUserResults, err error) { func (p *Pusher) GetConnsAndOnlinePush(
ctx context.Context,
msg *sdkws.MsgData,
pushToUserIDs []string,
) (wsResults []*msggateway.SingleMsgToUserResults, err error) {
conns, err := p.discov.GetConns(ctx, config.Config.RpcRegisterName.OpenImMessageGatewayName) conns, err := p.discov.GetConns(ctx, config.Config.RpcRegisterName.OpenImMessageGatewayName)
log.ZDebug(ctx, "get gateway conn", "conn length", len(conns)) log.ZDebug(ctx, "get gateway conn", "conn length", len(conns))
if err != nil { if err != nil {
@ -243,7 +307,10 @@ func (p *Pusher) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData,
//Online push message //Online push message
for _, v := range conns { for _, v := range conns {
msgClient := msggateway.NewMsgGatewayClient(v) msgClient := msggateway.NewMsgGatewayClient(v)
reply, err := msgClient.SuperGroupOnlineBatchPushOneMsg(ctx, &msggateway.OnlineBatchPushOneMsgReq{MsgData: msg, PushToUserIDs: pushToUserIDs}) reply, err := msgClient.SuperGroupOnlineBatchPushOneMsg(
ctx,
&msggateway.OnlineBatchPushOneMsgReq{MsgData: msg, PushToUserIDs: pushToUserIDs},
)
if err != nil { if err != nil {
continue continue
} }
@ -256,7 +323,12 @@ func (p *Pusher) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData,
return wsResults, nil return wsResults, nil
} }
func (p *Pusher) offlinePushMsg(ctx context.Context, conversationID string, msg *sdkws.MsgData, offlinePushUserIDs []string) error { func (p *Pusher) offlinePushMsg(
ctx context.Context,
conversationID string,
msg *sdkws.MsgData,
offlinePushUserIDs []string,
) error {
title, content, opts, err := p.getOfflinePushInfos(conversationID, msg) title, content, opts, err := p.getOfflinePushInfos(conversationID, msg)
if err != nil { if err != nil {
return err return err
@ -290,7 +362,10 @@ func (p *Pusher) GetOfflinePushOpts(msg *sdkws.MsgData) (opts *offlinepush.Opts,
return opts, nil return opts, nil
} }
func (p *Pusher) getOfflinePushInfos(conversationID string, msg *sdkws.MsgData) (title, content string, opts *offlinepush.Opts, err error) { func (p *Pusher) getOfflinePushInfos(
conversationID string,
msg *sdkws.MsgData,
) (title, content string, opts *offlinepush.Opts, err error) {
if p.offlinePusher == nil { if p.offlinePusher == nil {
err = errNoOfflinePusher err = errNoOfflinePusher
return return

@ -3,6 +3,8 @@ package conversation
import ( import (
"context" "context"
"google.golang.org/grpc"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
@ -17,7 +19,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/grpc"
) )
type conversationServer struct { type conversationServer struct {
@ -44,12 +45,19 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
pbConversation.RegisterConversationServer(server, &conversationServer{ pbConversation.RegisterConversationServer(server, &conversationServer{
conversationNotificationSender: notification.NewConversationNotificationSender(&msgRpcClient), conversationNotificationSender: notification.NewConversationNotificationSender(&msgRpcClient),
groupRpcClient: &groupRpcClient, groupRpcClient: &groupRpcClient,
conversationDatabase: controller.NewConversationDatabase(conversationDB, cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), conversationDB), tx.NewGorm(db)), conversationDatabase: controller.NewConversationDatabase(
conversationDB,
cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), conversationDB),
tx.NewGorm(db),
),
}) })
return nil return nil
} }
func (c *conversationServer) GetConversation(ctx context.Context, req *pbConversation.GetConversationReq) (*pbConversation.GetConversationResp, error) { func (c *conversationServer) GetConversation(
ctx context.Context,
req *pbConversation.GetConversationReq,
) (*pbConversation.GetConversationResp, error) {
conversations, err := c.conversationDatabase.FindConversations(ctx, req.OwnerUserID, []string{req.ConversationID}) conversations, err := c.conversationDatabase.FindConversations(ctx, req.OwnerUserID, []string{req.ConversationID})
if err != nil { if err != nil {
return nil, err return nil, err
@ -62,7 +70,10 @@ func (c *conversationServer) GetConversation(ctx context.Context, req *pbConvers
return resp, nil return resp, nil
} }
func (c *conversationServer) GetAllConversations(ctx context.Context, req *pbConversation.GetAllConversationsReq) (*pbConversation.GetAllConversationsResp, error) { func (c *conversationServer) GetAllConversations(
ctx context.Context,
req *pbConversation.GetAllConversationsReq,
) (*pbConversation.GetAllConversationsResp, error) {
conversations, err := c.conversationDatabase.GetUserAllConversation(ctx, req.OwnerUserID) conversations, err := c.conversationDatabase.GetUserAllConversation(ctx, req.OwnerUserID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -72,7 +83,10 @@ func (c *conversationServer) GetAllConversations(ctx context.Context, req *pbCon
return resp, nil return resp, nil
} }
func (c *conversationServer) GetConversations(ctx context.Context, req *pbConversation.GetConversationsReq) (*pbConversation.GetConversationsResp, error) { func (c *conversationServer) GetConversations(
ctx context.Context,
req *pbConversation.GetConversationsReq,
) (*pbConversation.GetConversationsResp, error) {
conversations, err := c.conversationDatabase.FindConversations(ctx, req.OwnerUserID, req.ConversationIDs) conversations, err := c.conversationDatabase.FindConversations(ctx, req.OwnerUserID, req.ConversationIDs)
if err != nil { if err != nil {
return nil, err return nil, err
@ -82,12 +96,19 @@ func (c *conversationServer) GetConversations(ctx context.Context, req *pbConver
return resp, nil return resp, nil
} }
func (c *conversationServer) SetConversation(ctx context.Context, req *pbConversation.SetConversationReq) (*pbConversation.SetConversationResp, error) { func (c *conversationServer) SetConversation(
ctx context.Context,
req *pbConversation.SetConversationReq,
) (*pbConversation.SetConversationResp, error) {
var conversation tableRelation.ConversationModel var conversation tableRelation.ConversationModel
if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil { if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil {
return nil, err return nil, err
} }
err := c.conversationDatabase.SetUserConversations(ctx, req.Conversation.OwnerUserID, []*tableRelation.ConversationModel{&conversation}) err := c.conversationDatabase.SetUserConversations(
ctx,
req.Conversation.OwnerUserID,
[]*tableRelation.ConversationModel{&conversation},
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -96,7 +117,10 @@ func (c *conversationServer) SetConversation(ctx context.Context, req *pbConvers
return resp, nil return resp, nil
} }
func (c *conversationServer) SetConversations(ctx context.Context, req *pbConversation.SetConversationsReq) (*pbConversation.SetConversationsResp, error) { func (c *conversationServer) SetConversations(
ctx context.Context,
req *pbConversation.SetConversationsReq,
) (*pbConversation.SetConversationsResp, error) {
if req.Conversation == nil { if req.Conversation == nil {
return nil, errs.ErrArgs.Wrap("conversation must not be nil") return nil, errs.ErrArgs.Wrap("conversation must not be nil")
} }
@ -154,7 +178,12 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbConver
return nil, err return nil, err
} }
for _, userID := range req.UserIDs { for _, userID := range req.UserIDs {
c.conversationNotificationSender.ConversationSetPrivateNotification(ctx, userID, req.Conversation.UserID, req.Conversation.IsPrivateChat.Value) c.conversationNotificationSender.ConversationSetPrivateNotification(
ctx,
userID,
req.Conversation.UserID,
req.Conversation.IsPrivateChat.Value,
)
} }
} }
if req.Conversation.BurnDuration != nil { if req.Conversation.BurnDuration != nil {
@ -171,7 +200,10 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbConver
} }
// 获取超级大群开启免打扰的用户ID // 获取超级大群开启免打扰的用户ID
func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(ctx context.Context, req *pbConversation.GetRecvMsgNotNotifyUserIDsReq) (*pbConversation.GetRecvMsgNotNotifyUserIDsResp, error) { func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(
ctx context.Context,
req *pbConversation.GetRecvMsgNotNotifyUserIDsReq,
) (*pbConversation.GetRecvMsgNotNotifyUserIDsResp, error) {
userIDs, err := c.conversationDatabase.FindRecvMsgNotNotifyUserIDs(ctx, req.GroupID) userIDs, err := c.conversationDatabase.FindRecvMsgNotNotifyUserIDs(ctx, req.GroupID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -180,7 +212,10 @@ func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(ctx context.Context, req
} }
// create conversation without notification for msg redis transfer // create conversation without notification for msg redis transfer
func (c *conversationServer) CreateSingleChatConversations(ctx context.Context, req *pbConversation.CreateSingleChatConversationsReq) (*pbConversation.CreateSingleChatConversationsResp, error) { func (c *conversationServer) CreateSingleChatConversations(
ctx context.Context,
req *pbConversation.CreateSingleChatConversationsReq,
) (*pbConversation.CreateSingleChatConversationsResp, error) {
var conversation tableRelation.ConversationModel var conversation tableRelation.ConversationModel
conversation.ConversationID = utils.GetConversationIDBySessionType(constant.SingleChatType, req.RecvID, req.SendID) conversation.ConversationID = utils.GetConversationIDBySessionType(constant.SingleChatType, req.RecvID, req.SendID)
conversation.ConversationType = constant.SingleChatType conversation.ConversationType = constant.SingleChatType
@ -201,7 +236,10 @@ func (c *conversationServer) CreateSingleChatConversations(ctx context.Context,
return &pbConversation.CreateSingleChatConversationsResp{}, nil return &pbConversation.CreateSingleChatConversationsResp{}, nil
} }
func (c *conversationServer) CreateGroupChatConversations(ctx context.Context, req *pbConversation.CreateGroupChatConversationsReq) (*pbConversation.CreateGroupChatConversationsResp, error) { func (c *conversationServer) CreateGroupChatConversations(
ctx context.Context,
req *pbConversation.CreateGroupChatConversationsReq,
) (*pbConversation.CreateGroupChatConversationsResp, error) {
err := c.conversationDatabase.CreateGroupChatConversation(ctx, req.GroupID, req.UserIDs) err := c.conversationDatabase.CreateGroupChatConversation(ctx, req.GroupID, req.UserIDs)
if err != nil { if err != nil {
return nil, err return nil, err
@ -209,7 +247,10 @@ func (c *conversationServer) CreateGroupChatConversations(ctx context.Context, r
return &pbConversation.CreateGroupChatConversationsResp{}, nil return &pbConversation.CreateGroupChatConversationsResp{}, nil
} }
func (c *conversationServer) SetConversationMaxSeq(ctx context.Context, req *pbConversation.SetConversationMaxSeqReq) (*pbConversation.SetConversationMaxSeqResp, error) { func (c *conversationServer) SetConversationMaxSeq(
ctx context.Context,
req *pbConversation.SetConversationMaxSeqReq,
) (*pbConversation.SetConversationMaxSeqResp, error) {
if err := c.conversationDatabase.UpdateUsersConversationFiled(ctx, req.OwnerUserID, req.ConversationID, if err := c.conversationDatabase.UpdateUsersConversationFiled(ctx, req.OwnerUserID, req.ConversationID,
map[string]interface{}{"max_seq": req.MaxSeq}); err != nil { map[string]interface{}{"max_seq": req.MaxSeq}); err != nil {
return nil, err return nil, err
@ -217,7 +258,10 @@ func (c *conversationServer) SetConversationMaxSeq(ctx context.Context, req *pbC
return &pbConversation.SetConversationMaxSeqResp{}, nil return &pbConversation.SetConversationMaxSeqResp{}, nil
} }
func (c *conversationServer) GetConversationIDs(ctx context.Context, req *pbConversation.GetConversationIDsReq) (*pbConversation.GetConversationIDsResp, error) { func (c *conversationServer) GetConversationIDs(
ctx context.Context,
req *pbConversation.GetConversationIDsReq,
) (*pbConversation.GetConversationIDsResp, error) {
conversationIDs, err := c.conversationDatabase.GetConversationIDs(ctx, req.UserID) conversationIDs, err := c.conversationDatabase.GetConversationIDs(ctx, req.UserID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -225,7 +269,10 @@ func (c *conversationServer) GetConversationIDs(ctx context.Context, req *pbConv
return &pbConversation.GetConversationIDsResp{ConversationIDs: conversationIDs}, nil return &pbConversation.GetConversationIDsResp{ConversationIDs: conversationIDs}, nil
} }
func (c *conversationServer) GetUserConversationIDsHash(ctx context.Context, req *pbConversation.GetUserConversationIDsHashReq) (*pbConversation.GetUserConversationIDsHashResp, error) { func (c *conversationServer) GetUserConversationIDsHash(
ctx context.Context,
req *pbConversation.GetUserConversationIDsHashReq,
) (*pbConversation.GetUserConversationIDsHashResp, error) {
hash, err := c.conversationDatabase.GetUserConversationIDsHash(ctx, req.OwnerUserID) hash, err := c.conversationDatabase.GetUserConversationIDsHash(ctx, req.OwnerUserID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -233,10 +280,15 @@ func (c *conversationServer) GetUserConversationIDsHash(ctx context.Context, req
return &pbConversation.GetUserConversationIDsHashResp{Hash: hash}, nil return &pbConversation.GetUserConversationIDsHashResp{Hash: hash}, nil
} }
func (c *conversationServer) GetConversationsByConversationID(ctx context.Context, req *pbConversation.GetConversationsByConversationIDReq) (*pbConversation.GetConversationsByConversationIDResp, error) { func (c *conversationServer) GetConversationsByConversationID(
ctx context.Context,
req *pbConversation.GetConversationsByConversationIDReq,
) (*pbConversation.GetConversationsByConversationIDResp, error) {
conversations, err := c.conversationDatabase.GetConversationsByConversationID(ctx, req.ConversationIDs) conversations, err := c.conversationDatabase.GetConversationsByConversationID(ctx, req.ConversationIDs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &pbConversation.GetConversationsByConversationIDResp{Conversations: convert.ConversationsDB2Pb(conversations)}, nil return &pbConversation.GetConversationsByConversationIDResp{
Conversations: convert.ConversationsDB2Pb(conversations),
}, nil
} }

@ -16,9 +16,10 @@ package group
import ( import (
"context" "context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
"time" "time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
pbGroup "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group" pbGroup "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
) )

@ -3,20 +3,23 @@ package group
import ( import (
"context" "context"
"fmt" "fmt"
pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
"math/big" "math/big"
"math/rand" "math/rand"
"strconv" "strconv"
"strings" "strings"
"time" "time"
pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw/specialerror" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw/specialerror"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"google.golang.org/grpc"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
@ -31,7 +34,6 @@ import (
pbGroup "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group" pbGroup "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/grpc"
) )
func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error { func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
@ -57,13 +59,18 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
pbGroup.RegisterGroupServer(server, &groupServer{ pbGroup.RegisterGroupServer(server, &groupServer{
GroupDatabase: database, GroupDatabase: database,
User: userRpcClient, User: userRpcClient,
Notification: notification.NewGroupNotificationSender(database, &msgRpcClient, &userRpcClient, func(ctx context.Context, userIDs []string) ([]notification.CommonUser, error) { Notification: notification.NewGroupNotificationSender(
database,
&msgRpcClient,
&userRpcClient,
func(ctx context.Context, userIDs []string) ([]notification.CommonUser, error) {
users, err := userRpcClient.GetUsersInfo(ctx, userIDs) users, err := userRpcClient.GetUsersInfo(ctx, userIDs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return utils.Slice(users, func(e *sdkws.UserInfo) notification.CommonUser { return e }), nil return utils.Slice(users, func(e *sdkws.UserInfo) notification.CommonUser { return e }), nil
}), },
),
conversationRpcClient: conversationRpcClient, conversationRpcClient: conversationRpcClient,
msgRpcClient: msgRpcClient, msgRpcClient: msgRpcClient,
}) })
@ -120,7 +127,16 @@ func (s *groupServer) GenGroupID(ctx context.Context, groupID *string) error {
} }
} }
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
id := utils.Md5(strings.Join([]string{mcontext.GetOperationID(ctx), strconv.FormatInt(time.Now().UnixNano(), 10), strconv.Itoa(rand.Int())}, ",;,")) id := utils.Md5(
strings.Join(
[]string{
mcontext.GetOperationID(ctx),
strconv.FormatInt(time.Now().UnixNano(), 10),
strconv.Itoa(rand.Int()),
},
",;,",
),
)
bi := big.NewInt(0) bi := big.NewInt(0)
bi.SetString(id[0:8], 16) bi.SetString(id[0:8], 16)
id = bi.String() id = bi.String()
@ -234,7 +250,10 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
return resp, nil return resp, nil
} }
func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJoinedGroupListReq) (*pbGroup.GetJoinedGroupListResp, error) { func (s *groupServer) GetJoinedGroupList(
ctx context.Context,
req *pbGroup.GetJoinedGroupListReq,
) (*pbGroup.GetJoinedGroupListResp, error) {
resp := &pbGroup.GetJoinedGroupListResp{} resp := &pbGroup.GetJoinedGroupListResp{}
if err := tokenverify.CheckAccessV3(ctx, req.FromUserID); err != nil { if err := tokenverify.CheckAccessV3(ctx, req.FromUserID); err != nil {
return nil, err return nil, err
@ -244,7 +263,8 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
pageNumber = req.Pagination.PageNumber pageNumber = req.Pagination.PageNumber
showNumber = req.Pagination.ShowNumber showNumber = req.Pagination.ShowNumber
} }
//total, members, err := s.GroupDatabase.PageGroupMember(ctx, nil, []string{req.FromUserID}, nil, pageNumber, showNumber) // total, members, err := s.GroupDatabase.PageGroupMember(ctx, nil, []string{req.FromUserID}, nil, pageNumber,
// showNumber)
total, members, err := s.GroupDatabase.PageGetJoinGroup(ctx, req.FromUserID, pageNumber, showNumber) total, members, err := s.GroupDatabase.PageGetJoinGroup(ctx, req.FromUserID, pageNumber, showNumber)
if err != nil { if err != nil {
return nil, err return nil, err
@ -283,7 +303,10 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
return resp, nil return resp, nil
} }
func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.InviteUserToGroupReq) (*pbGroup.InviteUserToGroupResp, error) { func (s *groupServer) InviteUserToGroup(
ctx context.Context,
req *pbGroup.InviteUserToGroupReq,
) (*pbGroup.InviteUserToGroupResp, error) {
resp := &pbGroup.InviteUserToGroupResp{} resp := &pbGroup.InviteUserToGroupResp{}
if len(req.InvitedUserIDs) == 0 { if len(req.InvitedUserIDs) == 0 {
return nil, errs.ErrArgs.Wrap("user empty") return nil, errs.ErrArgs.Wrap("user empty")
@ -384,7 +407,10 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
return resp, nil return resp, nil
} }
func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGroupAllMemberReq) (*pbGroup.GetGroupAllMemberResp, error) { func (s *groupServer) GetGroupAllMember(
ctx context.Context,
req *pbGroup.GetGroupAllMemberReq,
) (*pbGroup.GetGroupAllMemberResp, error) {
resp := &pbGroup.GetGroupAllMemberResp{} resp := &pbGroup.GetGroupAllMemberResp{}
group, err := s.GroupDatabase.TakeGroup(ctx, req.GroupID) group, err := s.GroupDatabase.TakeGroup(ctx, req.GroupID)
if err != nil { if err != nil {
@ -412,7 +438,10 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
return resp, nil return resp, nil
} }
func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGroupMemberListReq) (*pbGroup.GetGroupMemberListResp, error) { func (s *groupServer) GetGroupMemberList(
ctx context.Context,
req *pbGroup.GetGroupMemberListReq,
) (*pbGroup.GetGroupMemberListResp, error) {
resp := &pbGroup.GetGroupMemberListResp{} resp := &pbGroup.GetGroupMemberListResp{}
total, members, err := s.PageGetGroupMember(ctx, req.GroupID, req.Pagination.PageNumber, req.Pagination.ShowNumber) total, members, err := s.PageGetGroupMember(ctx, req.GroupID, req.Pagination.PageNumber, req.Pagination.ShowNumber)
log.ZDebug(ctx, "GetGroupMemberList", "total", total, "members", members, "length", len(members)) log.ZDebug(ctx, "GetGroupMemberList", "total", total, "members", members, "length", len(members))
@ -425,7 +454,10 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGr
return resp, nil return resp, nil
} }
func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGroupMemberReq) (*pbGroup.KickGroupMemberResp, error) { func (s *groupServer) KickGroupMember(
ctx context.Context,
req *pbGroup.KickGroupMemberReq,
) (*pbGroup.KickGroupMemberResp, error) {
resp := &pbGroup.KickGroupMemberResp{} resp := &pbGroup.KickGroupMemberResp{}
group, err := s.GroupDatabase.TakeGroup(ctx, req.GroupID) group, err := s.GroupDatabase.TakeGroup(ctx, req.GroupID)
if err != nil { if err != nil {
@ -533,7 +565,10 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
return resp, nil return resp, nil
} }
func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetGroupMembersInfoReq) (*pbGroup.GetGroupMembersInfoResp, error) { func (s *groupServer) GetGroupMembersInfo(
ctx context.Context,
req *pbGroup.GetGroupMembersInfoReq,
) (*pbGroup.GetGroupMembersInfoResp, error) {
resp := &pbGroup.GetGroupMembersInfoResp{} resp := &pbGroup.GetGroupMembersInfoResp{}
if len(req.UserIDs) == 0 { if len(req.UserIDs) == 0 {
return nil, errs.ErrArgs.Wrap("userIDs empty") return nil, errs.ErrArgs.Wrap("userIDs empty")
@ -560,7 +595,10 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG
return resp, nil return resp, nil
} }
func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.GetGroupApplicationListReq) (*pbGroup.GetGroupApplicationListResp, error) { func (s *groupServer) GetGroupApplicationList(
ctx context.Context,
req *pbGroup.GetGroupApplicationListReq,
) (*pbGroup.GetGroupApplicationListResp, error) {
pageNumber, showNumber := utils.GetPage(req.Pagination) pageNumber, showNumber := utils.GetPage(req.Pagination)
groupIDs, err := s.GroupDatabase.FindUserManagedGroupID(ctx, req.FromUserID) groupIDs, err := s.GroupDatabase.FindUserManagedGroupID(ctx, req.FromUserID)
@ -611,12 +649,19 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.
return e.GroupID return e.GroupID
}) })
resp.GroupRequests = utils.Slice(groupRequests, func(e *relationTb.GroupRequestModel) *sdkws.GroupRequest { resp.GroupRequests = utils.Slice(groupRequests, func(e *relationTb.GroupRequestModel) *sdkws.GroupRequest {
return convert.Db2PbGroupRequest(e, userMap[e.UserID], convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerMap[e.GroupID].UserID, groupMemberNumMap[e.GroupID])) return convert.Db2PbGroupRequest(
e,
userMap[e.UserID],
convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerMap[e.GroupID].UserID, groupMemberNumMap[e.GroupID]),
)
}) })
return resp, nil return resp, nil
} }
func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsInfoReq) (*pbGroup.GetGroupsInfoResp, error) { func (s *groupServer) GetGroupsInfo(
ctx context.Context,
req *pbGroup.GetGroupsInfoReq,
) (*pbGroup.GetGroupsInfoResp, error) {
resp := &pbGroup.GetGroupsInfoResp{} resp := &pbGroup.GetGroupsInfoResp{}
if len(req.GroupIDs) == 0 { if len(req.GroupIDs) == 0 {
return nil, errs.ErrArgs.Wrap("groupID is empty") return nil, errs.ErrArgs.Wrap("groupID is empty")
@ -646,7 +691,10 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
return resp, nil return resp, nil
} }
func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) { func (s *groupServer) GroupApplicationResponse(
ctx context.Context,
req *pbGroup.GroupApplicationResponseReq,
) (*pbGroup.GroupApplicationResponseResp, error) {
defer log.ZInfo(ctx, utils.GetFuncName()+" Return") defer log.ZInfo(ctx, utils.GetFuncName()+" Return")
if !utils.Contain(req.HandleResult, constant.GroupResponseAgree, constant.GroupResponseRefuse) { if !utils.Contain(req.HandleResult, constant.GroupResponseAgree, constant.GroupResponseRefuse) {
return nil, errs.ErrArgs.Wrap("HandleResult unknown") return nil, errs.ErrArgs.Wrap("HandleResult unknown")
@ -718,7 +766,10 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
return &pbGroup.GroupApplicationResponseResp{}, nil return &pbGroup.GroupApplicationResponseResp{}, nil
} }
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (resp *pbGroup.JoinGroupResp, err error) { func (s *groupServer) JoinGroup(
ctx context.Context,
req *pbGroup.JoinGroupReq,
) (resp *pbGroup.JoinGroupResp, err error) {
defer log.ZInfo(ctx, "JoinGroup.Return") defer log.ZInfo(ctx, "JoinGroup.Return")
user, err := s.User.GetUserInfo(ctx, req.InviterUserID) user, err := s.User.GetUserInfo(ctx, req.InviterUserID)
if err != nil { if err != nil {
@ -818,7 +869,10 @@ func (s *groupServer) deleteMemberAndSetConversationSeq(ctx context.Context, gro
return s.conversationRpcClient.SetConversationMaxSeq(ctx, userIDs, conevrsationID, maxSeq) return s.conversationRpcClient.SetConversationMaxSeq(ctx, userIDs, conevrsationID, maxSeq)
} }
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.SetGroupInfoResp, error) { func (s *groupServer) SetGroupInfo(
ctx context.Context,
req *pbGroup.SetGroupInfoReq,
) (*pbGroup.SetGroupInfoResp, error) {
var opMember *relationTb.GroupMemberModel var opMember *relationTb.GroupMemberModel
if !tokenverify.IsAppManagerUid(ctx) { if !tokenverify.IsAppManagerUid(ctx) {
var err error var err error
@ -870,11 +924,17 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
go func() { go func() {
nctx := mcontext.NewCtx("@@@" + mcontext.GetOperationID(ctx)) nctx := mcontext.NewCtx("@@@" + mcontext.GetOperationID(ctx))
conversation := &pbConversation.ConversationReq{ conversation := &pbConversation.ConversationReq{
ConversationID: utils.GetConversationIDBySessionType(constant.SuperGroupChatType, req.GroupInfoForSet.GroupID), ConversationID: utils.GetConversationIDBySessionType(
constant.SuperGroupChatType,
req.GroupInfoForSet.GroupID,
),
ConversationType: constant.SuperGroupChatType, ConversationType: constant.SuperGroupChatType,
GroupID: req.GroupInfoForSet.GroupID, GroupID: req.GroupInfoForSet.GroupID,
} }
resp, err := s.GetGroupMemberUserIDs(nctx, &pbGroup.GetGroupMemberUserIDsReq{GroupID: req.GroupInfoForSet.GroupID}) resp, err := s.GetGroupMemberUserIDs(
nctx,
&pbGroup.GetGroupMemberUserIDsReq{GroupID: req.GroupInfoForSet.GroupID},
)
if err != nil { if err != nil {
log.ZWarn(ctx, "GetGroupMemberIDs", err) log.ZWarn(ctx, "GetGroupMemberIDs", err)
return return
@ -885,7 +945,10 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
} }
}() }()
num++ num++
s.Notification.GroupInfoSetAnnouncementNotification(ctx, &sdkws.GroupInfoSetAnnouncementTips{Group: tips.Group, OpUser: tips.OpUser}) s.Notification.GroupInfoSetAnnouncementNotification(
ctx,
&sdkws.GroupInfoSetAnnouncementTips{Group: tips.Group, OpUser: tips.OpUser},
)
} }
switch len(data) - num { switch len(data) - num {
@ -902,7 +965,10 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
return resp, nil return resp, nil
} }
func (s *groupServer) TransferGroupOwner(ctx context.Context, req *pbGroup.TransferGroupOwnerReq) (*pbGroup.TransferGroupOwnerResp, error) { func (s *groupServer) TransferGroupOwner(
ctx context.Context,
req *pbGroup.TransferGroupOwnerReq,
) (*pbGroup.TransferGroupOwnerResp, error) {
resp := &pbGroup.TransferGroupOwnerResp{} resp := &pbGroup.TransferGroupOwnerResp{}
group, err := s.GroupDatabase.TakeGroup(ctx, req.GroupID) group, err := s.GroupDatabase.TakeGroup(ctx, req.GroupID)
if err != nil { if err != nil {
@ -981,9 +1047,20 @@ func (s *groupServer) GetGroups(ctx context.Context, req *pbGroup.GetGroupsReq)
return resp, nil return resp, nil
} }
func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbGroup.GetGroupMembersCMSReq) (*pbGroup.GetGroupMembersCMSResp, error) { func (s *groupServer) GetGroupMembersCMS(
ctx context.Context,
req *pbGroup.GetGroupMembersCMSReq,
) (*pbGroup.GetGroupMembersCMSResp, error) {
resp := &pbGroup.GetGroupMembersCMSResp{} resp := &pbGroup.GetGroupMembersCMSResp{}
total, members, err := s.GroupDatabase.SearchGroupMember(ctx, req.UserName, []string{req.GroupID}, nil, nil, req.Pagination.PageNumber, req.Pagination.ShowNumber) total, members, err := s.GroupDatabase.SearchGroupMember(
ctx,
req.UserName,
[]string{req.GroupID},
nil,
nil,
req.Pagination.PageNumber,
req.Pagination.ShowNumber,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1003,7 +1080,10 @@ func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbGroup.GetGr
return resp, nil return resp, nil
} }
func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbGroup.GetUserReqApplicationListReq) (*pbGroup.GetUserReqApplicationListResp, error) { func (s *groupServer) GetUserReqApplicationList(
ctx context.Context,
req *pbGroup.GetUserReqApplicationListReq,
) (*pbGroup.GetUserReqApplicationListResp, error) {
resp := &pbGroup.GetUserReqApplicationListResp{} resp := &pbGroup.GetUserReqApplicationListResp{}
user, err := s.User.GetPublicUserInfo(ctx, req.UserID) user, err := s.User.GetPublicUserInfo(ctx, req.UserID)
if err != nil { if err != nil {
@ -1050,12 +1130,19 @@ func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbGrou
return nil, err return nil, err
} }
resp.GroupRequests = utils.Slice(requests, func(e *relationTb.GroupRequestModel) *sdkws.GroupRequest { resp.GroupRequests = utils.Slice(requests, func(e *relationTb.GroupRequestModel) *sdkws.GroupRequest {
return convert.Db2PbGroupRequest(e, user, convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerMap[e.GroupID].UserID, uint32(groupMemberNum[e.GroupID]))) return convert.Db2PbGroupRequest(
e,
user,
convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerMap[e.GroupID].UserID, uint32(groupMemberNum[e.GroupID])),
)
}) })
return resp, nil return resp, nil
} }
func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGroupReq) (*pbGroup.DismissGroupResp, error) { func (s *groupServer) DismissGroup(
ctx context.Context,
req *pbGroup.DismissGroupReq,
) (*pbGroup.DismissGroupResp, error) {
defer log.ZInfo(ctx, "DismissGroup.return") defer log.ZInfo(ctx, "DismissGroup.return")
resp := &pbGroup.DismissGroupResp{} resp := &pbGroup.DismissGroupResp{}
owner, err := s.TakeGroupOwner(ctx, req.GroupID) owner, err := s.TakeGroupOwner(ctx, req.GroupID)
@ -1104,7 +1191,10 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
return resp, nil return resp, nil
} }
func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGroupMemberReq) (*pbGroup.MuteGroupMemberResp, error) { func (s *groupServer) MuteGroupMember(
ctx context.Context,
req *pbGroup.MuteGroupMemberReq,
) (*pbGroup.MuteGroupMemberResp, error) {
resp := &pbGroup.MuteGroupMemberResp{} resp := &pbGroup.MuteGroupMemberResp{}
//if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil { //if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil {
// return nil, err // return nil, err
@ -1139,7 +1229,10 @@ func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGrou
return resp, nil return resp, nil
} }
func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.CancelMuteGroupMemberReq) (*pbGroup.CancelMuteGroupMemberResp, error) { func (s *groupServer) CancelMuteGroupMember(
ctx context.Context,
req *pbGroup.CancelMuteGroupMemberReq,
) (*pbGroup.CancelMuteGroupMemberResp, error) {
resp := &pbGroup.CancelMuteGroupMemberResp{} resp := &pbGroup.CancelMuteGroupMemberResp{}
//member, err := s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, req.UserID) //member, err := s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, req.UserID)
//if err != nil { //if err != nil {
@ -1151,7 +1244,8 @@ func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.Ca
// return nil, err // return nil, err
// } // }
// if opMember.RoleLevel <= member.RoleLevel { // if opMember.RoleLevel <= member.RoleLevel {
// return nil, errs.ErrNoPermission.Wrap(fmt.Sprintf("self RoleLevel %d target %d", opMember.RoleLevel, member.RoleLevel)) // return nil, errs.ErrNoPermission.Wrap(fmt.Sprintf("self RoleLevel %d target %d", opMember.RoleLevel,
// member.RoleLevel))
// } // }
//} //}
//if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil { //if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil {
@ -1199,7 +1293,10 @@ func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq)
return resp, nil return resp, nil
} }
func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMuteGroupReq) (*pbGroup.CancelMuteGroupResp, error) { func (s *groupServer) CancelMuteGroup(
ctx context.Context,
req *pbGroup.CancelMuteGroupReq,
) (*pbGroup.CancelMuteGroupResp, error) {
resp := &pbGroup.CancelMuteGroupResp{} resp := &pbGroup.CancelMuteGroupResp{}
if err := s.CheckGroupAdmin(ctx, req.GroupID); err != nil { if err := s.CheckGroupAdmin(ctx, req.GroupID); err != nil {
return nil, err return nil, err
@ -1211,7 +1308,10 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu
return resp, nil return resp, nil
} }
func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGroupMemberInfoReq) (*pbGroup.SetGroupMemberInfoResp, error) { func (s *groupServer) SetGroupMemberInfo(
ctx context.Context,
req *pbGroup.SetGroupMemberInfoReq,
) (*pbGroup.SetGroupMemberInfoResp, error) {
resp := &pbGroup.SetGroupMemberInfoResp{} resp := &pbGroup.SetGroupMemberInfoResp{}
if len(req.Members) == 0 { if len(req.Members) == 0 {
return nil, errs.ErrArgs.Wrap("members empty") return nil, errs.ErrArgs.Wrap("members empty")
@ -1238,9 +1338,11 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
delete(duplicateMap, [...]string{member.GroupID, member.UserID}) delete(duplicateMap, [...]string{member.GroupID, member.UserID})
} }
if len(duplicateMap) > 0 { if len(duplicateMap) > 0 {
return nil, errs.ErrArgs.Wrap("user not found" + strings.Join(utils.Slice(utils.Keys(duplicateMap), func(e [2]string) string { return nil, errs.ErrArgs.Wrap(
"user not found" + strings.Join(utils.Slice(utils.Keys(duplicateMap), func(e [2]string) string {
return fmt.Sprintf("[group: %s user: %s]", e[0], e[1]) return fmt.Sprintf("[group: %s user: %s]", e[0], e[1])
}), ",")) }), ","),
)
} }
memberMap := utils.SliceToMap(members, func(e *relationTb.GroupMemberModel) [2]string { memberMap := utils.SliceToMap(members, func(e *relationTb.GroupMemberModel) [2]string {
return [...]string{e.GroupID, e.UserID} return [...]string{e.GroupID, e.UserID}
@ -1270,7 +1372,9 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
} }
dbMember, ok := memberMap[[...]string{member.GroupID, member.UserID}] dbMember, ok := memberMap[[...]string{member.GroupID, member.UserID}]
if !ok { if !ok {
return nil, errs.ErrRecordNotFound.Wrap(fmt.Sprintf("user %s not in group %s", member.UserID, member.GroupID)) return nil, errs.ErrRecordNotFound.Wrap(
fmt.Sprintf("user %s not in group %s", member.UserID, member.GroupID),
)
} }
//if opMember.RoleLevel == constant.GroupOwner { //if opMember.RoleLevel == constant.GroupOwner {
// continue // continue
@ -1332,14 +1436,25 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
if member.Nickname != nil || member.FaceURL != nil || member.Ex != nil { if member.Nickname != nil || member.FaceURL != nil || member.Ex != nil {
log.ZDebug(ctx, "setGroupMemberInfo notification", "member", member.UserID) log.ZDebug(ctx, "setGroupMemberInfo notification", "member", member.UserID)
if err := s.Notification.GroupMemberInfoSetNotification(ctx, member.GroupID, member.UserID); err != nil { if err := s.Notification.GroupMemberInfoSetNotification(ctx, member.GroupID, member.UserID); err != nil {
log.ZError(ctx, "setGroupMemberInfo notification failed", err, "member", member.UserID, "groupID", member.GroupID) log.ZError(
ctx,
"setGroupMemberInfo notification failed",
err,
"member",
member.UserID,
"groupID",
member.GroupID,
)
} }
} }
} }
return resp, nil return resp, nil
} }
func (s *groupServer) GetGroupAbstractInfo(ctx context.Context, req *pbGroup.GetGroupAbstractInfoReq) (*pbGroup.GetGroupAbstractInfoResp, error) { func (s *groupServer) GetGroupAbstractInfo(
ctx context.Context,
req *pbGroup.GetGroupAbstractInfoReq,
) (*pbGroup.GetGroupAbstractInfoResp, error) {
resp := &pbGroup.GetGroupAbstractInfoResp{} resp := &pbGroup.GetGroupAbstractInfoResp{}
if len(req.GroupIDs) == 0 { if len(req.GroupIDs) == 0 {
return nil, errs.ErrArgs.Wrap("groupIDs empty") return nil, errs.ErrArgs.Wrap("groupIDs empty")
@ -1370,7 +1485,10 @@ func (s *groupServer) GetGroupAbstractInfo(ctx context.Context, req *pbGroup.Get
return resp, nil return resp, nil
} }
func (s *groupServer) GetUserInGroupMembers(ctx context.Context, req *pbGroup.GetUserInGroupMembersReq) (*pbGroup.GetUserInGroupMembersResp, error) { func (s *groupServer) GetUserInGroupMembers(
ctx context.Context,
req *pbGroup.GetUserInGroupMembersReq,
) (*pbGroup.GetUserInGroupMembersResp, error) {
resp := &pbGroup.GetUserInGroupMembersResp{} resp := &pbGroup.GetUserInGroupMembersResp{}
if len(req.GroupIDs) == 0 { if len(req.GroupIDs) == 0 {
return nil, errs.ErrArgs.Wrap("groupIDs empty") return nil, errs.ErrArgs.Wrap("groupIDs empty")
@ -1394,7 +1512,10 @@ func (s *groupServer) GetUserInGroupMembers(ctx context.Context, req *pbGroup.Ge
return resp, nil return resp, nil
} }
func (s *groupServer) GetGroupMemberUserIDs(ctx context.Context, req *pbGroup.GetGroupMemberUserIDsReq) (resp *pbGroup.GetGroupMemberUserIDsResp, err error) { func (s *groupServer) GetGroupMemberUserIDs(
ctx context.Context,
req *pbGroup.GetGroupMemberUserIDsReq,
) (resp *pbGroup.GetGroupMemberUserIDsResp, err error) {
resp = &pbGroup.GetGroupMemberUserIDsResp{} resp = &pbGroup.GetGroupMemberUserIDsResp{}
resp.UserIDs, err = s.GroupDatabase.FindGroupMemberUserID(ctx, req.GroupID) resp.UserIDs, err = s.GroupDatabase.FindGroupMemberUserID(ctx, req.GroupID)
if err != nil { if err != nil {
@ -1403,7 +1524,10 @@ func (s *groupServer) GetGroupMemberUserIDs(ctx context.Context, req *pbGroup.Ge
return resp, nil return resp, nil
} }
func (s *groupServer) GetGroupMemberRoleLevel(ctx context.Context, req *pbGroup.GetGroupMemberRoleLevelReq) (*pbGroup.GetGroupMemberRoleLevelResp, error) { func (s *groupServer) GetGroupMemberRoleLevel(
ctx context.Context,
req *pbGroup.GetGroupMemberRoleLevelReq,
) (*pbGroup.GetGroupMemberRoleLevelResp, error) {
resp := &pbGroup.GetGroupMemberRoleLevelResp{} resp := &pbGroup.GetGroupMemberRoleLevelResp{}
if len(req.RoleLevels) == 0 { if len(req.RoleLevels) == 0 {
return nil, errs.ErrArgs.Wrap("RoleLevels empty") return nil, errs.ErrArgs.Wrap("RoleLevels empty")

@ -2,12 +2,16 @@ package group
import ( import (
"context" "context"
"time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group"
"time"
) )
func (s *groupServer) GroupCreateCount(ctx context.Context, req *group.GroupCreateCountReq) (*group.GroupCreateCountResp, error) { func (s *groupServer) GroupCreateCount(
ctx context.Context,
req *group.GroupCreateCountReq,
) (*group.GroupCreateCountResp, error) {
if req.Start > req.End { if req.Start > req.End {
return nil, errs.ErrArgs.Wrap("start > end") return nil, errs.ErrArgs.Wrap("start > end")
} }

@ -124,3 +124,24 @@ func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg.
} }
return &msg.RevokeMsgResp{}, nil return &msg.RevokeMsgResp{}, nil
} }
func (m *msgServer) ManageMsg(ctx context.Context, req *msg.ManageMsgReq) (*msg.ManageMsgResp, error) {
resp := &msg.ManageMsgResp{}
msgData := &sdkws.MsgData{
SendID: req.SendID,
RecvID: req.RecvID,
SessionType: req.SessionType,
GroupID: req.GroupID,
}
conversationID := utils.GetChatConversationIDByMsg(msgData)
revokeReq := &msg.RevokeMsgReq{
ConversationID: conversationID,
Seq: req.Seq,
UserID: req.SendID,
}
_, err := m.RevokeMsg(ctx, revokeReq)
if err != nil {
return nil, err
}
return resp, nil
}

@ -2,6 +2,9 @@ package msg
import ( import (
"context" "context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation"
"google.golang.org/grpc"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
@ -13,7 +16,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"google.golang.org/grpc"
) )
type MessageInterceptorChain []MessageInterceptorFunc type MessageInterceptorChain []MessageInterceptorFunc
@ -60,11 +62,13 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
} }
cacheModel := cache.NewMsgCacheModel(rdb) cacheModel := cache.NewMsgCacheModel(rdb)
msgDocModel := unrelation.NewMsgMongoDriver(mongo.GetDatabase()) msgDocModel := unrelation.NewMsgMongoDriver(mongo.GetDatabase())
msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, cacheModel)
conversationClient := rpcclient.NewConversationRpcClient(client) conversationClient := rpcclient.NewConversationRpcClient(client)
userRpcClient := rpcclient.NewUserRpcClient(client) userRpcClient := rpcclient.NewUserRpcClient(client)
groupRpcClient := rpcclient.NewGroupRpcClient(client) groupRpcClient := rpcclient.NewGroupRpcClient(client)
friendRpcClient := rpcclient.NewFriendRpcClient(client) friendRpcClient := rpcclient.NewFriendRpcClient(client)
mysql, err := relation.NewGormDB()
msgMysModel := relation.NewChatLogGorm(mysql)
msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, cacheModel, msgMysModel)
s := &msgServer{ s := &msgServer{
Conversation: &conversationClient, Conversation: &conversationClient,
User: &userRpcClient, User: &userRpcClient,
@ -100,7 +104,8 @@ func (m *msgServer) initPrometheus() {
} }
func (m *msgServer) conversationAndGetRecvID(conversation *conversation.Conversation, userID string) (recvID string) { func (m *msgServer) conversationAndGetRecvID(conversation *conversation.Conversation, userID string) (recvID string) {
if conversation.ConversationType == constant.SingleChatType || conversation.ConversationType == constant.NotificationChatType { if conversation.ConversationType == constant.SingleChatType ||
conversation.ConversationType == constant.NotificationChatType {
if userID == conversation.OwnerUserID { if userID == conversation.OwnerUserID {
recvID = conversation.UserID recvID = conversation.UserID
} else { } else {

@ -2,15 +2,24 @@ package msg
import ( import (
"context" "context"
"time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"time"
) )
func (m *msgServer) GetActiveUser(ctx context.Context, req *msg.GetActiveUserReq) (*msg.GetActiveUserResp, error) { func (m *msgServer) GetActiveUser(ctx context.Context, req *msg.GetActiveUserReq) (*msg.GetActiveUserResp, error) {
msgCount, userCount, users, dateCount, err := m.MsgDatabase.RangeUserSendCount(ctx, time.UnixMilli(req.Start), time.UnixMilli(req.End), req.Group, req.Ase, req.Pagination.PageNumber, req.Pagination.ShowNumber) msgCount, userCount, users, dateCount, err := m.MsgDatabase.RangeUserSendCount(
ctx,
time.UnixMilli(req.Start),
time.UnixMilli(req.End),
req.Group,
req.Ase,
req.Pagination.PageNumber,
req.Pagination.ShowNumber,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -45,7 +54,14 @@ func (m *msgServer) GetActiveUser(ctx context.Context, req *msg.GetActiveUserReq
} }
func (m *msgServer) GetActiveGroup(ctx context.Context, req *msg.GetActiveGroupReq) (*msg.GetActiveGroupResp, error) { func (m *msgServer) GetActiveGroup(ctx context.Context, req *msg.GetActiveGroupReq) (*msg.GetActiveGroupResp, error) {
msgCount, groupCount, groups, dateCount, err := m.MsgDatabase.RangeGroupSendCount(ctx, time.UnixMilli(req.Start), time.UnixMilli(req.End), req.Ase, req.Pagination.PageNumber, req.Pagination.ShowNumber) msgCount, groupCount, groups, dateCount, err := m.MsgDatabase.RangeGroupSendCount(
ctx,
time.UnixMilli(req.Start),
time.UnixMilli(req.End),
req.Ase,
req.Pagination.PageNumber,
req.Pagination.ShowNumber,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -16,6 +16,8 @@ package msg
import ( import (
"context" "context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
@ -102,3 +104,50 @@ func (m *msgServer) GetMaxSeq(ctx context.Context, req *sdkws.GetMaxSeqReq) (*sd
resp.MaxSeqs = maxSeqs resp.MaxSeqs = maxSeqs
return resp, nil return resp, nil
} }
func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq) (resp *msg.SearchMessageResp, err error) {
var chatLogs []*sdkws.MsgData
resp = &msg.SearchMessageResp{}
if chatLogs, err = m.MsgDatabase.SearchMessage(ctx, req); err != nil {
return nil, err
}
var num int
for _, chatLog := range chatLogs {
pbChatLog := &msg.ChatLog{}
utils.CopyStructFields(pbChatLog, chatLog)
pbChatLog.SendTime = chatLog.SendTime
pbChatLog.CreateTime = chatLog.CreateTime
if chatLog.SenderNickname == "" {
sendUser, err := m.User.GetUserInfo(ctx, chatLog.SendID)
if err != nil {
return nil, err
}
pbChatLog.SenderNickname = sendUser.Nickname
}
switch chatLog.SessionType {
case constant.SingleChatType:
recvUser, err := m.User.GetUserInfo(ctx, chatLog.RecvID)
if err != nil {
return nil, err
}
pbChatLog.SenderNickname = recvUser.Nickname
case constant.GroupChatType, constant.SuperGroupChatType:
group, err := m.Group.GetGroupInfo(ctx, chatLog.GroupID)
if err != nil {
return nil, err
}
pbChatLog.SenderFaceURL = group.FaceURL
pbChatLog.GroupMemberCount = group.MemberCount
pbChatLog.RecvID = group.GroupID
pbChatLog.GroupName = group.GroupName
pbChatLog.GroupOwner = group.OwnerUserID
pbChatLog.GroupType = group.GroupType
}
resp.ChatLogs = append(resp.ChatLogs, pbChatLog)
num++
}
resp.ChatLogsNum = int32(num)
return resp, nil
}

@ -2,6 +2,8 @@ package third
import ( import (
"context" "context"
"time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/cont" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/cont"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
@ -9,7 +11,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"time"
) )
func (t *thirdServer) PartLimit(ctx context.Context, req *third.PartLimitReq) (*third.PartLimitResp, error) { func (t *thirdServer) PartLimit(ctx context.Context, req *third.PartLimitReq) (*third.PartLimitResp, error) {
@ -29,7 +30,10 @@ func (t *thirdServer) PartSize(ctx context.Context, req *third.PartSizeReq) (*th
return &third.PartSizeResp{Size: size}, nil return &third.PartSizeResp{Size: size}, nil
} }
func (t *thirdServer) InitiateMultipartUpload(ctx context.Context, req *third.InitiateMultipartUploadReq) (*third.InitiateMultipartUploadResp, error) { func (t *thirdServer) InitiateMultipartUpload(
ctx context.Context,
req *third.InitiateMultipartUploadReq,
) (*third.InitiateMultipartUploadResp, error) {
defer log.ZDebug(ctx, "return") defer log.ZDebug(ctx, "return")
if err := checkUploadName(ctx, req.Name); err != nil { if err := checkUploadName(ctx, req.Name); err != nil {
return nil, err return nil, err
@ -108,7 +112,10 @@ func (t *thirdServer) AuthSign(ctx context.Context, req *third.AuthSignReq) (*th
return resp, nil return resp, nil
} }
func (t *thirdServer) CompleteMultipartUpload(ctx context.Context, req *third.CompleteMultipartUploadReq) (*third.CompleteMultipartUploadResp, error) { func (t *thirdServer) CompleteMultipartUpload(
ctx context.Context,
req *third.CompleteMultipartUploadReq,
) (*third.CompleteMultipartUploadResp, error) {
defer log.ZDebug(ctx, "return") defer log.ZDebug(ctx, "return")
if err := checkUploadName(ctx, req.Name); err != nil { if err := checkUploadName(ctx, req.Name); err != nil {
return nil, err return nil, err

@ -3,12 +3,15 @@ package third
import ( import (
"context" "context"
"fmt" "fmt"
"net/url"
"time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/cos" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/cos"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/minio" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/minio"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/oss" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/oss"
"net/url"
"time" "google.golang.org/grpc"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
@ -18,7 +21,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"google.golang.org/grpc"
) )
func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error { func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
@ -77,7 +79,10 @@ type thirdServer struct {
defaultExpire time.Duration defaultExpire time.Duration
} }
func (t *thirdServer) FcmUpdateToken(ctx context.Context, req *third.FcmUpdateTokenReq) (resp *third.FcmUpdateTokenResp, err error) { func (t *thirdServer) FcmUpdateToken(
ctx context.Context,
req *third.FcmUpdateTokenReq,
) (resp *third.FcmUpdateTokenResp, err error) {
err = t.thirdDatabase.FcmUpdateToken(ctx, req.Account, int(req.PlatformID), req.FcmToken, req.ExpireTime) err = t.thirdDatabase.FcmUpdateToken(ctx, req.Account, int(req.PlatformID), req.FcmToken, req.ExpireTime)
if err != nil { if err != nil {
return nil, err return nil, err
@ -85,7 +90,10 @@ func (t *thirdServer) FcmUpdateToken(ctx context.Context, req *third.FcmUpdateTo
return &third.FcmUpdateTokenResp{}, nil return &third.FcmUpdateTokenResp{}, nil
} }
func (t *thirdServer) SetAppBadge(ctx context.Context, req *third.SetAppBadgeReq) (resp *third.SetAppBadgeResp, err error) { func (t *thirdServer) SetAppBadge(
ctx context.Context,
req *third.SetAppBadgeReq,
) (resp *third.SetAppBadgeResp, err error) {
err = t.thirdDatabase.SetAppBadge(ctx, req.UserID, int(req.AppUnreadCount)) err = t.thirdDatabase.SetAppBadge(ctx, req.UserID, int(req.AppUnreadCount))
if err != nil { if err != nil {
return nil, err return nil, err

@ -4,12 +4,13 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"strings"
"unicode/utf8"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
"strings"
"unicode/utf8"
) )
func toPbMapArray(m map[string][]string) []*third.KeyValues { func toPbMapArray(m map[string][]string) []*third.KeyValues {

@ -24,8 +24,9 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/grpc" "google.golang.org/grpc"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
) )
type userServer struct { type userServer struct {
@ -63,13 +64,19 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
UserDatabase: database, UserDatabase: database,
RegisterCenter: client, RegisterCenter: client,
friendRpcClient: &friendRpcClient, friendRpcClient: &friendRpcClient,
notificationSender: notification.NewFriendNotificationSender(&msgRpcClient, notification.WithDBFunc(database.FindWithError)), notificationSender: notification.NewFriendNotificationSender(
&msgRpcClient,
notification.WithDBFunc(database.FindWithError),
),
} }
pbuser.RegisterUserServer(server, u) pbuser.RegisterUserServer(server, u)
return u.UserDatabase.InitOnce(context.Background(), users) return u.UserDatabase.InitOnce(context.Background(), users)
} }
func (s *userServer) GetDesignateUsers(ctx context.Context, req *pbuser.GetDesignateUsersReq) (resp *pbuser.GetDesignateUsersResp, err error) { func (s *userServer) GetDesignateUsers(
ctx context.Context,
req *pbuser.GetDesignateUsersReq,
) (resp *pbuser.GetDesignateUsersResp, err error) {
resp = &pbuser.GetDesignateUsersResp{} resp = &pbuser.GetDesignateUsersResp{}
users, err := s.FindWithError(ctx, req.UserIDs) users, err := s.FindWithError(ctx, req.UserIDs)
if err != nil { if err != nil {
@ -82,7 +89,10 @@ func (s *userServer) GetDesignateUsers(ctx context.Context, req *pbuser.GetDesig
return resp, nil return resp, nil
} }
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserInfoReq) (resp *pbuser.UpdateUserInfoResp, err error) { func (s *userServer) UpdateUserInfo(
ctx context.Context,
req *pbuser.UpdateUserInfoReq,
) (resp *pbuser.UpdateUserInfoResp, err error) {
resp = &pbuser.UpdateUserInfoResp{} resp = &pbuser.UpdateUserInfoResp{}
err = tokenverify.CheckAccessV3(ctx, req.UserInfo.UserID) err = tokenverify.CheckAccessV3(ctx, req.UserInfo.UserID)
if err != nil { if err != nil {
@ -107,7 +117,10 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
return resp, nil return resp, nil
} }
func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbuser.SetGlobalRecvMessageOptReq) (resp *pbuser.SetGlobalRecvMessageOptResp, err error) { func (s *userServer) SetGlobalRecvMessageOpt(
ctx context.Context,
req *pbuser.SetGlobalRecvMessageOptReq,
) (resp *pbuser.SetGlobalRecvMessageOptResp, err error) {
resp = &pbuser.SetGlobalRecvMessageOptResp{} resp = &pbuser.SetGlobalRecvMessageOptResp{}
if _, err := s.FindWithError(ctx, []string{req.UserID}); err != nil { if _, err := s.FindWithError(ctx, []string{req.UserID}); err != nil {
return nil, err return nil, err
@ -121,7 +134,10 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbuser.Se
return resp, nil return resp, nil
} }
func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckReq) (resp *pbuser.AccountCheckResp, err error) { func (s *userServer) AccountCheck(
ctx context.Context,
req *pbuser.AccountCheckReq,
) (resp *pbuser.AccountCheckResp, err error) {
resp = &pbuser.AccountCheckResp{} resp = &pbuser.AccountCheckResp{}
if utils.Duplicate(req.CheckUserIDs) { if utils.Duplicate(req.CheckUserIDs) {
return nil, errs.ErrArgs.Wrap("userID repeated") return nil, errs.ErrArgs.Wrap("userID repeated")
@ -150,7 +166,10 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckR
return resp, nil return resp, nil
} }
func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPaginationUsersReq) (resp *pbuser.GetPaginationUsersResp, err error) { func (s *userServer) GetPaginationUsers(
ctx context.Context,
req *pbuser.GetPaginationUsersReq,
) (resp *pbuser.GetPaginationUsersResp, err error) {
var pageNumber, showNumber int32 var pageNumber, showNumber int32
if req.Pagination != nil { if req.Pagination != nil {
pageNumber = req.Pagination.PageNumber pageNumber = req.Pagination.PageNumber
@ -163,7 +182,10 @@ func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPagi
return &pbuser.GetPaginationUsersResp{Total: int32(total), Users: convert.UsersDB2Pb(users)}, err return &pbuser.GetPaginationUsersResp{Total: int32(total), Users: convert.UsersDB2Pb(users)}, err
} }
func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterReq) (resp *pbuser.UserRegisterResp, err error) { func (s *userServer) UserRegister(
ctx context.Context,
req *pbuser.UserRegisterReq,
) (resp *pbuser.UserRegisterResp, err error) {
resp = &pbuser.UserRegisterResp{} resp = &pbuser.UserRegisterResp{}
if len(req.Users) == 0 { if len(req.Users) == 0 {
return nil, errs.ErrArgs.Wrap("users is empty") return nil, errs.ErrArgs.Wrap("users is empty")
@ -211,7 +233,10 @@ func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterR
return resp, nil return resp, nil
} }
func (s *userServer) GetGlobalRecvMessageOpt(ctx context.Context, req *pbuser.GetGlobalRecvMessageOptReq) (resp *pbuser.GetGlobalRecvMessageOptResp, err error) { func (s *userServer) GetGlobalRecvMessageOpt(
ctx context.Context,
req *pbuser.GetGlobalRecvMessageOptReq,
) (resp *pbuser.GetGlobalRecvMessageOptResp, err error) {
user, err := s.FindWithError(ctx, []string{req.UserID}) user, err := s.FindWithError(ctx, []string{req.UserID})
if err != nil { if err != nil {
return nil, err return nil, err
@ -219,7 +244,10 @@ func (s *userServer) GetGlobalRecvMessageOpt(ctx context.Context, req *pbuser.Ge
return &pbuser.GetGlobalRecvMessageOptResp{GlobalRecvMsgOpt: user[0].GlobalRecvMsgOpt}, nil return &pbuser.GetGlobalRecvMessageOptResp{GlobalRecvMsgOpt: user[0].GlobalRecvMsgOpt}, nil
} }
func (s *userServer) GetAllUserID(ctx context.Context, req *pbuser.GetAllUserIDReq) (resp *pbuser.GetAllUserIDResp, err error) { func (s *userServer) GetAllUserID(
ctx context.Context,
req *pbuser.GetAllUserIDReq,
) (resp *pbuser.GetAllUserIDResp, err error) {
userIDs, err := s.UserDatabase.GetAllUserID(ctx) userIDs, err := s.UserDatabase.GetAllUserID(ctx)
if err != nil { if err != nil {
return nil, err return nil, err

@ -19,19 +19,60 @@ func (c *MsgTool) ConversationsDestructMsgs() {
} }
log.ZDebug(context.Background(), "nums conversations need destruct", "nums", len(conversations)) log.ZDebug(context.Background(), "nums conversations need destruct", "nums", len(conversations))
for _, conversation := range conversations { for _, conversation := range conversations {
log.ZDebug(ctx, "UserMsgsDestruct", "conversationID", conversation.ConversationID, "ownerUserID", conversation.OwnerUserID, "msgDestructTime", conversation.MsgDestructTime, "lastMsgDestructTime", conversation.LatestMsgDestructTime) log.ZDebug(
seqs, err := c.msgDatabase.UserMsgsDestruct(ctx, conversation.OwnerUserID, conversation.ConversationID, conversation.MsgDestructTime, conversation.LatestMsgDestructTime) ctx,
"UserMsgsDestruct",
"conversationID",
conversation.ConversationID,
"ownerUserID",
conversation.OwnerUserID,
"msgDestructTime",
conversation.MsgDestructTime,
"lastMsgDestructTime",
conversation.LatestMsgDestructTime,
)
seqs, err := c.msgDatabase.UserMsgsDestruct(
ctx,
conversation.OwnerUserID,
conversation.ConversationID,
conversation.MsgDestructTime,
conversation.LatestMsgDestructTime,
)
if err != nil { if err != nil {
log.ZError(ctx, "user msg destruct failed", err, "conversationID", conversation.ConversationID, "ownerUserID", conversation.OwnerUserID) log.ZError(
ctx,
"user msg destruct failed",
err,
"conversationID",
conversation.ConversationID,
"ownerUserID",
conversation.OwnerUserID,
)
continue continue
} }
if err := c.conversationDatabase.UpdateUsersConversationFiled(ctx, []string{conversation.OwnerUserID}, conversation.ConversationID, map[string]interface{}{"latest_msg_destruct_time": time.Now()}); err != nil { if err := c.conversationDatabase.UpdateUsersConversationFiled(ctx, []string{conversation.OwnerUserID}, conversation.ConversationID, map[string]interface{}{"latest_msg_destruct_time": time.Now()}); err != nil {
log.ZError(ctx, "updateUsersConversationFiled failed", err, "conversationID", conversation.ConversationID, "ownerUserID", conversation.OwnerUserID) log.ZError(
ctx,
"updateUsersConversationFiled failed",
err,
"conversationID",
conversation.ConversationID,
"ownerUserID",
conversation.OwnerUserID,
)
continue continue
} }
if len(seqs) > 0 { if len(seqs) > 0 {
if err := c.msgNotificationSender.UserDeleteMsgsNotification(ctx, conversation.OwnerUserID, conversation.ConversationID, seqs); err != nil { if err := c.msgNotificationSender.UserDeleteMsgsNotification(ctx, conversation.OwnerUserID, conversation.ConversationID, seqs); err != nil {
log.ZError(ctx, "userDeleteMsgsNotification failed", err, "conversationID", conversation.ConversationID, "ownerUserID", conversation.OwnerUserID) log.ZError(
ctx,
"userDeleteMsgsNotification failed",
err,
"conversationID",
conversation.ConversationID,
"ownerUserID",
conversation.OwnerUserID,
)
} }
} }
} }

@ -34,10 +34,19 @@ func StartCronTask() error {
c := cron.New() c := cron.New()
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(1) wg.Add(1)
log.ZInfo(context.Background(), "start chatRecordsClearTime cron task", "cron config", config.Config.ChatRecordsClearTime) log.ZInfo(
context.Background(),
"start chatRecordsClearTime cron task",
"cron config",
config.Config.ChatRecordsClearTime,
)
_, err = c.AddFunc(config.Config.ChatRecordsClearTime, msgTool.AllConversationClearMsgAndFixSeq) _, err = c.AddFunc(config.Config.ChatRecordsClearTime, msgTool.AllConversationClearMsgAndFixSeq)
if err != nil { if err != nil {
fmt.Println("start allConversationClearMsgAndFixSeq cron failed", err.Error(), config.Config.ChatRecordsClearTime) fmt.Println(
"start allConversationClearMsgAndFixSeq cron failed",
err.Error(),
config.Config.ChatRecordsClearTime,
)
panic(err) panic(err)
} }
log.ZInfo(context.Background(), "start msgDestruct cron task", "cron config", config.Config.MsgDestructTime) log.ZInfo(context.Background(), "start msgDestruct cron task", "cron config", config.Config.MsgDestructTime)

@ -6,6 +6,10 @@ import (
"math" "math"
"time" "time"
"github.com/redis/go-redis/v9"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
@ -20,9 +24,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"github.com/redis/go-redis/v9"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
) )
type MsgTool struct { type MsgTool struct {
@ -33,8 +34,13 @@ type MsgTool struct {
msgNotificationSender *notification.MsgNotificationSender msgNotificationSender *notification.MsgNotificationSender
} }
func NewMsgTool(msgDatabase controller.CommonMsgDatabase, userDatabase controller.UserDatabase, func NewMsgTool(
groupDatabase controller.GroupDatabase, conversationDatabase controller.ConversationDatabase, msgNotificationSender *notification.MsgNotificationSender) *MsgTool { msgDatabase controller.CommonMsgDatabase,
userDatabase controller.UserDatabase,
groupDatabase controller.GroupDatabase,
conversationDatabase controller.ConversationDatabase,
msgNotificationSender *notification.MsgNotificationSender,
) *MsgTool {
return &MsgTool{ return &MsgTool{
msgDatabase: msgDatabase, msgDatabase: msgDatabase,
userDatabase: userDatabase, userDatabase: userDatabase,
@ -57,18 +63,35 @@ func InitMsgTool() (*MsgTool, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
discov, err := zookeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema, discov, err := zookeeper.NewClient(
zookeeper.WithFreq(time.Hour), zookeeper.WithRoundRobin(), zookeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username, config.Config.Zookeeper.ZkAddr,
config.Config.Zookeeper.Password), zookeeper.WithTimeout(10), zookeeper.WithLogger(log.NewZkLogger())) config.Config.Zookeeper.Schema,
zookeeper.WithFreq(
time.Hour,
),
zookeeper.WithRoundRobin(),
zookeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username,
config.Config.Zookeeper.Password),
zookeeper.WithTimeout(10),
zookeeper.WithLogger(log.NewZkLogger()),
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
discov.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials())) discov.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()))
userDB := relation.NewUserGorm(db) userDB := relation.NewUserGorm(db)
msgDatabase := controller.InitCommonMsgDatabase(rdb, mongo.GetDatabase()) msgDatabase := controller.InitCommonMsgDatabase(rdb, mongo.GetDatabase(), db)
userDatabase := controller.NewUserDatabase(userDB, cache.NewUserCacheRedis(rdb, relation.NewUserGorm(db), cache.GetDefaultOpt()), tx.NewGorm(db)) userDatabase := controller.NewUserDatabase(
userDB,
cache.NewUserCacheRedis(rdb, relation.NewUserGorm(db), cache.GetDefaultOpt()),
tx.NewGorm(db),
)
groupDatabase := controller.InitGroupDatabase(db, rdb, mongo.GetDatabase()) groupDatabase := controller.InitGroupDatabase(db, rdb, mongo.GetDatabase())
conversationDatabase := controller.NewConversationDatabase(relation.NewConversationGorm(db), cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), relation.NewConversationGorm(db)), tx.NewGorm(db)) conversationDatabase := controller.NewConversationDatabase(
relation.NewConversationGorm(db),
cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), relation.NewConversationGorm(db)),
tx.NewGorm(db),
)
msgRpcClient := rpcclient.NewMessageRpcClient(discov) msgRpcClient := rpcclient.NewMessageRpcClient(discov)
msgNotificationSender := notification.NewMsgNotificationSender(rpcclient.WithRpcClient(&msgRpcClient)) msgNotificationSender := notification.NewMsgNotificationSender(rpcclient.WithRpcClient(&msgRpcClient))
msgTool := NewMsgTool(msgDatabase, userDatabase, groupDatabase, conversationDatabase, msgNotificationSender) msgTool := NewMsgTool(msgDatabase, userDatabase, groupDatabase, conversationDatabase, msgNotificationSender)
@ -93,7 +116,15 @@ func (c *MsgTool) AllConversationClearMsgAndFixSeq() {
func (c *MsgTool) ClearConversationsMsg(ctx context.Context, conversationIDs []string) { func (c *MsgTool) ClearConversationsMsg(ctx context.Context, conversationIDs []string) {
for _, conversationID := range conversationIDs { for _, conversationID := range conversationIDs {
if err := c.msgDatabase.DeleteConversationMsgsAndSetMinSeq(ctx, conversationID, int64(config.Config.RetainChatRecords*24*60*60)); err != nil { if err := c.msgDatabase.DeleteConversationMsgsAndSetMinSeq(ctx, conversationID, int64(config.Config.RetainChatRecords*24*60*60)); err != nil {
log.ZError(ctx, "DeleteUserSuperGroupMsgsAndSetMinSeq failed", err, "conversationID", conversationID, "DBRetainChatRecords", config.Config.RetainChatRecords) log.ZError(
ctx,
"DeleteUserSuperGroupMsgsAndSetMinSeq failed",
err,
"conversationID",
conversationID,
"DBRetainChatRecords",
config.Config.RetainChatRecords,
)
} }
if err := c.checkMaxSeq(ctx, conversationID); err != nil { if err := c.checkMaxSeq(ctx, conversationID); err != nil {
log.ZError(ctx, "fixSeq failed", err, "conversationID", conversationID) log.ZError(ctx, "fixSeq failed", err, "conversationID", conversationID)
@ -107,7 +138,19 @@ func (c *MsgTool) checkMaxSeqWithMongo(ctx context.Context, conversationID strin
return err return err
} }
if math.Abs(float64(maxSeqMongo-maxSeqCache)) > 10 { if math.Abs(float64(maxSeqMongo-maxSeqCache)) > 10 {
log.ZError(ctx, "cache max seq and mongo max seq is diff > 10", nil, "maxSeqMongo", maxSeqMongo, "minSeqMongo", minSeqMongo, "maxSeqCache", maxSeqCache, "conversationID", conversationID) log.ZError(
ctx,
"cache max seq and mongo max seq is diff > 10",
nil,
"maxSeqMongo",
maxSeqMongo,
"minSeqMongo",
minSeqMongo,
"maxSeqCache",
maxSeqCache,
"conversationID",
conversationID,
)
} }
return nil return nil
} }

@ -46,17 +46,17 @@ type SetMsgMinSeqResp struct {
type PictureBaseInfo struct { type PictureBaseInfo struct {
UUID string `mapstructure:"uuid"` UUID string `mapstructure:"uuid"`
Type string `mapstructure:"type" ` Type string `mapstructure:"type"`
Size int64 `mapstructure:"size" ` Size int64 `mapstructure:"size"`
Width int32 `mapstructure:"width" ` Width int32 `mapstructure:"width"`
Height int32 `mapstructure:"height"` Height int32 `mapstructure:"height"`
Url string `mapstructure:"url" ` Url string `mapstructure:"url"`
} }
type PictureElem struct { type PictureElem struct {
SourcePath string `mapstructure:"sourcePath"` SourcePath string `mapstructure:"sourcePath"`
SourcePicture PictureBaseInfo `mapstructure:"sourcePicture"` SourcePicture PictureBaseInfo `mapstructure:"sourcePicture"`
BigPicture PictureBaseInfo `mapstructure:"bigPicture" ` BigPicture PictureBaseInfo `mapstructure:"bigPicture"`
SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture"` SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture"`
} }
type SoundElem struct { type SoundElem struct {

@ -3,10 +3,11 @@ package cmd
import ( import (
"errors" "errors"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/startrpc"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"google.golang.org/grpc" "google.golang.org/grpc"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/startrpc"
) )
type RpcCmd struct { type RpcCmd struct {
@ -26,7 +27,10 @@ func (a *RpcCmd) Exec() error {
return a.Execute() return a.Execute()
} }
func (a *RpcCmd) StartSvr(name string, rpcFn func(discov discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error) error { func (a *RpcCmd) StartSvr(
name string,
rpcFn func(discov discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error,
) error {
if a.GetPortFlag() == 0 { if a.GetPortFlag() == 0 {
return errors.New("port is required") return errors.New("port is required")
} }

@ -27,6 +27,11 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
) )
const (
maxRetry = 10 //number of retries
)
// NewRedis Initialize redis connection
func NewRedis() (redis.UniversalClient, error) { func NewRedis() (redis.UniversalClient, error) {
if len(config.Config.Redis.Address) == 0 { if len(config.Config.Redis.Address) == 0 {
return nil, errors.New("redis address is empty") return nil, errors.New("redis address is empty")
@ -39,6 +44,7 @@ func NewRedis() (redis.UniversalClient, error) {
Username: config.Config.Redis.Username, Username: config.Config.Redis.Username,
Password: config.Config.Redis.Password, // no password set Password: config.Config.Redis.Password, // no password set
PoolSize: 50, PoolSize: 50,
MaxRetries: maxRetry,
}) })
} else { } else {
rdb = redis.NewClient(&redis.Options{ rdb = redis.NewClient(&redis.Options{
@ -46,14 +52,17 @@ func NewRedis() (redis.UniversalClient, error) {
Username: config.Config.Redis.Username, Username: config.Config.Redis.Username,
Password: config.Config.Redis.Password, // no password set Password: config.Config.Redis.Password, // no password set
DB: 0, // use default DB DB: 0, // use default DB
PoolSize: 100, // 连接池大小 PoolSize: 100, // connection pool size
MaxRetries: maxRetry,
}) })
} }
var err error = nil
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel() defer cancel()
err := rdb.Ping(ctx).Err() err = rdb.Ping(ctx).Err()
if err != nil { if err != nil {
return nil, fmt.Errorf("redis ping %w", err) return nil, fmt.Errorf("redis ping %w", err)
} }
return rdb, nil return rdb, err
} }

@ -0,0 +1,36 @@
// 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 cache
import (
"fmt"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"testing"
)
//TestNewRedis Test redis connection
func TestNewRedis(t *testing.T) {
err := config.InitConfig("config_folder_path")
if err != nil {
fmt.Println("config load error")
return
}
redis, err := NewRedis()
if err != nil {
fmt.Println(err)
return
}
fmt.Println(redis)
}

@ -14,13 +14,22 @@ import (
type ConversationDatabase interface { type ConversationDatabase interface {
//UpdateUserConversationFiled 更新用户该会话的属性信息 //UpdateUserConversationFiled 更新用户该会话的属性信息
UpdateUsersConversationFiled(ctx context.Context, userIDs []string, conversationID string, args map[string]interface{}) error UpdateUsersConversationFiled(
ctx context.Context,
userIDs []string,
conversationID string,
args map[string]interface{},
) error
//CreateConversation 创建一批新的会话 //CreateConversation 创建一批新的会话
CreateConversation(ctx context.Context, conversations []*relationTb.ConversationModel) error CreateConversation(ctx context.Context, conversations []*relationTb.ConversationModel) error
//SyncPeerUserPrivateConversation 同步对端私聊会话内部保证事务操作 //SyncPeerUserPrivateConversation 同步对端私聊会话内部保证事务操作
SyncPeerUserPrivateConversationTx(ctx context.Context, conversation []*relationTb.ConversationModel) error SyncPeerUserPrivateConversationTx(ctx context.Context, conversation []*relationTb.ConversationModel) error
//FindConversations 根据会话ID获取某个用户的多个会话 //FindConversations 根据会话ID获取某个用户的多个会话
FindConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*relationTb.ConversationModel, error) FindConversations(
ctx context.Context,
ownerUserID string,
conversationIDs []string,
) ([]*relationTb.ConversationModel, error)
//FindRecvMsgNotNotifyUserIDs 获取超级大群开启免打扰的用户ID //FindRecvMsgNotNotifyUserIDs 获取超级大群开启免打扰的用户ID
FindRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error) FindRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error)
//GetUserAllConversation 获取一个用户在服务器上所有的会话 //GetUserAllConversation 获取一个用户在服务器上所有的会话
@ -28,17 +37,29 @@ type ConversationDatabase interface {
//SetUserConversations 设置用户多个会话属性,如果会话不存在则创建,否则更新,内部保证原子性 //SetUserConversations 设置用户多个会话属性,如果会话不存在则创建,否则更新,内部保证原子性
SetUserConversations(ctx context.Context, ownerUserID string, conversations []*relationTb.ConversationModel) error SetUserConversations(ctx context.Context, ownerUserID string, conversations []*relationTb.ConversationModel) error
//SetUsersConversationFiledTx 设置多个用户会话关于某个字段的更新操作,如果会话不存在则创建,否则更新,内部保证事务操作 //SetUsersConversationFiledTx 设置多个用户会话关于某个字段的更新操作,如果会话不存在则创建,否则更新,内部保证事务操作
SetUsersConversationFiledTx(ctx context.Context, userIDs []string, conversation *relationTb.ConversationModel, filedMap map[string]interface{}) error SetUsersConversationFiledTx(
ctx context.Context,
userIDs []string,
conversation *relationTb.ConversationModel,
filedMap map[string]interface{},
) error
CreateGroupChatConversation(ctx context.Context, groupID string, userIDs []string) error CreateGroupChatConversation(ctx context.Context, groupID string, userIDs []string) error
GetConversationIDs(ctx context.Context, userID string) ([]string, error) GetConversationIDs(ctx context.Context, userID string) ([]string, error)
GetUserConversationIDsHash(ctx context.Context, ownerUserID string) (hash uint64, err error) GetUserConversationIDsHash(ctx context.Context, ownerUserID string) (hash uint64, err error)
GetAllConversationIDs(ctx context.Context) ([]string, error) GetAllConversationIDs(ctx context.Context) ([]string, error)
GetUserAllHasReadSeqs(ctx context.Context, ownerUserID string) (map[string]int64, error) GetUserAllHasReadSeqs(ctx context.Context, ownerUserID string) (map[string]int64, error)
GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*relationTb.ConversationModel, error) GetConversationsByConversationID(
ctx context.Context,
conversationIDs []string,
) ([]*relationTb.ConversationModel, error)
GetConversationIDsNeedDestruct(ctx context.Context) ([]*relationTb.ConversationModel, error) GetConversationIDsNeedDestruct(ctx context.Context) ([]*relationTb.ConversationModel, error)
} }
func NewConversationDatabase(conversation relationTb.ConversationModelInterface, cache cache.ConversationCache, tx tx.Tx) ConversationDatabase { func NewConversationDatabase(
conversation relationTb.ConversationModelInterface,
cache cache.ConversationCache,
tx tx.Tx,
) ConversationDatabase {
return &conversationDatabase{ return &conversationDatabase{
conversationDB: conversation, conversationDB: conversation,
cache: cache, cache: cache,
@ -52,7 +73,12 @@ type conversationDatabase struct {
tx tx.Tx tx tx.Tx
} }
func (c *conversationDatabase) SetUsersConversationFiledTx(ctx context.Context, userIDs []string, conversation *relationTb.ConversationModel, filedMap map[string]interface{}) (err error) { func (c *conversationDatabase) SetUsersConversationFiledTx(
ctx context.Context,
userIDs []string,
conversation *relationTb.ConversationModel,
filedMap map[string]interface{},
) (err error) {
cache := c.cache.NewCache() cache := c.cache.NewCache()
if err := c.tx.Transaction(func(tx any) error { if err := c.tx.Transaction(func(tx any) error {
conversationTx := c.conversationDB.NewTx(tx) conversationTx := c.conversationDB.NewTx(tx)
@ -100,7 +126,12 @@ func (c *conversationDatabase) SetUsersConversationFiledTx(ctx context.Context,
return cache.ExecDel(ctx) return cache.ExecDel(ctx)
} }
func (c *conversationDatabase) UpdateUsersConversationFiled(ctx context.Context, userIDs []string, conversationID string, args map[string]interface{}) error { func (c *conversationDatabase) UpdateUsersConversationFiled(
ctx context.Context,
userIDs []string,
conversationID string,
args map[string]interface{},
) error {
_, err := c.conversationDB.UpdateByMap(ctx, userIDs, conversationID, args) _, err := c.conversationDB.UpdateByMap(ctx, userIDs, conversationID, args)
if err != nil { if err != nil {
return err return err
@ -108,7 +139,10 @@ func (c *conversationDatabase) UpdateUsersConversationFiled(ctx context.Context,
return c.cache.DelUsersConversation(conversationID, userIDs...).ExecDel(ctx) return c.cache.DelUsersConversation(conversationID, userIDs...).ExecDel(ctx)
} }
func (c *conversationDatabase) CreateConversation(ctx context.Context, conversations []*relationTb.ConversationModel) error { func (c *conversationDatabase) CreateConversation(
ctx context.Context,
conversations []*relationTb.ConversationModel,
) error {
if err := c.conversationDB.Create(ctx, conversations); err != nil { if err := c.conversationDB.Create(ctx, conversations); err != nil {
return err return err
} }
@ -121,7 +155,10 @@ func (c *conversationDatabase) CreateConversation(ctx context.Context, conversat
return cache.DelConversationIDs(userIDs...).DelUserConversationIDsHash(userIDs...).ExecDel(ctx) return cache.DelConversationIDs(userIDs...).DelUserConversationIDsHash(userIDs...).ExecDel(ctx)
} }
func (c *conversationDatabase) SyncPeerUserPrivateConversationTx(ctx context.Context, conversations []*relationTb.ConversationModel) error { func (c *conversationDatabase) SyncPeerUserPrivateConversationTx(
ctx context.Context,
conversations []*relationTb.ConversationModel,
) error {
cache := c.cache.NewCache() cache := c.cache.NewCache()
if err := c.tx.Transaction(func(tx any) error { if err := c.tx.Transaction(func(tx any) error {
conversationTx := c.conversationDB.NewTx(tx) conversationTx := c.conversationDB.NewTx(tx)
@ -159,19 +196,34 @@ func (c *conversationDatabase) SyncPeerUserPrivateConversationTx(ctx context.Con
return cache.ExecDel(ctx) return cache.ExecDel(ctx)
} }
func (c *conversationDatabase) FindConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*relationTb.ConversationModel, error) { func (c *conversationDatabase) FindConversations(
ctx context.Context,
ownerUserID string,
conversationIDs []string,
) ([]*relationTb.ConversationModel, error) {
return c.cache.GetConversations(ctx, ownerUserID, conversationIDs) return c.cache.GetConversations(ctx, ownerUserID, conversationIDs)
} }
func (c *conversationDatabase) GetConversation(ctx context.Context, ownerUserID string, conversationID string) (*relationTb.ConversationModel, error) { func (c *conversationDatabase) GetConversation(
ctx context.Context,
ownerUserID string,
conversationID string,
) (*relationTb.ConversationModel, error) {
return c.cache.GetConversation(ctx, ownerUserID, conversationID) return c.cache.GetConversation(ctx, ownerUserID, conversationID)
} }
func (c *conversationDatabase) GetUserAllConversation(ctx context.Context, ownerUserID string) ([]*relationTb.ConversationModel, error) { func (c *conversationDatabase) GetUserAllConversation(
ctx context.Context,
ownerUserID string,
) ([]*relationTb.ConversationModel, error) {
return c.cache.GetUserAllConversations(ctx, ownerUserID) return c.cache.GetUserAllConversations(ctx, ownerUserID)
} }
func (c *conversationDatabase) SetUserConversations(ctx context.Context, ownerUserID string, conversations []*relationTb.ConversationModel) error { func (c *conversationDatabase) SetUserConversations(
ctx context.Context,
ownerUserID string,
conversations []*relationTb.ConversationModel,
) error {
cache := c.cache.NewCache() cache := c.cache.NewCache()
if err := c.tx.Transaction(func(tx any) error { if err := c.tx.Transaction(func(tx any) error {
var conversationIDs []string var conversationIDs []string
@ -221,7 +273,11 @@ func (c *conversationDatabase) FindRecvMsgNotNotifyUserIDs(ctx context.Context,
return c.cache.GetSuperGroupRecvMsgNotNotifyUserIDs(ctx, groupID) return c.cache.GetSuperGroupRecvMsgNotNotifyUserIDs(ctx, groupID)
} }
func (c *conversationDatabase) CreateGroupChatConversation(ctx context.Context, groupID string, userIDs []string) error { func (c *conversationDatabase) CreateGroupChatConversation(
ctx context.Context,
groupID string,
userIDs []string,
) error {
cache := c.cache.NewCache() cache := c.cache.NewCache()
conversationID := utils.GetConversationIDBySessionType(constant.SuperGroupChatType, groupID) conversationID := utils.GetConversationIDBySessionType(constant.SuperGroupChatType, groupID)
if err := c.tx.Transaction(func(tx any) error { if err := c.tx.Transaction(func(tx any) error {
@ -261,7 +317,10 @@ func (c *conversationDatabase) GetConversationIDs(ctx context.Context, userID st
return c.cache.GetUserConversationIDs(ctx, userID) return c.cache.GetUserConversationIDs(ctx, userID)
} }
func (c *conversationDatabase) GetUserConversationIDsHash(ctx context.Context, ownerUserID string) (hash uint64, err error) { func (c *conversationDatabase) GetUserConversationIDsHash(
ctx context.Context,
ownerUserID string,
) (hash uint64, err error) {
return c.cache.GetUserConversationIDsHash(ctx, ownerUserID) return c.cache.GetUserConversationIDsHash(ctx, ownerUserID)
} }
@ -269,14 +328,22 @@ func (c *conversationDatabase) GetAllConversationIDs(ctx context.Context) ([]str
return c.conversationDB.GetAllConversationIDs(ctx) return c.conversationDB.GetAllConversationIDs(ctx)
} }
func (c *conversationDatabase) GetUserAllHasReadSeqs(ctx context.Context, ownerUserID string) (map[string]int64, error) { func (c *conversationDatabase) GetUserAllHasReadSeqs(
ctx context.Context,
ownerUserID string,
) (map[string]int64, error) {
return c.cache.GetUserAllHasReadSeqs(ctx, ownerUserID) return c.cache.GetUserAllHasReadSeqs(ctx, ownerUserID)
} }
func (c *conversationDatabase) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*relationTb.ConversationModel, error) { func (c *conversationDatabase) GetConversationsByConversationID(
ctx context.Context,
conversationIDs []string,
) ([]*relationTb.ConversationModel, error) {
return c.conversationDB.GetConversationsByConversationID(ctx, conversationIDs) return c.conversationDB.GetConversationsByConversationID(ctx, conversationIDs)
} }
func (c *conversationDatabase) GetConversationIDsNeedDestruct(ctx context.Context) ([]*relationTb.ConversationModel, error) { func (c *conversationDatabase) GetConversationIDsNeedDestruct(
ctx context.Context,
) ([]*relationTb.ConversationModel, error) {
return c.conversationDB.GetConversationIDsNeedDestruct(ctx) return c.conversationDB.GetConversationIDsNeedDestruct(ctx)
} }

@ -573,6 +573,10 @@ func (g *groupDatabase) CountTotal(ctx context.Context, before *time.Time) (coun
return g.groupDB.CountTotal(ctx, before) return g.groupDB.CountTotal(ctx, before)
} }
func (g *groupDatabase) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) { func (g *groupDatabase) CountRangeEverydayTotal(
ctx context.Context,
start time.Time,
end time.Time,
) (map[string]int64, error) {
return g.groupDB.CountRangeEverydayTotal(ctx, start, end) return g.groupDB.CountRangeEverydayTotal(ctx, start, end)
} }

@ -1,6 +1,9 @@
package controller package controller
import ( import (
relation2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
"gorm.io/gorm"
"time" "time"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
@ -18,10 +21,11 @@ import (
"context" "context"
"errors" "errors"
"go.mongodb.org/mongo-driver/mongo"
pbMsg "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg" pbMsg "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"go.mongodb.org/mongo-driver/mongo"
) )
const ( const (
@ -40,16 +44,36 @@ type CommonMsgDatabase interface {
DeleteMessagesFromCache(ctx context.Context, conversationID string, seqs []int64) error DeleteMessagesFromCache(ctx context.Context, conversationID string, seqs []int64) error
DelUserDeleteMsgsList(ctx context.Context, conversationID string, seqs []int64) DelUserDeleteMsgsList(ctx context.Context, conversationID string, seqs []int64)
// incrSeq然后批量插入缓存 // incrSeq然后批量插入缓存
BatchInsertChat2Cache(ctx context.Context, conversationID string, msgs []*sdkws.MsgData) (seq int64, isNewConversation bool, err error) BatchInsertChat2Cache(
ctx context.Context,
conversationID string,
msgs []*sdkws.MsgData,
) (seq int64, isNewConversation bool, err error)
// 通过seqList获取mongo中写扩散消息 // 通过seqList获取mongo中写扩散消息
GetMsgBySeqsRange(ctx context.Context, userID string, conversationID string, begin, end, num, userMaxSeq int64) (minSeq int64, maxSeq int64, seqMsg []*sdkws.MsgData, err error) GetMsgBySeqsRange(
ctx context.Context,
userID string,
conversationID string,
begin, end, num, userMaxSeq int64,
) (minSeq int64, maxSeq int64, seqMsg []*sdkws.MsgData, err error)
// 通过seqList获取大群在 mongo里面的消息 // 通过seqList获取大群在 mongo里面的消息
GetMsgBySeqs(ctx context.Context, userID string, conversationID string, seqs []int64) (minSeq int64, maxSeq int64, seqMsg []*sdkws.MsgData, err error) GetMsgBySeqs(
ctx context.Context,
userID string,
conversationID string,
seqs []int64,
) (minSeq int64, maxSeq int64, seqMsg []*sdkws.MsgData, err error)
// 删除会话消息重置最小seq remainTime为消息保留的时间单位秒,超时消息删除, 传0删除所有消息(此方法不删除redis cache) // 删除会话消息重置最小seq remainTime为消息保留的时间单位秒,超时消息删除, 传0删除所有消息(此方法不删除redis cache)
DeleteConversationMsgsAndSetMinSeq(ctx context.Context, conversationID string, remainTime int64) error DeleteConversationMsgsAndSetMinSeq(ctx context.Context, conversationID string, remainTime int64) error
// 用户标记删除过期消息返回标记删除的seq列表 // 用户标记删除过期消息返回标记删除的seq列表
UserMsgsDestruct(cte context.Context, userID string, conversationID string, destructTime int64, lastMsgDestructTime time.Time) (seqs []int64, err error) UserMsgsDestruct(
cte context.Context,
userID string,
conversationID string,
destructTime int64,
lastMsgDestructTime time.Time,
) (seqs []int64, err error)
// 用户根据seq删除消息 // 用户根据seq删除消息
DeleteUserMsgsBySeqs(ctx context.Context, userID string, conversationID string, seqs []int64) error DeleteUserMsgsBySeqs(ctx context.Context, userID string, conversationID string, seqs []int64) error
@ -75,9 +99,13 @@ type CommonMsgDatabase interface {
UserSetHasReadSeqs(ctx context.Context, userID string, hasReadSeqs map[string]int64) error UserSetHasReadSeqs(ctx context.Context, userID string, hasReadSeqs map[string]int64) error
GetMongoMaxAndMinSeq(ctx context.Context, conversationID string) (minSeqMongo, maxSeqMongo int64, err error) GetMongoMaxAndMinSeq(ctx context.Context, conversationID string) (minSeqMongo, maxSeqMongo int64, err error)
GetConversationMinMaxSeqInMongoAndCache(ctx context.Context, conversationID string) (minSeqMongo, maxSeqMongo, minSeqCache, maxSeqCache int64, err error) GetConversationMinMaxSeqInMongoAndCache(
ctx context.Context,
conversationID string,
) (minSeqMongo, maxSeqMongo, minSeqCache, maxSeqCache int64, err error)
SetSendMsgStatus(ctx context.Context, id string, status int32) error SetSendMsgStatus(ctx context.Context, id string, status int32) error
GetSendMsgStatus(ctx context.Context, id string) (int32, error) GetSendMsgStatus(ctx context.Context, id string) (int32, error)
SearchMessage(ctx context.Context, req *pbMsg.SearchMessageReq) (msgData []*sdkws.MsgData, err error)
// to mq // to mq
MsgToMQ(ctx context.Context, key string, msg2mq *sdkws.MsgData) error MsgToMQ(ctx context.Context, key string, msg2mq *sdkws.MsgData) error
@ -85,12 +113,28 @@ type CommonMsgDatabase interface {
MsgToPushMQ(ctx context.Context, key, conversarionID string, msg2mq *sdkws.MsgData) (int32, int64, error) MsgToPushMQ(ctx context.Context, key, conversarionID string, msg2mq *sdkws.MsgData) (int32, int64, error)
MsgToMongoMQ(ctx context.Context, key, conversarionID string, msgs []*sdkws.MsgData, lastSeq int64) error MsgToMongoMQ(ctx context.Context, key, conversarionID string, msgs []*sdkws.MsgData, lastSeq int64) error
RangeUserSendCount(ctx context.Context, start time.Time, end time.Time, group bool, ase bool, pageNumber int32, showNumber int32) (msgCount int64, userCount int64, users []*unRelationTb.UserCount, dateCount map[string]int64, err error) RangeUserSendCount(
RangeGroupSendCount(ctx context.Context, start time.Time, end time.Time, ase bool, pageNumber int32, showNumber int32) (msgCount int64, userCount int64, groups []*unRelationTb.GroupCount, dateCount map[string]int64, err error) ctx context.Context,
start time.Time,
end time.Time,
group bool,
ase bool,
pageNumber int32,
showNumber int32,
) (msgCount int64, userCount int64, users []*unRelationTb.UserCount, dateCount map[string]int64, err error)
RangeGroupSendCount(
ctx context.Context,
start time.Time,
end time.Time,
ase bool,
pageNumber int32,
showNumber int32,
) (msgCount int64, userCount int64, groups []*unRelationTb.GroupCount, dateCount map[string]int64, err error)
} }
func NewCommonMsgDatabase(msgDocModel unRelationTb.MsgDocModelInterface, cacheModel cache.MsgModel) CommonMsgDatabase { func NewCommonMsgDatabase(msgDocModel unRelationTb.MsgDocModelInterface, cacheModel cache.MsgModel, msgMyqModel relation.ChatLogModelInterface) CommonMsgDatabase {
return &commonMsgDatabase{ return &commonMsgDatabase{
msgMyq: msgMyqModel,
msgDocDatabase: msgDocModel, msgDocDatabase: msgDocModel,
cache: cacheModel, cache: cacheModel,
producer: kafka.NewKafkaProducer(config.Config.Kafka.Addr, config.Config.Kafka.LatestMsgToRedis.Topic), producer: kafka.NewKafkaProducer(config.Config.Kafka.Addr, config.Config.Kafka.LatestMsgToRedis.Topic),
@ -99,16 +143,18 @@ func NewCommonMsgDatabase(msgDocModel unRelationTb.MsgDocModelInterface, cacheMo
} }
} }
func InitCommonMsgDatabase(rdb redis.UniversalClient, database *mongo.Database) CommonMsgDatabase { func InitCommonMsgDatabase(rdb redis.UniversalClient, database *mongo.Database, dbGrom *gorm.DB) CommonMsgDatabase {
cacheModel := cache.NewMsgCacheModel(rdb) cacheModel := cache.NewMsgCacheModel(rdb)
msgDocModel := unrelation.NewMsgMongoDriver(database) msgDocModel := unrelation.NewMsgMongoDriver(database)
CommonMsgDatabase := NewCommonMsgDatabase(msgDocModel, cacheModel) msgMyqModel := relation2.NewChatLogGorm(dbGrom)
CommonMsgDatabase := NewCommonMsgDatabase(msgDocModel, cacheModel, msgMyqModel)
return CommonMsgDatabase return CommonMsgDatabase
} }
type commonMsgDatabase struct { type commonMsgDatabase struct {
msgDocDatabase unRelationTb.MsgDocModelInterface msgDocDatabase unRelationTb.MsgDocModelInterface
msg unRelationTb.MsgDocModel msg unRelationTb.MsgDocModel
msgMyq relation.ChatLogModelInterface
cache cache.MsgModel cache cache.MsgModel
producer *kafka.Producer producer *kafka.Producer
producerToMongo *kafka.Producer producerToMongo *kafka.Producer
@ -121,16 +167,32 @@ func (db *commonMsgDatabase) MsgToMQ(ctx context.Context, key string, msg2mq *sd
return err return err
} }
func (db *commonMsgDatabase) MsgToModifyMQ(ctx context.Context, key, conversationID string, messages []*sdkws.MsgData) error { func (db *commonMsgDatabase) MsgToModifyMQ(
ctx context.Context,
key, conversationID string,
messages []*sdkws.MsgData,
) error {
if len(messages) > 0 { if len(messages) > 0 {
_, _, err := db.producerToModify.SendMessage(ctx, key, &pbMsg.MsgDataToModifyByMQ{ConversationID: conversationID, Messages: messages}) _, _, err := db.producerToModify.SendMessage(
ctx,
key,
&pbMsg.MsgDataToModifyByMQ{ConversationID: conversationID, Messages: messages},
)
return err return err
} }
return nil return nil
} }
func (db *commonMsgDatabase) MsgToPushMQ(ctx context.Context, key, conversationID string, msg2mq *sdkws.MsgData) (int32, int64, error) { func (db *commonMsgDatabase) MsgToPushMQ(
partition, offset, err := db.producerToPush.SendMessage(ctx, key, &pbMsg.PushMsgDataToMQ{MsgData: msg2mq, ConversationID: conversationID}) ctx context.Context,
key, conversationID string,
msg2mq *sdkws.MsgData,
) (int32, int64, error) {
partition, offset, err := db.producerToPush.SendMessage(
ctx,
key,
&pbMsg.PushMsgDataToMQ{MsgData: msg2mq, ConversationID: conversationID},
)
if err != nil { if err != nil {
log.ZError(ctx, "MsgToPushMQ", err, "key", key, "msg2mq", msg2mq) log.ZError(ctx, "MsgToPushMQ", err, "key", key, "msg2mq", msg2mq)
return 0, 0, err return 0, 0, err
@ -138,15 +200,30 @@ func (db *commonMsgDatabase) MsgToPushMQ(ctx context.Context, key, conversationI
return partition, offset, nil return partition, offset, nil
} }
func (db *commonMsgDatabase) MsgToMongoMQ(ctx context.Context, key, conversationID string, messages []*sdkws.MsgData, lastSeq int64) error { func (db *commonMsgDatabase) MsgToMongoMQ(
ctx context.Context,
key, conversationID string,
messages []*sdkws.MsgData,
lastSeq int64,
) error {
if len(messages) > 0 { if len(messages) > 0 {
_, _, err := db.producerToMongo.SendMessage(ctx, key, &pbMsg.MsgDataToMongoByMQ{LastSeq: lastSeq, ConversationID: conversationID, MsgData: messages}) _, _, err := db.producerToMongo.SendMessage(
ctx,
key,
&pbMsg.MsgDataToMongoByMQ{LastSeq: lastSeq, ConversationID: conversationID, MsgData: messages},
)
return err return err
} }
return nil return nil
} }
func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationID string, fields []any, key int8, firstSeq int64) error { func (db *commonMsgDatabase) BatchInsertBlock(
ctx context.Context,
conversationID string,
fields []any,
key int8,
firstSeq int64,
) error {
if len(fields) == 0 { if len(fields) == 0 {
return nil return nil
} }
@ -247,7 +324,12 @@ func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationI
return nil return nil
} }
func (db *commonMsgDatabase) BatchInsertChat2DB(ctx context.Context, conversationID string, msgList []*sdkws.MsgData, currentMaxSeq int64) error { func (db *commonMsgDatabase) BatchInsertChat2DB(
ctx context.Context,
conversationID string,
msgList []*sdkws.MsgData,
currentMaxSeq int64,
) error {
if len(msgList) == 0 { if len(msgList) == 0 {
return errs.ErrArgs.Wrap("msgList is empty") return errs.ErrArgs.Wrap("msgList is empty")
} }
@ -293,11 +375,21 @@ func (db *commonMsgDatabase) BatchInsertChat2DB(ctx context.Context, conversatio
return db.BatchInsertBlock(ctx, conversationID, msgs, updateKeyMsg, msgList[0].Seq) return db.BatchInsertBlock(ctx, conversationID, msgs, updateKeyMsg, msgList[0].Seq)
} }
func (db *commonMsgDatabase) RevokeMsg(ctx context.Context, conversationID string, seq int64, revoke *unRelationTb.RevokeModel) error { func (db *commonMsgDatabase) RevokeMsg(
ctx context.Context,
conversationID string,
seq int64,
revoke *unRelationTb.RevokeModel,
) error {
return db.BatchInsertBlock(ctx, conversationID, []any{revoke}, updateKeyRevoke, seq) return db.BatchInsertBlock(ctx, conversationID, []any{revoke}, updateKeyRevoke, seq)
} }
func (db *commonMsgDatabase) MarkSingleChatMsgsAsRead(ctx context.Context, userID string, conversationID string, totalSeqs []int64) error { func (db *commonMsgDatabase) MarkSingleChatMsgsAsRead(
ctx context.Context,
userID string,
conversationID string,
totalSeqs []int64,
) error {
for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, totalSeqs) { for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, totalSeqs) {
var indexes []int64 var indexes []int64
for _, seq := range seqs { for _, seq := range seqs {
@ -320,7 +412,11 @@ func (db *commonMsgDatabase) DelUserDeleteMsgsList(ctx context.Context, conversa
db.cache.DelUserDeleteMsgsList(ctx, conversationID, seqs) db.cache.DelUserDeleteMsgsList(ctx, conversationID, seqs)
} }
func (db *commonMsgDatabase) BatchInsertChat2Cache(ctx context.Context, conversationID string, msgs []*sdkws.MsgData) (seq int64, isNew bool, err error) { func (db *commonMsgDatabase) BatchInsertChat2Cache(
ctx context.Context,
conversationID string,
msgs []*sdkws.MsgData,
) (seq int64, isNew bool, err error) {
currentMaxSeq, err := db.cache.GetMaxSeq(ctx, conversationID) currentMaxSeq, err := db.cache.GetMaxSeq(ctx, conversationID)
if err != nil && errs.Unwrap(err) != redis.Nil { if err != nil && errs.Unwrap(err) != redis.Nil {
prome.Inc(prome.SeqGetFailedCounter) prome.Inc(prome.SeqGetFailedCounter)
@ -367,7 +463,11 @@ func (db *commonMsgDatabase) BatchInsertChat2Cache(ctx context.Context, conversa
return lastMaxSeq, isNew, utils.Wrap(err, "") return lastMaxSeq, isNew, utils.Wrap(err, "")
} }
func (db *commonMsgDatabase) getMsgBySeqs(ctx context.Context, userID, conversationID string, seqs []int64) (totalMsgs []*sdkws.MsgData, err error) { func (db *commonMsgDatabase) getMsgBySeqs(
ctx context.Context,
userID, conversationID string,
seqs []int64,
) (totalMsgs []*sdkws.MsgData, err error) {
for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, seqs) { for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, seqs) {
//log.ZDebug(ctx, "getMsgBySeqs", "docID", docID, "seqs", seqs) //log.ZDebug(ctx, "getMsgBySeqs", "docID", docID, "seqs", seqs)
msgs, err := db.findMsgInfoBySeq(ctx, userID, docID, seqs) msgs, err := db.findMsgInfoBySeq(ctx, userID, docID, seqs)
@ -381,7 +481,11 @@ func (db *commonMsgDatabase) getMsgBySeqs(ctx context.Context, userID, conversat
return totalMsgs, nil return totalMsgs, nil
} }
func (db *commonMsgDatabase) findMsgInfoBySeq(ctx context.Context, userID, docID string, seqs []int64) (totalMsgs []*unRelationTb.MsgInfoModel, err error) { func (db *commonMsgDatabase) findMsgInfoBySeq(
ctx context.Context,
userID, docID string,
seqs []int64,
) (totalMsgs []*unRelationTb.MsgInfoModel, err error) {
msgs, err := db.msgDocDatabase.GetMsgBySeqIndexIn1Doc(ctx, userID, docID, seqs) msgs, err := db.msgDocDatabase.GetMsgBySeqIndexIn1Doc(ctx, userID, docID, seqs)
for _, msg := range msgs { for _, msg := range msgs {
if msg.IsRead { if msg.IsRead {
@ -391,8 +495,25 @@ func (db *commonMsgDatabase) findMsgInfoBySeq(ctx context.Context, userID, docID
return msgs, err return msgs, err
} }
func (db *commonMsgDatabase) getMsgBySeqsRange(ctx context.Context, userID string, conversationID string, allSeqs []int64, begin, end int64) (seqMsgs []*sdkws.MsgData, err error) { func (db *commonMsgDatabase) getMsgBySeqsRange(
log.ZDebug(ctx, "getMsgBySeqsRange", "conversationID", conversationID, "allSeqs", allSeqs, "begin", begin, "end", end) ctx context.Context,
userID string,
conversationID string,
allSeqs []int64,
begin, end int64,
) (seqMsgs []*sdkws.MsgData, err error) {
log.ZDebug(
ctx,
"getMsgBySeqsRange",
"conversationID",
conversationID,
"allSeqs",
allSeqs,
"begin",
begin,
"end",
end,
)
for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, allSeqs) { for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, allSeqs) {
log.ZDebug(ctx, "getMsgBySeqsRange", "docID", docID, "seqs", seqs) log.ZDebug(ctx, "getMsgBySeqsRange", "docID", docID, "seqs", seqs)
msgs, err := db.findMsgInfoBySeq(ctx, userID, docID, seqs) msgs, err := db.findMsgInfoBySeq(ctx, userID, docID, seqs)
@ -409,7 +530,12 @@ func (db *commonMsgDatabase) getMsgBySeqsRange(ctx context.Context, userID strin
return seqMsgs, nil return seqMsgs, nil
} }
func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID string, conversationID string, begin, end, num, userMaxSeq int64) (int64, int64, []*sdkws.MsgData, error) { func (db *commonMsgDatabase) GetMsgBySeqsRange(
ctx context.Context,
userID string,
conversationID string,
begin, end, num, userMaxSeq int64,
) (int64, int64, []*sdkws.MsgData, error) {
userMinSeq, err := db.cache.GetConversationUserMinSeq(ctx, conversationID, userID) userMinSeq, err := db.cache.GetConversationUserMinSeq(ctx, conversationID, userID)
if err != nil && errs.Unwrap(err) != redis.Nil { if err != nil && errs.Unwrap(err) != redis.Nil {
return 0, 0, nil, err return 0, 0, nil, err
@ -429,7 +555,18 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
if err != nil && errs.Unwrap(err) != redis.Nil { if err != nil && errs.Unwrap(err) != redis.Nil {
return 0, 0, nil, err return 0, 0, nil, err
} }
log.ZDebug(ctx, "GetMsgBySeqsRange", "userMinSeq", userMinSeq, "conMinSeq", minSeq, "conMaxSeq", maxSeq, "userMaxSeq", userMaxSeq) log.ZDebug(
ctx,
"GetMsgBySeqsRange",
"userMinSeq",
userMinSeq,
"conMinSeq",
minSeq,
"conMaxSeq",
maxSeq,
"userMaxSeq",
userMaxSeq,
)
if userMaxSeq != 0 { if userMaxSeq != 0 {
if userMaxSeq < maxSeq { if userMaxSeq < maxSeq {
maxSeq = userMaxSeq maxSeq = userMaxSeq
@ -479,7 +616,18 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
cacheDelNum += 1 cacheDelNum += 1
} }
} }
log.ZDebug(ctx, "get delSeqs from redis", "delSeqs", delSeqs, "userID", userID, "conversationID", conversationID, "cacheDelNum", cacheDelNum) log.ZDebug(
ctx,
"get delSeqs from redis",
"delSeqs",
delSeqs,
"userID",
userID,
"conversationID",
conversationID,
"cacheDelNum",
cacheDelNum,
)
var reGetSeqsCache []int64 var reGetSeqsCache []int64
for i := 1; i <= cacheDelNum; { for i := 1; i <= cacheDelNum; {
newSeq := newBegin - int64(i) newSeq := newBegin - int64(i)
@ -499,7 +647,15 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
if err != nil { if err != nil {
if err != redis.Nil { if err != redis.Nil {
prome.Add(prome.MsgPullFromRedisFailedCounter, len(failedSeqs2)) prome.Add(prome.MsgPullFromRedisFailedCounter, len(failedSeqs2))
log.ZError(ctx, "get message from redis exception", err, "conversationID", conversationID, "seqs", reGetSeqsCache) log.ZError(
ctx,
"get message from redis exception",
err,
"conversationID",
conversationID,
"seqs",
reGetSeqsCache,
)
} }
} }
failedSeqs = append(failedSeqs, failedSeqs2...) failedSeqs = append(failedSeqs, failedSeqs2...)
@ -525,7 +681,12 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
return minSeq, maxSeq, successMsgs, nil return minSeq, maxSeq, successMsgs, nil
} }
func (db *commonMsgDatabase) GetMsgBySeqs(ctx context.Context, userID string, conversationID string, seqs []int64) (int64, int64, []*sdkws.MsgData, error) { func (db *commonMsgDatabase) GetMsgBySeqs(
ctx context.Context,
userID string,
conversationID string,
seqs []int64,
) (int64, int64, []*sdkws.MsgData, error) {
userMinSeq, err := db.cache.GetConversationUserMinSeq(ctx, conversationID, userID) userMinSeq, err := db.cache.GetConversationUserMinSeq(ctx, conversationID, userID)
if err != nil && errs.Unwrap(err) != redis.Nil { if err != nil && errs.Unwrap(err) != redis.Nil {
return 0, 0, nil, err return 0, 0, nil, err
@ -551,10 +712,33 @@ func (db *commonMsgDatabase) GetMsgBySeqs(ctx context.Context, userID string, co
if err != nil { if err != nil {
if err != redis.Nil { if err != redis.Nil {
prome.Add(prome.MsgPullFromRedisFailedCounter, len(failedSeqs)) prome.Add(prome.MsgPullFromRedisFailedCounter, len(failedSeqs))
log.ZError(ctx, "get message from redis exception", err, "failedSeqs", failedSeqs, "conversationID", conversationID) log.ZError(
ctx,
"get message from redis exception",
err,
"failedSeqs",
failedSeqs,
"conversationID",
conversationID,
)
} }
} }
log.ZInfo(ctx, "db.cache.GetMessagesBySeq", "userID", userID, "conversationID", conversationID, "seqs", seqs, "successMsgs", len(successMsgs), "failedSeqs", failedSeqs, "conversationID", conversationID) log.ZInfo(
ctx,
"db.cache.GetMessagesBySeq",
"userID",
userID,
"conversationID",
conversationID,
"seqs",
seqs,
"successMsgs",
len(successMsgs),
"failedSeqs",
failedSeqs,
"conversationID",
conversationID,
)
prome.Add(prome.MsgPullFromRedisSuccessCounter, len(successMsgs)) prome.Add(prome.MsgPullFromRedisSuccessCounter, len(successMsgs))
if len(failedSeqs) > 0 { if len(failedSeqs) > 0 {
mongoMsgs, err := db.getMsgBySeqs(ctx, userID, conversationID, failedSeqs) mongoMsgs, err := db.getMsgBySeqs(ctx, userID, conversationID, failedSeqs)
@ -568,7 +752,11 @@ func (db *commonMsgDatabase) GetMsgBySeqs(ctx context.Context, userID string, co
return minSeq, maxSeq, successMsgs, nil return minSeq, maxSeq, successMsgs, nil
} }
func (db *commonMsgDatabase) DeleteConversationMsgsAndSetMinSeq(ctx context.Context, conversationID string, remainTime int64) error { func (db *commonMsgDatabase) DeleteConversationMsgsAndSetMinSeq(
ctx context.Context,
conversationID string,
remainTime int64,
) error {
var delStruct delMsgRecursionStruct var delStruct delMsgRecursionStruct
var skip int64 var skip int64
minSeq, err := db.deleteMsgRecursion(ctx, conversationID, skip, &delStruct, remainTime) minSeq, err := db.deleteMsgRecursion(ctx, conversationID, skip, &delStruct, remainTime)
@ -588,7 +776,13 @@ func (db *commonMsgDatabase) DeleteConversationMsgsAndSetMinSeq(ctx context.Cont
return db.cache.SetMinSeq(ctx, conversationID, minSeq) return db.cache.SetMinSeq(ctx, conversationID, minSeq)
} }
func (db *commonMsgDatabase) UserMsgsDestruct(ctx context.Context, userID string, conversationID string, destructTime int64, lastMsgDestructTime time.Time) (seqs []int64, err error) { func (db *commonMsgDatabase) UserMsgsDestruct(
ctx context.Context,
userID string,
conversationID string,
destructTime int64,
lastMsgDestructTime time.Time,
) (seqs []int64, err error) {
var index int64 var index int64
for { for {
// from oldest 2 newest // from oldest 2 newest
@ -596,7 +790,16 @@ func (db *commonMsgDatabase) UserMsgsDestruct(ctx context.Context, userID string
if err != nil || msgDocModel.DocID == "" { if err != nil || msgDocModel.DocID == "" {
if err != nil { if err != nil {
if err == unrelation.ErrMsgListNotExist { if err == unrelation.ErrMsgListNotExist {
log.ZDebug(ctx, "deleteMsgRecursion finished", "conversationID", conversationID, "userID", userID, "index", index) log.ZDebug(
ctx,
"deleteMsgRecursion finished",
"conversationID",
conversationID,
"userID",
userID,
"index",
index,
)
} else { } else {
log.ZError(ctx, "deleteMsgRecursion GetUserMsgListByIndex failed", err, "conversationID", conversationID, "index", index) log.ZError(ctx, "deleteMsgRecursion GetUserMsgListByIndex failed", err, "conversationID", conversationID, "index", index)
} }
@ -645,13 +848,26 @@ func (d *delMsgRecursionStruct) getSetMinSeq() int64 {
// seq 70 // seq 70
// set minSeq 21 // set minSeq 21
// recursion 删除list并且返回设置的最小seq // recursion 删除list并且返回设置的最小seq
func (db *commonMsgDatabase) deleteMsgRecursion(ctx context.Context, conversationID string, index int64, delStruct *delMsgRecursionStruct, remainTime int64) (int64, error) { func (db *commonMsgDatabase) deleteMsgRecursion(
ctx context.Context,
conversationID string,
index int64,
delStruct *delMsgRecursionStruct,
remainTime int64,
) (int64, error) {
// find from oldest list // find from oldest list
msgDocModel, err := db.msgDocDatabase.GetMsgDocModelByIndex(ctx, conversationID, index, 1) msgDocModel, err := db.msgDocDatabase.GetMsgDocModelByIndex(ctx, conversationID, index, 1)
if err != nil || msgDocModel.DocID == "" { if err != nil || msgDocModel.DocID == "" {
if err != nil { if err != nil {
if err == unrelation.ErrMsgListNotExist { if err == unrelation.ErrMsgListNotExist {
log.ZDebug(ctx, "deleteMsgRecursion ErrMsgListNotExist", "conversationID", conversationID, "index:", index) log.ZDebug(
ctx,
"deleteMsgRecursion ErrMsgListNotExist",
"conversationID",
conversationID,
"index:",
index,
)
} else { } else {
log.ZError(ctx, "deleteMsgRecursion GetUserMsgListByIndex failed", err, "conversationID", conversationID, "index", index) log.ZError(ctx, "deleteMsgRecursion GetUserMsgListByIndex failed", err, "conversationID", conversationID, "index", index)
} }
@ -663,11 +879,23 @@ func (db *commonMsgDatabase) deleteMsgRecursion(ctx context.Context, conversatio
} }
return delStruct.getSetMinSeq() + 1, nil return delStruct.getSetMinSeq() + 1, nil
} }
log.ZDebug(ctx, "doc info", "conversationID", conversationID, "index", index, "docID", msgDocModel.DocID, "len", len(msgDocModel.Msg)) log.ZDebug(
ctx,
"doc info",
"conversationID",
conversationID,
"index",
index,
"docID",
msgDocModel.DocID,
"len",
len(msgDocModel.Msg),
)
if int64(len(msgDocModel.Msg)) > db.msg.GetSingleGocMsgNum() { if int64(len(msgDocModel.Msg)) > db.msg.GetSingleGocMsgNum() {
log.ZWarn(ctx, "msgs too large", nil, "lenth", len(msgDocModel.Msg), "docID:", msgDocModel.DocID) log.ZWarn(ctx, "msgs too large", nil, "lenth", len(msgDocModel.Msg), "docID:", msgDocModel.DocID)
} }
if msgDocModel.IsFull() && msgDocModel.Msg[len(msgDocModel.Msg)-1].Msg.SendTime+(remainTime*1000) < utils.GetCurrentTimestampByMill() { if msgDocModel.IsFull() &&
msgDocModel.Msg[len(msgDocModel.Msg)-1].Msg.SendTime+(remainTime*1000) < utils.GetCurrentTimestampByMill() {
log.ZDebug(ctx, "doc is full and all msg is expired", "docID", msgDocModel.DocID) log.ZDebug(ctx, "doc is full and all msg is expired", "docID", msgDocModel.DocID)
delStruct.delDocIDs = append(delStruct.delDocIDs, msgDocModel.DocID) delStruct.delDocIDs = append(delStruct.delDocIDs, msgDocModel.DocID)
delStruct.minSeq = msgDocModel.Msg[len(msgDocModel.Msg)-1].Msg.Seq delStruct.minSeq = msgDocModel.Msg[len(msgDocModel.Msg)-1].Msg.Seq
@ -704,7 +932,11 @@ func (db *commonMsgDatabase) deleteMsgRecursion(ctx context.Context, conversatio
return seq, err return seq, err
} }
func (db *commonMsgDatabase) DeleteMsgsPhysicalBySeqs(ctx context.Context, conversationID string, allSeqs []int64) error { func (db *commonMsgDatabase) DeleteMsgsPhysicalBySeqs(
ctx context.Context,
conversationID string,
allSeqs []int64,
) error {
if err := db.cache.DeleteMessages(ctx, conversationID, allSeqs); err != nil { if err := db.cache.DeleteMessages(ctx, conversationID, allSeqs); err != nil {
return err return err
} }
@ -720,7 +952,12 @@ func (db *commonMsgDatabase) DeleteMsgsPhysicalBySeqs(ctx context.Context, conve
return nil return nil
} }
func (db *commonMsgDatabase) DeleteUserMsgsBySeqs(ctx context.Context, userID string, conversationID string, seqs []int64) error { func (db *commonMsgDatabase) DeleteUserMsgsBySeqs(
ctx context.Context,
userID string,
conversationID string,
seqs []int64,
) error {
cachedMsgs, _, err := db.cache.GetMessagesBySeq(ctx, conversationID, seqs) cachedMsgs, _, err := db.cache.GetMessagesBySeq(ctx, conversationID, seqs)
if err != nil && errs.Unwrap(err) != redis.Nil { if err != nil && errs.Unwrap(err) != redis.Nil {
log.ZWarn(ctx, "DeleteUserMsgsBySeqs", err, "conversationID", conversationID, "seqs", seqs) log.ZWarn(ctx, "DeleteUserMsgsBySeqs", err, "conversationID", conversationID, "seqs", seqs)
@ -789,31 +1026,70 @@ func (db *commonMsgDatabase) GetMinSeqs(ctx context.Context, conversationIDs []s
func (db *commonMsgDatabase) GetMinSeq(ctx context.Context, conversationID string) (int64, error) { func (db *commonMsgDatabase) GetMinSeq(ctx context.Context, conversationID string) (int64, error) {
return db.cache.GetMinSeq(ctx, conversationID) return db.cache.GetMinSeq(ctx, conversationID)
} }
func (db *commonMsgDatabase) GetConversationUserMinSeq(ctx context.Context, conversationID string, userID string) (int64, error) {
func (db *commonMsgDatabase) GetConversationUserMinSeq(
ctx context.Context,
conversationID string,
userID string,
) (int64, error) {
return db.cache.GetConversationUserMinSeq(ctx, conversationID, userID) return db.cache.GetConversationUserMinSeq(ctx, conversationID, userID)
} }
func (db *commonMsgDatabase) GetConversationUserMinSeqs(ctx context.Context, conversationID string, userIDs []string) (map[string]int64, error) {
func (db *commonMsgDatabase) GetConversationUserMinSeqs(
ctx context.Context,
conversationID string,
userIDs []string,
) (map[string]int64, error) {
return db.cache.GetConversationUserMinSeqs(ctx, conversationID, userIDs) return db.cache.GetConversationUserMinSeqs(ctx, conversationID, userIDs)
} }
func (db *commonMsgDatabase) SetConversationUserMinSeq(ctx context.Context, conversationID string, userID string, minSeq int64) error {
func (db *commonMsgDatabase) SetConversationUserMinSeq(
ctx context.Context,
conversationID string,
userID string,
minSeq int64,
) error {
return db.cache.SetConversationUserMinSeq(ctx, conversationID, userID, minSeq) return db.cache.SetConversationUserMinSeq(ctx, conversationID, userID, minSeq)
} }
func (db *commonMsgDatabase) SetConversationUserMinSeqs(ctx context.Context, conversationID string, seqs map[string]int64) (err error) {
func (db *commonMsgDatabase) SetConversationUserMinSeqs(
ctx context.Context,
conversationID string,
seqs map[string]int64,
) (err error) {
return db.cache.SetConversationUserMinSeqs(ctx, conversationID, seqs) return db.cache.SetConversationUserMinSeqs(ctx, conversationID, seqs)
} }
func (db *commonMsgDatabase) SetUserConversationsMinSeqs(ctx context.Context, userID string, seqs map[string]int64) error { func (db *commonMsgDatabase) SetUserConversationsMinSeqs(
ctx context.Context,
userID string,
seqs map[string]int64,
) error {
return db.cache.SetUserConversationsMinSeqs(ctx, userID, seqs) return db.cache.SetUserConversationsMinSeqs(ctx, userID, seqs)
} }
func (db *commonMsgDatabase) UserSetHasReadSeqs(ctx context.Context, userID string, hasReadSeqs map[string]int64) error { func (db *commonMsgDatabase) UserSetHasReadSeqs(
ctx context.Context,
userID string,
hasReadSeqs map[string]int64,
) error {
return db.cache.UserSetHasReadSeqs(ctx, userID, hasReadSeqs) return db.cache.UserSetHasReadSeqs(ctx, userID, hasReadSeqs)
} }
func (db *commonMsgDatabase) SetHasReadSeq(ctx context.Context, userID string, conversationID string, hasReadSeq int64) error { func (db *commonMsgDatabase) SetHasReadSeq(
ctx context.Context,
userID string,
conversationID string,
hasReadSeq int64,
) error {
return db.cache.SetHasReadSeq(ctx, userID, conversationID, hasReadSeq) return db.cache.SetHasReadSeq(ctx, userID, conversationID, hasReadSeq)
} }
func (db *commonMsgDatabase) GetHasReadSeqs(ctx context.Context, userID string, conversationIDs []string) (map[string]int64, error) {
func (db *commonMsgDatabase) GetHasReadSeqs(
ctx context.Context,
userID string,
conversationIDs []string,
) (map[string]int64, error) {
return db.cache.GetHasReadSeqs(ctx, userID, conversationIDs) return db.cache.GetHasReadSeqs(ctx, userID, conversationIDs)
} }
@ -829,7 +1105,10 @@ func (db *commonMsgDatabase) GetSendMsgStatus(ctx context.Context, id string) (i
return db.cache.GetSendMsgStatus(ctx, id) return db.cache.GetSendMsgStatus(ctx, id)
} }
func (db *commonMsgDatabase) GetConversationMinMaxSeqInMongoAndCache(ctx context.Context, conversationID string) (minSeqMongo, maxSeqMongo, minSeqCache, maxSeqCache int64, err error) { func (db *commonMsgDatabase) GetConversationMinMaxSeqInMongoAndCache(
ctx context.Context,
conversationID string,
) (minSeqMongo, maxSeqMongo, minSeqCache, maxSeqCache int64, err error) {
minSeqMongo, maxSeqMongo, err = db.GetMinMaxSeqMongo(ctx, conversationID) minSeqMongo, maxSeqMongo, err = db.GetMinMaxSeqMongo(ctx, conversationID)
if err != nil { if err != nil {
return return
@ -845,11 +1124,17 @@ func (db *commonMsgDatabase) GetConversationMinMaxSeqInMongoAndCache(ctx context
return return
} }
func (db *commonMsgDatabase) GetMongoMaxAndMinSeq(ctx context.Context, conversationID string) (minSeqMongo, maxSeqMongo int64, err error) { func (db *commonMsgDatabase) GetMongoMaxAndMinSeq(
ctx context.Context,
conversationID string,
) (minSeqMongo, maxSeqMongo int64, err error) {
return db.GetMinMaxSeqMongo(ctx, conversationID) return db.GetMinMaxSeqMongo(ctx, conversationID)
} }
func (db *commonMsgDatabase) GetMinMaxSeqMongo(ctx context.Context, conversationID string) (minSeqMongo, maxSeqMongo int64, err error) { func (db *commonMsgDatabase) GetMinMaxSeqMongo(
ctx context.Context,
conversationID string,
) (minSeqMongo, maxSeqMongo int64, err error) {
oldestMsgMongo, err := db.msgDocDatabase.GetOldestMsg(ctx, conversationID) oldestMsgMongo, err := db.msgDocDatabase.GetOldestMsg(ctx, conversationID)
if err != nil { if err != nil {
return return
@ -863,10 +1148,37 @@ func (db *commonMsgDatabase) GetMinMaxSeqMongo(ctx context.Context, conversation
return return
} }
func (db *commonMsgDatabase) RangeUserSendCount(ctx context.Context, start time.Time, end time.Time, group bool, ase bool, pageNumber int32, showNumber int32) (msgCount int64, userCount int64, users []*unRelationTb.UserCount, dateCount map[string]int64, err error) { func (db *commonMsgDatabase) RangeUserSendCount(
ctx context.Context,
start time.Time,
end time.Time,
group bool,
ase bool,
pageNumber int32,
showNumber int32,
) (msgCount int64, userCount int64, users []*unRelationTb.UserCount, dateCount map[string]int64, err error) {
return db.msgDocDatabase.RangeUserSendCount(ctx, start, end, group, ase, pageNumber, showNumber) return db.msgDocDatabase.RangeUserSendCount(ctx, start, end, group, ase, pageNumber, showNumber)
} }
func (db *commonMsgDatabase) RangeGroupSendCount(ctx context.Context, start time.Time, end time.Time, ase bool, pageNumber int32, showNumber int32) (msgCount int64, userCount int64, groups []*unRelationTb.GroupCount, dateCount map[string]int64, err error) { func (db *commonMsgDatabase) RangeGroupSendCount(
ctx context.Context,
start time.Time,
end time.Time,
ase bool,
pageNumber int32,
showNumber int32,
) (msgCount int64, userCount int64, groups []*unRelationTb.GroupCount, dateCount map[string]int64, err error) {
return db.msgDocDatabase.RangeGroupSendCount(ctx, start, end, ase, pageNumber, showNumber) return db.msgDocDatabase.RangeGroupSendCount(ctx, start, end, ase, pageNumber, showNumber)
} }
func (db *commonMsgDatabase) SearchMessage(ctx context.Context, req *pbMsg.SearchMessageReq) (msgData []*sdkws.MsgData, err error) {
var totalMsgs []*sdkws.MsgData
msgs, err := db.msgDocDatabase.SearchMessage(ctx, req)
if err != nil {
return nil, err
}
for _, msg := range msgs {
totalMsgs = append(totalMsgs, convert.MsgDB2Pb(msg.Msg))
}
return totalMsgs, nil
}

@ -2,18 +2,25 @@ package controller
import ( import (
"context" "context"
"path/filepath"
"time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/cont" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/cont"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
"path/filepath"
"time"
) )
type S3Database interface { type S3Database interface {
PartLimit() *s3.PartLimit PartLimit() *s3.PartLimit
PartSize(ctx context.Context, size int64) (int64, error) PartSize(ctx context.Context, size int64) (int64, error)
AuthSign(ctx context.Context, uploadID string, partNumbers []int) (*s3.AuthSignResult, error) AuthSign(ctx context.Context, uploadID string, partNumbers []int) (*s3.AuthSignResult, error)
InitiateMultipartUpload(ctx context.Context, hash string, size int64, expire time.Duration, maxParts int) (*cont.InitiateUploadResult, error) InitiateMultipartUpload(
ctx context.Context,
hash string,
size int64,
expire time.Duration,
maxParts int,
) (*cont.InitiateUploadResult, error)
CompleteMultipartUpload(ctx context.Context, uploadID string, parts []string) (*cont.UploadResult, error) CompleteMultipartUpload(ctx context.Context, uploadID string, parts []string) (*cont.UploadResult, error)
AccessURL(ctx context.Context, name string, expire time.Duration) (time.Time, string, error) AccessURL(ctx context.Context, name string, expire time.Duration) (time.Time, string, error)
SetObject(ctx context.Context, info *relation.ObjectModel) error SetObject(ctx context.Context, info *relation.ObjectModel) error
@ -43,11 +50,21 @@ func (s *s3Database) AuthSign(ctx context.Context, uploadID string, partNumbers
return s.s3.AuthSign(ctx, uploadID, partNumbers) return s.s3.AuthSign(ctx, uploadID, partNumbers)
} }
func (s *s3Database) InitiateMultipartUpload(ctx context.Context, hash string, size int64, expire time.Duration, maxParts int) (*cont.InitiateUploadResult, error) { func (s *s3Database) InitiateMultipartUpload(
ctx context.Context,
hash string,
size int64,
expire time.Duration,
maxParts int,
) (*cont.InitiateUploadResult, error) {
return s.s3.InitiateUpload(ctx, hash, size, expire, maxParts) return s.s3.InitiateUpload(ctx, hash, size, expire, maxParts)
} }
func (s *s3Database) CompleteMultipartUpload(ctx context.Context, uploadID string, parts []string) (*cont.UploadResult, error) { func (s *s3Database) CompleteMultipartUpload(
ctx context.Context,
uploadID string,
parts []string,
) (*cont.UploadResult, error) {
return s.s3.CompleteUpload(ctx, uploadID, parts) return s.s3.CompleteUpload(ctx, uploadID, parts)
} }

@ -3,10 +3,11 @@ package relation
import ( import (
"context" "context"
"gorm.io/gorm"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"gorm.io/gorm"
) )
type ConversationGorm struct { type ConversationGorm struct {
@ -29,66 +30,172 @@ func (c *ConversationGorm) Delete(ctx context.Context, groupIDs []string) (err e
return utils.Wrap(c.db(ctx).Where("group_id in (?)", groupIDs).Delete(&relation.ConversationModel{}).Error, "") return utils.Wrap(c.db(ctx).Where("group_id in (?)", groupIDs).Delete(&relation.ConversationModel{}).Error, "")
} }
func (c *ConversationGorm) UpdateByMap(ctx context.Context, userIDList []string, conversationID string, args map[string]interface{}) (rows int64, err error) { func (c *ConversationGorm) UpdateByMap(
ctx context.Context,
userIDList []string,
conversationID string,
args map[string]interface{},
) (rows int64, err error) {
result := c.db(ctx).Where("owner_user_id IN (?) and conversation_id=?", userIDList, conversationID).Updates(args) result := c.db(ctx).Where("owner_user_id IN (?) and conversation_id=?", userIDList, conversationID).Updates(args)
return result.RowsAffected, utils.Wrap(result.Error, "") return result.RowsAffected, utils.Wrap(result.Error, "")
} }
func (c *ConversationGorm) Update(ctx context.Context, conversation *relation.ConversationModel) (err error) { func (c *ConversationGorm) Update(ctx context.Context, conversation *relation.ConversationModel) (err error) {
return utils.Wrap(c.db(ctx).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).Updates(conversation).Error, "") return utils.Wrap(
} c.db(ctx).
Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
func (c *ConversationGorm) Find(ctx context.Context, ownerUserID string, conversationIDs []string) (conversations []*relation.ConversationModel, err error) { Updates(conversation).
err = utils.Wrap(c.db(ctx).Where("owner_user_id=? and conversation_id IN (?)", ownerUserID, conversationIDs).Find(&conversations).Error, "") Error,
"",
)
}
func (c *ConversationGorm) Find(
ctx context.Context,
ownerUserID string,
conversationIDs []string,
) (conversations []*relation.ConversationModel, err error) {
err = utils.Wrap(
c.db(ctx).
Where("owner_user_id=? and conversation_id IN (?)", ownerUserID, conversationIDs).
Find(&conversations).
Error,
"",
)
return conversations, err return conversations, err
} }
func (c *ConversationGorm) Take(ctx context.Context, userID, conversationID string) (conversation *relation.ConversationModel, err error) { func (c *ConversationGorm) Take(
ctx context.Context,
userID, conversationID string,
) (conversation *relation.ConversationModel, err error) {
cc := &relation.ConversationModel{} cc := &relation.ConversationModel{}
return cc, utils.Wrap(c.db(ctx).Where("conversation_id = ? And owner_user_id = ?", conversationID, userID).Take(cc).Error, "") return cc, utils.Wrap(
} c.db(ctx).Where("conversation_id = ? And owner_user_id = ?", conversationID, userID).Take(cc).Error,
"",
func (c *ConversationGorm) FindUserID(ctx context.Context, userIDs []string, conversationIDs []string) (existUserID []string, err error) { )
return existUserID, utils.Wrap(c.db(ctx).Where(" owner_user_id IN (?) and conversation_id in (?)", userIDs, conversationIDs).Pluck("owner_user_id", &existUserID).Error, "") }
}
func (c *ConversationGorm) FindUserID(
func (c *ConversationGorm) FindConversationID(ctx context.Context, userID string, conversationIDList []string) (existConversationID []string, err error) { ctx context.Context,
return existConversationID, utils.Wrap(c.db(ctx).Where(" conversation_id IN (?) and owner_user_id=?", conversationIDList, userID).Pluck("conversation_id", &existConversationID).Error, "") userIDs []string,
} conversationIDs []string,
) (existUserID []string, err error) {
func (c *ConversationGorm) FindUserIDAllConversationID(ctx context.Context, userID string) (conversationIDList []string, err error) { return existUserID, utils.Wrap(
return conversationIDList, utils.Wrap(c.db(ctx).Where("owner_user_id=?", userID).Pluck("conversation_id", &conversationIDList).Error, "") c.db(ctx).
} Where(" owner_user_id IN (?) and conversation_id in (?)", userIDs, conversationIDs).
Pluck("owner_user_id", &existUserID).
func (c *ConversationGorm) FindUserIDAllConversations(ctx context.Context, userID string) (conversations []*relation.ConversationModel, err error) { Error,
"",
)
}
func (c *ConversationGorm) FindConversationID(
ctx context.Context,
userID string,
conversationIDList []string,
) (existConversationID []string, err error) {
return existConversationID, utils.Wrap(
c.db(ctx).
Where(" conversation_id IN (?) and owner_user_id=?", conversationIDList, userID).
Pluck("conversation_id", &existConversationID).
Error,
"",
)
}
func (c *ConversationGorm) FindUserIDAllConversationID(
ctx context.Context,
userID string,
) (conversationIDList []string, err error) {
return conversationIDList, utils.Wrap(
c.db(ctx).Where("owner_user_id=?", userID).Pluck("conversation_id", &conversationIDList).Error,
"",
)
}
func (c *ConversationGorm) FindUserIDAllConversations(
ctx context.Context,
userID string,
) (conversations []*relation.ConversationModel, err error) {
return conversations, utils.Wrap(c.db(ctx).Where("owner_user_id=?", userID).Find(&conversations).Error, "") return conversations, utils.Wrap(c.db(ctx).Where("owner_user_id=?", userID).Find(&conversations).Error, "")
} }
func (c *ConversationGorm) FindRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) (userIDs []string, err error) { func (c *ConversationGorm) FindRecvMsgNotNotifyUserIDs(
return userIDs, utils.Wrap(c.db(ctx).Where("group_id = ? and recv_msg_opt = ?", groupID, constant.ReceiveNotNotifyMessage).Pluck("user_id", &userIDs).Error, "") ctx context.Context,
} groupID string,
) (userIDs []string, err error) {
func (c *ConversationGorm) FindSuperGroupRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) (userIDs []string, err error) { return userIDs, utils.Wrap(
return userIDs, utils.Wrap(c.db(ctx).Where("group_id = ? and recv_msg_opt = ? and conversation_type = ?", groupID, constant.ReceiveNotNotifyMessage, constant.SuperGroupChatType).Pluck("user_id", &userIDs).Error, "") c.db(ctx).
} Where("group_id = ? and recv_msg_opt = ?", groupID, constant.ReceiveNotNotifyMessage).
Pluck("user_id", &userIDs).
func (c *ConversationGorm) GetUserRecvMsgOpt(ctx context.Context, ownerUserID, conversationID string) (opt int, err error) { Error,
"",
)
}
func (c *ConversationGorm) FindSuperGroupRecvMsgNotNotifyUserIDs(
ctx context.Context,
groupID string,
) (userIDs []string, err error) {
return userIDs, utils.Wrap(
c.db(ctx).
Where("group_id = ? and recv_msg_opt = ? and conversation_type = ?", groupID, constant.ReceiveNotNotifyMessage, constant.SuperGroupChatType).
Pluck("user_id", &userIDs).
Error,
"",
)
}
func (c *ConversationGorm) GetUserRecvMsgOpt(
ctx context.Context,
ownerUserID, conversationID string,
) (opt int, err error) {
var conversation relation.ConversationModel var conversation relation.ConversationModel
return int(conversation.RecvMsgOpt), utils.Wrap(c.db(ctx).Where("conversation_id = ? And owner_user_id = ?", conversationID, ownerUserID).Select("recv_msg_opt").Find(&conversation).Error, "") return int(
conversation.RecvMsgOpt,
), utils.Wrap(
c.db(ctx).
Where("conversation_id = ? And owner_user_id = ?", conversationID, ownerUserID).
Select("recv_msg_opt").
Find(&conversation).
Error,
"",
)
} }
func (c *ConversationGorm) GetAllConversationIDs(ctx context.Context) (conversationIDs []string, err error) { func (c *ConversationGorm) GetAllConversationIDs(ctx context.Context) (conversationIDs []string, err error) {
return conversationIDs, utils.Wrap(c.db(ctx).Distinct("conversation_id").Pluck("conversation_id", &conversationIDs).Error, "") return conversationIDs, utils.Wrap(
c.db(ctx).Distinct("conversation_id").Pluck("conversation_id", &conversationIDs).Error,
"",
)
} }
func (c *ConversationGorm) GetUserAllHasReadSeqs(ctx context.Context, ownerUserID string) (hasReadSeqs map[string]int64, err error) { func (c *ConversationGorm) GetUserAllHasReadSeqs(
ctx context.Context,
ownerUserID string,
) (hasReadSeqs map[string]int64, err error) {
return nil, nil return nil, nil
} }
func (c *ConversationGorm) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) (conversations []*relation.ConversationModel, err error) { func (c *ConversationGorm) GetConversationsByConversationID(
return conversations, utils.Wrap(c.db(ctx).Where("conversation_id IN (?)", conversationIDs).Find(&conversations).Error, "") ctx context.Context,
} conversationIDs []string,
) (conversations []*relation.ConversationModel, err error) {
func (c *ConversationGorm) GetConversationIDsNeedDestruct(ctx context.Context) (conversations []*relation.ConversationModel, err error) { return conversations, utils.Wrap(
return conversations, utils.Wrap(c.db(ctx).Where("is_msg_destruct = 1 && UNIX_TIMESTAMP(NOW()) > (msg_destruct_time + UNIX_TIMESTAMP(latest_msg_destruct_time)) && msg_destruct_time != 0").Find(&conversations).Error, "") c.db(ctx).Where("conversation_id IN (?)", conversationIDs).Find(&conversations).Error,
"",
)
}
func (c *ConversationGorm) GetConversationIDsNeedDestruct(
ctx context.Context,
) (conversations []*relation.ConversationModel, err error) {
return conversations, utils.Wrap(
c.db(ctx).
Where("is_msg_destruct = 1 && UNIX_TIMESTAMP(NOW()) > (msg_destruct_time + UNIX_TIMESTAMP(latest_msg_destruct_time)) && msg_destruct_time != 0").
Find(&conversations).
Error,
"",
)
} }

@ -2,12 +2,15 @@ package relation
import ( import (
"context" "context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"time"
"gorm.io/gorm"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/ormutil" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/ormutil"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"gorm.io/gorm"
"time"
) )
var _ relation.GroupModelInterface = (*GroupGorm)(nil) var _ relation.GroupModelInterface = (*GroupGorm)(nil)
@ -33,7 +36,13 @@ func (g *GroupGorm) UpdateMap(ctx context.Context, groupID string, args map[stri
} }
func (g *GroupGorm) UpdateStatus(ctx context.Context, groupID string, status int32) (err error) { func (g *GroupGorm) UpdateStatus(ctx context.Context, groupID string, status int32) (err error) {
return utils.Wrap(g.DB.Where("group_id = ?", groupID).Model(&relation.GroupModel{}).Updates(map[string]any{"status": status}).Error, "") return utils.Wrap(
g.DB.Where("group_id = ?", groupID).
Model(&relation.GroupModel{}).
Updates(map[string]any{"status": status}).
Error,
"",
)
} }
func (g *GroupGorm) Find(ctx context.Context, groupIDs []string) (groups []*relation.GroupModel, err error) { func (g *GroupGorm) Find(ctx context.Context, groupIDs []string) (groups []*relation.GroupModel, err error) {
@ -45,12 +54,21 @@ func (g *GroupGorm) Take(ctx context.Context, groupID string) (group *relation.G
return group, utils.Wrap(g.DB.Where("group_id = ?", groupID).Take(group).Error, "") return group, utils.Wrap(g.DB.Where("group_id = ?", groupID).Take(group).Error, "")
} }
func (g *GroupGorm) Search(ctx context.Context, keyword string, pageNumber, showNumber int32) (total uint32, groups []*relation.GroupModel, err error) { func (g *GroupGorm) Search(
return ormutil.GormSearch[relation.GroupModel](g.DB, []string{"name"}, keyword, pageNumber, showNumber) ctx context.Context,
keyword string,
pageNumber, showNumber int32,
) (total uint32, groups []*relation.GroupModel, err error) {
db := g.DB
db = db.WithContext(ctx).Where("status!=?", constant.GroupStatusDismissed)
return ormutil.GormSearch[relation.GroupModel](db, []string{"name"}, keyword, pageNumber, showNumber)
} }
func (g *GroupGorm) GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error) { func (g *GroupGorm) GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error) {
return groupIDs, utils.Wrap(g.DB.Model(&relation.GroupModel{}).Where("group_type = ? ", groupType).Pluck("group_id", &groupIDs).Error, "") return groupIDs, utils.Wrap(
g.DB.Model(&relation.GroupModel{}).Where("group_type = ? ", groupType).Pluck("group_id", &groupIDs).Error,
"",
)
} }
func (g *GroupGorm) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) { func (g *GroupGorm) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) {
@ -64,12 +82,22 @@ func (g *GroupGorm) CountTotal(ctx context.Context, before *time.Time) (count in
return count, nil return count, nil
} }
func (g *GroupGorm) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) { func (g *GroupGorm) CountRangeEverydayTotal(
ctx context.Context,
start time.Time,
end time.Time,
) (map[string]int64, error) {
var res []struct { var res []struct {
Date time.Time `gorm:"column:date"` Date time.Time `gorm:"column:date"`
Count int64 `gorm:"column:count"` Count int64 `gorm:"column:count"`
} }
err := g.db(ctx).Model(&relation.GroupModel{}).Select("DATE(create_time) AS date, count(1) AS count").Where("create_time >= ? and create_time < ?", start, end).Group("date").Find(&res).Error err := g.db(ctx).
Model(&relation.GroupModel{}).
Select("DATE(create_time) AS date, count(1) AS count").
Where("create_time >= ? and create_time < ?", start, end).
Group("date").
Find(&res).
Error
if err != nil { if err != nil {
return nil, errs.Wrap(err) return nil, errs.Wrap(err)
} }

@ -2,9 +2,11 @@ package relation
import ( import (
"context" "context"
"gorm.io/gorm"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"gorm.io/gorm"
) )
type ObjectInfoGorm struct { type ObjectInfoGorm struct {

@ -6,13 +6,15 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/google/uuid"
"path" "path"
"strings" "strings"
"time" "time"
"github.com/google/uuid"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
) )
func New(impl s3.Interface) *Controller { func New(impl s3.Interface) *Controller {
@ -56,7 +58,13 @@ func (c *Controller) GetHashObject(ctx context.Context, hash string) (*s3.Object
return c.impl.StatObject(ctx, c.HashPath(hash)) return c.impl.StatObject(ctx, c.HashPath(hash))
} }
func (c *Controller) InitiateUpload(ctx context.Context, hash string, size int64, expire time.Duration, maxParts int) (*InitiateUploadResult, error) { func (c *Controller) InitiateUpload(
ctx context.Context,
hash string,
size int64,
expire time.Duration,
maxParts int,
) (*InitiateUploadResult, error) {
defer log.ZDebug(ctx, "return") defer log.ZDebug(ctx, "return")
if size < 0 { if size < 0 {
return nil, errors.New("invalid size") return nil, errors.New("invalid size")
@ -239,6 +247,11 @@ func (c *Controller) IsNotFound(err error) bool {
return c.impl.IsNotFound(err) return c.impl.IsNotFound(err)
} }
func (c *Controller) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) { func (c *Controller) AccessURL(
ctx context.Context,
name string,
expire time.Duration,
opt *s3.AccessURLOption,
) (string, error) {
return c.impl.AccessURL(ctx, name, expire, opt) return c.impl.AccessURL(ctx, name, expire, opt)
} }

@ -2,6 +2,7 @@ package cont
import ( import (
"fmt" "fmt"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
) )

@ -4,14 +4,16 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
"github.com/tencentyun/cos-go-sdk-v5"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/tencentyun/cos-go-sdk-v5"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
) )
const ( const (
@ -70,7 +72,12 @@ func (c *Cos) InitiateMultipartUpload(ctx context.Context, name string) (*s3.Ini
}, nil }, nil
} }
func (c *Cos) CompleteMultipartUpload(ctx context.Context, uploadID string, name string, parts []s3.Part) (*s3.CompleteMultipartUploadResult, error) { func (c *Cos) CompleteMultipartUpload(
ctx context.Context,
uploadID string,
name string,
parts []s3.Part,
) (*s3.CompleteMultipartUploadResult, error) {
opts := &cos.CompleteMultipartUploadOptions{ opts := &cos.CompleteMultipartUploadOptions{
Parts: make([]cos.Object, len(parts)), Parts: make([]cos.Object, len(parts)),
} }
@ -109,7 +116,13 @@ func (c *Cos) PartSize(ctx context.Context, size int64) (int64, error) {
return partSize, nil return partSize, nil
} }
func (c *Cos) AuthSign(ctx context.Context, uploadID string, name string, expire time.Duration, partNumbers []int) (*s3.AuthSignResult, error) { func (c *Cos) AuthSign(
ctx context.Context,
uploadID string,
name string,
expire time.Duration,
partNumbers []int,
) (*s3.AuthSignResult, error) {
result := s3.AuthSignResult{ result := s3.AuthSignResult{
URL: c.client.BaseURL.BucketURL.String() + "/" + cos.EncodeURIComponent(name), URL: c.client.BaseURL.BucketURL.String() + "/" + cos.EncodeURIComponent(name),
Query: url.Values{"uploadId": {uploadID}}, Query: url.Values{"uploadId": {uploadID}},
@ -120,7 +133,13 @@ func (c *Cos) AuthSign(ctx context.Context, uploadID string, name string, expire
if err != nil { if err != nil {
return nil, err return nil, err
} }
cos.AddAuthorizationHeader(c.credential.SecretID, c.credential.SecretKey, c.credential.SessionToken, req, cos.NewAuthTime(expire)) cos.AddAuthorizationHeader(
c.credential.SecretID,
c.credential.SecretKey,
c.credential.SessionToken,
req,
cos.NewAuthTime(expire),
)
result.Header = req.Header result.Header = req.Header
for i, partNumber := range partNumbers { for i, partNumber := range partNumbers {
result.Parts[i] = s3.SignPart{ result.Parts[i] = s3.SignPart{
@ -132,7 +151,15 @@ func (c *Cos) AuthSign(ctx context.Context, uploadID string, name string, expire
} }
func (c *Cos) PresignedPutObject(ctx context.Context, name string, expire time.Duration) (string, error) { func (c *Cos) PresignedPutObject(ctx context.Context, name string, expire time.Duration) (string, error) {
rawURL, err := c.client.Object.GetPresignedURL(ctx, http.MethodPut, name, c.credential.SecretID, c.credential.SecretKey, expire, nil) rawURL, err := c.client.Object.GetPresignedURL(
ctx,
http.MethodPut,
name,
c.credential.SecretID,
c.credential.SecretKey,
expire,
nil,
)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -204,7 +231,13 @@ func (c *Cos) AbortMultipartUpload(ctx context.Context, uploadID string, name st
return err return err
} }
func (c *Cos) ListUploadedParts(ctx context.Context, uploadID string, name string, partNumberMarker int, maxParts int) (*s3.ListUploadedPartsResult, error) { func (c *Cos) ListUploadedParts(
ctx context.Context,
uploadID string,
name string,
partNumberMarker int,
maxParts int,
) (*s3.ListUploadedPartsResult, error) {
result, _, err := c.client.Object.ListParts(ctx, name, uploadID, &cos.ObjectListPartsOptions{ result, _, err := c.client.Object.ListParts(ctx, name, uploadID, &cos.ObjectListPartsOptions{
MaxParts: strconv.Itoa(maxParts), MaxParts: strconv.Itoa(maxParts),
PartNumberMarker: strconv.Itoa(partNumberMarker), PartNumberMarker: strconv.Itoa(partNumberMarker),
@ -231,7 +264,12 @@ func (c *Cos) ListUploadedParts(ctx context.Context, uploadID string, name strin
return res, nil return res, nil
} }
func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) { func (c *Cos) AccessURL(
ctx context.Context,
name string,
expire time.Duration,
opt *s3.AccessURLOption,
) (string, error) {
//reqParams := make(url.Values) //reqParams := make(url.Values)
//if opt != nil { //if opt != nil {
// if opt.ContentType != "" { // if opt.ContentType != "" {
@ -246,7 +284,15 @@ func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration,
} else if expire < time.Second { } else if expire < time.Second {
expire = time.Second expire = time.Second
} }
rawURL, err := c.client.Object.GetPresignedURL(ctx, http.MethodGet, name, c.credential.SecretID, c.credential.SecretKey, expire, nil) rawURL, err := c.client.Object.GetPresignedURL(
ctx,
http.MethodGet,
name,
c.credential.SecretID,
c.credential.SecretKey,
expire,
nil,
)
if err != nil { if err != nil {
return "", err return "", err
} }

@ -4,16 +4,18 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/minio/minio-go/v7/pkg/signer"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/minio/minio-go/v7/pkg/signer"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
) )
const ( const (
@ -79,7 +81,12 @@ func (m *Minio) InitiateMultipartUpload(ctx context.Context, name string) (*s3.I
}, nil }, nil
} }
func (m *Minio) CompleteMultipartUpload(ctx context.Context, uploadID string, name string, parts []s3.Part) (*s3.CompleteMultipartUploadResult, error) { func (m *Minio) CompleteMultipartUpload(
ctx context.Context,
uploadID string,
name string,
parts []s3.Part,
) (*s3.CompleteMultipartUploadResult, error) {
minioParts := make([]minio.CompletePart, len(parts)) minioParts := make([]minio.CompletePart, len(parts))
for i, part := range parts { for i, part := range parts {
minioParts[i] = minio.CompletePart{ minioParts[i] = minio.CompletePart{
@ -116,7 +123,13 @@ func (m *Minio) PartSize(ctx context.Context, size int64) (int64, error) {
return partSize, nil return partSize, nil
} }
func (m *Minio) AuthSign(ctx context.Context, uploadID string, name string, expire time.Duration, partNumbers []int) (*s3.AuthSignResult, error) { func (m *Minio) AuthSign(
ctx context.Context,
uploadID string,
name string,
expire time.Duration,
partNumbers []int,
) (*s3.AuthSignResult, error) {
creds, err := m.opts.Creds.Get() creds, err := m.opts.Creds.Get()
if err != nil { if err != nil {
return nil, err return nil, err
@ -133,7 +146,14 @@ func (m *Minio) AuthSign(ctx context.Context, uploadID string, name string, expi
return nil, err return nil, err
} }
request.Header.Set("X-Amz-Content-Sha256", unsignedPayload) request.Header.Set("X-Amz-Content-Sha256", unsignedPayload)
request = signer.SignV4Trailer(*request, creds.AccessKeyID, creds.SecretAccessKey, creds.SessionToken, "us-east-1", nil) request = signer.SignV4Trailer(
*request,
creds.AccessKeyID,
creds.SecretAccessKey,
creds.SessionToken,
"us-east-1",
nil,
)
result.Parts[i] = s3.SignPart{ result.Parts[i] = s3.SignPart{
PartNumber: partNumber, PartNumber: partNumber,
URL: request.URL.String(), URL: request.URL.String(),
@ -204,7 +224,13 @@ func (m *Minio) AbortMultipartUpload(ctx context.Context, uploadID string, name
return m.core.AbortMultipartUpload(ctx, m.bucket, name, uploadID) return m.core.AbortMultipartUpload(ctx, m.bucket, name, uploadID)
} }
func (m *Minio) ListUploadedParts(ctx context.Context, uploadID string, name string, partNumberMarker int, maxParts int) (*s3.ListUploadedPartsResult, error) { func (m *Minio) ListUploadedParts(
ctx context.Context,
uploadID string,
name string,
partNumberMarker int,
maxParts int,
) (*s3.ListUploadedPartsResult, error) {
result, err := m.core.ListObjectParts(ctx, m.bucket, name, uploadID, partNumberMarker, maxParts) result, err := m.core.ListObjectParts(ctx, m.bucket, name, uploadID, partNumberMarker, maxParts)
if err != nil { if err != nil {
return nil, err return nil, err
@ -227,7 +253,12 @@ func (m *Minio) ListUploadedParts(ctx context.Context, uploadID string, name str
return res, nil return res, nil
} }
func (m *Minio) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) { func (m *Minio) AccessURL(
ctx context.Context,
name string,
expire time.Duration,
opt *s3.AccessURLOption,
) (string, error) {
//reqParams := make(url.Values) //reqParams := make(url.Values)
//if opt != nil { //if opt != nil {
// if opt.ContentType != "" { // if opt.ContentType != "" {

@ -4,14 +4,16 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
) )
const ( const (
@ -73,7 +75,12 @@ func (o *OSS) InitiateMultipartUpload(ctx context.Context, name string) (*s3.Ini
}, nil }, nil
} }
func (o *OSS) CompleteMultipartUpload(ctx context.Context, uploadID string, name string, parts []s3.Part) (*s3.CompleteMultipartUploadResult, error) { func (o *OSS) CompleteMultipartUpload(
ctx context.Context,
uploadID string,
name string,
parts []s3.Part,
) (*s3.CompleteMultipartUploadResult, error) {
ossParts := make([]oss.UploadPart, len(parts)) ossParts := make([]oss.UploadPart, len(parts))
for i, part := range parts { for i, part := range parts {
ossParts[i] = oss.UploadPart{ ossParts[i] = oss.UploadPart{
@ -114,7 +121,13 @@ func (o *OSS) PartSize(ctx context.Context, size int64) (int64, error) {
return partSize, nil return partSize, nil
} }
func (o *OSS) AuthSign(ctx context.Context, uploadID string, name string, expire time.Duration, partNumbers []int) (*s3.AuthSignResult, error) { func (o *OSS) AuthSign(
ctx context.Context,
uploadID string,
name string,
expire time.Duration,
partNumbers []int,
) (*s3.AuthSignResult, error) {
result := s3.AuthSignResult{ result := s3.AuthSignResult{
URL: o.bucketURL + name, URL: o.bucketURL + name,
Query: url.Values{"uploadId": {uploadID}}, Query: url.Values{"uploadId": {uploadID}},
@ -132,7 +145,15 @@ func (o *OSS) AuthSign(ctx context.Context, uploadID string, name string, expire
} }
request.Header.Set(oss.HTTPHeaderHost, request.Host) request.Header.Set(oss.HTTPHeaderHost, request.Host)
request.Header.Set(oss.HTTPHeaderDate, time.Now().UTC().Format(http.TimeFormat)) request.Header.Set(oss.HTTPHeaderDate, time.Now().UTC().Format(http.TimeFormat))
authorization := fmt.Sprintf(`OSS %s:%s`, o.credentials.GetAccessKeyID(), o.getSignedStr(request, fmt.Sprintf(`/%s/%s?partNumber=%d&uploadId=%s`, o.bucket.BucketName, name, partNumber, uploadID), o.credentials.GetAccessKeySecret())) authorization := fmt.Sprintf(
`OSS %s:%s`,
o.credentials.GetAccessKeyID(),
o.getSignedStr(
request,
fmt.Sprintf(`/%s/%s?partNumber=%d&uploadId=%s`, o.bucket.BucketName, name, partNumber, uploadID),
o.credentials.GetAccessKeySecret(),
),
)
request.Header.Set(oss.HTTPHeaderAuthorization, authorization) request.Header.Set(oss.HTTPHeaderAuthorization, authorization)
result.Parts[i] = s3.SignPart{ result.Parts[i] = s3.SignPart{
PartNumber: partNumber, PartNumber: partNumber,
@ -213,7 +234,13 @@ func (o *OSS) AbortMultipartUpload(ctx context.Context, uploadID string, name st
}) })
} }
func (o *OSS) ListUploadedParts(ctx context.Context, uploadID string, name string, partNumberMarker int, maxParts int) (*s3.ListUploadedPartsResult, error) { func (o *OSS) ListUploadedParts(
ctx context.Context,
uploadID string,
name string,
partNumberMarker int,
maxParts int,
) (*s3.ListUploadedPartsResult, error) {
result, err := o.bucket.ListUploadedParts(oss.InitiateMultipartUploadResult{ result, err := o.bucket.ListUploadedParts(oss.InitiateMultipartUploadResult{
UploadID: uploadID, UploadID: uploadID,
Key: name, Key: name,
@ -240,7 +267,12 @@ func (o *OSS) ListUploadedParts(ctx context.Context, uploadID string, name strin
return res, nil return res, nil
} }
func (o *OSS) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) { func (o *OSS) AccessURL(
ctx context.Context,
name string,
expire time.Duration,
opt *s3.AccessURLOption,
) (string, error) {
//var opts []oss.Option //var opts []oss.Option
//if opt != nil { //if opt != nil {
// if opt.ContentType != "" { // if opt.ContentType != "" {

@ -5,12 +5,13 @@ import (
"crypto/sha1" "crypto/sha1"
"crypto/sha256" "crypto/sha256"
"encoding/base64" "encoding/base64"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"hash" "hash"
"io" "io"
"net/http" "net/http"
"sort" "sort"
"strings" "strings"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
) )
func (o *OSS) getAdditionalHeaderKeys(req *http.Request) ([]string, map[string]string) { func (o *OSS) getAdditionalHeaderKeys(req *http.Request) ([]string, map[string]string) {
@ -71,7 +72,10 @@ func (o *OSS) getSignedStr(req *http.Request, canonicalizedResource string, keyS
// v2 signature // v2 signature
if o.bucket.Client.Config.AuthVersion == oss.AuthV2 { if o.bucket.Client.Config.AuthVersion == oss.AuthV2 {
signStr = req.Method + "\n" + contentMd5 + "\n" + contentType + "\n" + date + "\n" + canonicalizedOSSHeaders + strings.Join(additionalList, ";") + "\n" + canonicalizedResource signStr = req.Method + "\n" + contentMd5 + "\n" + contentType + "\n" + date + "\n" + canonicalizedOSSHeaders + strings.Join(
additionalList,
";",
) + "\n" + canonicalizedResource
h = hmac.New(func() hash.Hash { return sha256.New() }, []byte(keySecret)) h = hmac.New(func() hash.Hash { return sha256.New() }, []byte(keySecret))
} }
_, _ = io.WriteString(h, signStr) _, _ = io.WriteString(h, signStr)

@ -112,10 +112,21 @@ type Interface interface {
PartLimit() *PartLimit PartLimit() *PartLimit
InitiateMultipartUpload(ctx context.Context, name string) (*InitiateMultipartUploadResult, error) InitiateMultipartUpload(ctx context.Context, name string) (*InitiateMultipartUploadResult, error)
CompleteMultipartUpload(ctx context.Context, uploadID string, name string, parts []Part) (*CompleteMultipartUploadResult, error) CompleteMultipartUpload(
ctx context.Context,
uploadID string,
name string,
parts []Part,
) (*CompleteMultipartUploadResult, error)
PartSize(ctx context.Context, size int64) (int64, error) PartSize(ctx context.Context, size int64) (int64, error)
AuthSign(ctx context.Context, uploadID string, name string, expire time.Duration, partNumbers []int) (*AuthSignResult, error) AuthSign(
ctx context.Context,
uploadID string,
name string,
expire time.Duration,
partNumbers []int,
) (*AuthSignResult, error)
PresignedPutObject(ctx context.Context, name string, expire time.Duration) (string, error) PresignedPutObject(ctx context.Context, name string, expire time.Duration) (string, error)
@ -128,7 +139,13 @@ type Interface interface {
IsNotFound(err error) bool IsNotFound(err error) bool
AbortMultipartUpload(ctx context.Context, uploadID string, name string) error AbortMultipartUpload(ctx context.Context, uploadID string, name string) error
ListUploadedParts(ctx context.Context, uploadID string, name string, partNumberMarker int, maxParts int) (*ListUploadedPartsResult, error) ListUploadedParts(
ctx context.Context,
uploadID string,
name string,
partNumberMarker int,
maxParts int,
) (*ListUploadedPartsResult, error)
AccessURL(ctx context.Context, name string, expire time.Duration, opt *AccessURLOption) (string, error) AccessURL(ctx context.Context, name string, expire time.Duration, opt *AccessURLOption) (string, error)
} }

@ -37,13 +37,26 @@ func (ConversationModel) TableName() string {
type ConversationModelInterface interface { type ConversationModelInterface interface {
Create(ctx context.Context, conversations []*ConversationModel) (err error) Create(ctx context.Context, conversations []*ConversationModel) (err error)
Delete(ctx context.Context, groupIDs []string) (err error) Delete(ctx context.Context, groupIDs []string) (err error)
UpdateByMap(ctx context.Context, userIDs []string, conversationID string, args map[string]interface{}) (rows int64, err error) UpdateByMap(
ctx context.Context,
userIDs []string,
conversationID string,
args map[string]interface{},
) (rows int64, err error)
Update(ctx context.Context, conversation *ConversationModel) (err error) Update(ctx context.Context, conversation *ConversationModel) (err error)
Find(ctx context.Context, ownerUserID string, conversationIDs []string) (conversations []*ConversationModel, err error) Find(
ctx context.Context,
ownerUserID string,
conversationIDs []string,
) (conversations []*ConversationModel, err error)
FindUserID(ctx context.Context, userIDs []string, conversationIDs []string) ([]string, error) FindUserID(ctx context.Context, userIDs []string, conversationIDs []string) ([]string, error)
FindUserIDAllConversationID(ctx context.Context, userID string) ([]string, error) FindUserIDAllConversationID(ctx context.Context, userID string) ([]string, error)
Take(ctx context.Context, userID, conversationID string) (conversation *ConversationModel, err error) Take(ctx context.Context, userID, conversationID string) (conversation *ConversationModel, err error)
FindConversationID(ctx context.Context, userID string, conversationIDs []string) (existConversationID []string, err error) FindConversationID(
ctx context.Context,
userID string,
conversationIDs []string,
) (existConversationID []string, err error)
FindUserIDAllConversations(ctx context.Context, userID string) (conversations []*ConversationModel, err error) FindUserIDAllConversations(ctx context.Context, userID string) (conversations []*ConversationModel, err error)
FindRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error) FindRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error)
GetUserRecvMsgOpt(ctx context.Context, ownerUserID, conversationID string) (opt int, err error) GetUserRecvMsgOpt(ctx context.Context, ownerUserID, conversationID string) (opt int, err error)

@ -16,6 +16,7 @@ package unrelation
import ( import (
"context" "context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
"strconv" "strconv"
"time" "time"
@ -108,8 +109,24 @@ type MsgDocModelInterface interface {
GetMsgDocModelByIndex(ctx context.Context, conversationID string, index, sort int64) (*MsgDocModel, error) GetMsgDocModelByIndex(ctx context.Context, conversationID string, index, sort int64) (*MsgDocModel, error)
DeleteMsgsInOneDocByIndex(ctx context.Context, docID string, indexes []int) error DeleteMsgsInOneDocByIndex(ctx context.Context, docID string, indexes []int) error
MarkSingleChatMsgsAsRead(ctx context.Context, userID string, docID string, indexes []int64) error MarkSingleChatMsgsAsRead(ctx context.Context, userID string, docID string, indexes []int64) error
RangeUserSendCount(ctx context.Context, start time.Time, end time.Time, group bool, ase bool, pageNumber int32, showNumber int32) (msgCount int64, userCount int64, users []*UserCount, dateCount map[string]int64, err error) SearchMessage(ctx context.Context, req *msg.SearchMessageReq) ([]*MsgInfoModel, error)
RangeGroupSendCount(ctx context.Context, start time.Time, end time.Time, ase bool, pageNumber int32, showNumber int32) (msgCount int64, userCount int64, groups []*GroupCount, dateCount map[string]int64, err error) RangeUserSendCount(
ctx context.Context,
start time.Time,
end time.Time,
group bool,
ase bool,
pageNumber int32,
showNumber int32,
) (msgCount int64, userCount int64, users []*UserCount, dateCount map[string]int64, err error)
RangeGroupSendCount(
ctx context.Context,
start time.Time,
end time.Time,
ase bool,
pageNumber int32,
showNumber int32,
) (msgCount int64, userCount int64, groups []*GroupCount, dateCount map[string]int64, err error)
} }
func (MsgDocModel) TableName() string { func (MsgDocModel) TableName() string {

@ -31,19 +31,21 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
) )
const (
maxRetry = 10 //number of retries
)
type Mongo struct { type Mongo struct {
db *mongo.Client db *mongo.Client
} }
// NewMongo Initialize MongoDB connection
func NewMongo() (*Mongo, error) { func NewMongo() (*Mongo, error) {
specialerror.AddReplace(mongo.ErrNoDocuments, errs.ErrRecordNotFound) specialerror.AddReplace(mongo.ErrNoDocuments, errs.ErrRecordNotFound)
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority" url := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
if config.Config.Mongo.Uri != "" { if config.Config.Mongo.Uri != "" {
// example: url = config.Config.Mongo.Uri
// mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize
uri = config.Config.Mongo.Uri
} else { } else {
//mongodb://mongodb1.example.com:27317,mongodb2.example.com:27017/?replicaSet=mySet&authSource=authDB
mongodbHosts := "" mongodbHosts := ""
for i, v := range config.Config.Mongo.Address { for i, v := range config.Config.Mongo.Address {
if i == len(config.Config.Mongo.Address)-1 { if i == len(config.Config.Mongo.Address)-1 {
@ -53,23 +55,34 @@ func NewMongo() (*Mongo, error) {
} }
} }
if config.Config.Mongo.Password != "" && config.Config.Mongo.Username != "" { if config.Config.Mongo.Password != "" && config.Config.Mongo.Username != "" {
uri = fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d&authSource=admin", url = fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d&authSource=admin",
config.Config.Mongo.Username, config.Config.Mongo.Password, mongodbHosts, config.Config.Mongo.Username, config.Config.Mongo.Password, mongodbHosts,
config.Config.Mongo.Database, config.Config.Mongo.MaxPoolSize) config.Config.Mongo.Database, config.Config.Mongo.MaxPoolSize)
} else { } else {
uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d&authSource=admin", url = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d&authSource=admin",
mongodbHosts, config.Config.Mongo.Database, mongodbHosts, config.Config.Mongo.Database,
config.Config.Mongo.MaxPoolSize) config.Config.Mongo.MaxPoolSize)
} }
} }
fmt.Println("mongo:", uri) fmt.Println("mongo:", url)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*60) var mongoClient *mongo.Client
var err error = nil
for i := 0; i <= maxRetry; i++ {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel() defer cancel()
mongoClient, err := mongo.Connect(ctx, options.Client().ApplyURI(uri)) mongoClient, err = mongo.Connect(ctx, options.Client().ApplyURI(url))
if err != nil { if err == nil {
return &Mongo{db: mongoClient}, nil
}
if cmdErr, ok := err.(mongo.CommandError); ok {
if cmdErr.Code == 13 || cmdErr.Code == 18 {
return nil, err return nil, err
} else {
fmt.Printf("Failed to connect to MongoDB: %s\n", err)
} }
return &Mongo{db: mongoClient}, nil }
}
return nil, err
} }
func (m *Mongo) GetClient() *mongo.Client { func (m *Mongo) GetClient() *mongo.Client {

@ -19,6 +19,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
"time" "time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
@ -555,7 +556,15 @@ func (m *MsgMongoDriver) MarkSingleChatMsgsAsRead(
// } // }
// //
// ]) // ])
func (m *MsgMongoDriver) RangeUserSendCount(ctx context.Context, start time.Time, end time.Time, group bool, ase bool, pageNumber int32, showNumber int32) (msgCount int64, userCount int64, users []*table.UserCount, dateCount map[string]int64, err error) { func (m *MsgMongoDriver) RangeUserSendCount(
ctx context.Context,
start time.Time,
end time.Time,
group bool,
ase bool,
pageNumber int32,
showNumber int32,
) (msgCount int64, userCount int64, users []*table.UserCount, dateCount map[string]int64, err error) {
var sort int var sort int
if ase { if ase {
sort = 1 sort = 1
@ -808,7 +817,14 @@ func (m *MsgMongoDriver) RangeUserSendCount(ctx context.Context, start time.Time
return result[0].MsgCount, result[0].UserCount, users, dateCount, nil return result[0].MsgCount, result[0].UserCount, users, dateCount, nil
} }
func (m *MsgMongoDriver) RangeGroupSendCount(ctx context.Context, start time.Time, end time.Time, ase bool, pageNumber int32, showNumber int32) (msgCount int64, userCount int64, groups []*table.GroupCount, dateCount map[string]int64, err error) { func (m *MsgMongoDriver) RangeGroupSendCount(
ctx context.Context,
start time.Time,
end time.Time,
ase bool,
pageNumber int32,
showNumber int32,
) (msgCount int64, userCount int64, groups []*table.GroupCount, dateCount map[string]int64, err error) {
var sort int var sort int
if ase { if ase {
sort = 1 sort = 1
@ -1049,3 +1065,136 @@ func (m *MsgMongoDriver) RangeGroupSendCount(ctx context.Context, start time.Tim
} }
return result[0].MsgCount, result[0].UserCount, groups, dateCount, nil return result[0].MsgCount, result[0].UserCount, groups, dateCount, nil
} }
func (m *MsgMongoDriver) SearchMessage(ctx context.Context, req *msg.SearchMessageReq) ([]*table.MsgInfoModel, error) {
msgs, err := m.searchMessage(ctx, req)
if err != nil {
return nil, err
}
for _, msg1 := range msgs {
if msg1.IsRead {
msg1.Msg.IsRead = true
}
}
return msgs, nil
}
func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessageReq) ([]*table.MsgInfoModel, error) {
var pipe mongo.Pipeline
conditon := bson.A{}
if req.SendTime != "" {
conditon = append(conditon, bson.M{"$eq": bson.A{bson.M{"$dateToString": bson.M{"format": "%Y-%m-%d", "date": bson.M{"$toDate": "$$item.msg.send_time"}}}, req.SendTime}})
}
if req.MsgType != 0 {
conditon = append(conditon, bson.M{"$eq": bson.A{"$$item.msg.content_type", req.MsgType}})
}
if req.SessionType != 0 {
conditon = append(conditon, bson.M{"$eq": bson.A{"$$item.msg.session_type", req.SessionType}})
}
if req.RecvID != "" {
conditon = append(conditon, bson.M{"$regexFind": bson.M{"input": "$$item.msg.recv_id", "regex": req.RecvID}})
}
if req.SendID != "" {
conditon = append(conditon, bson.M{"$regexFind": bson.M{"input": "$$item.msg.send_id", "regex": req.SendID}})
}
or := bson.A{
bson.M{
"doc_id": bson.M{
"$regex": "^si_",
"$options": "i",
},
},
}
or = append(or,
bson.M{
"doc_id": bson.M{
"$regex": "^g_",
"$options": "i",
},
},
bson.M{
"doc_id": bson.M{
"$regex": "^sg_",
"$options": "i",
},
},
)
pipe = mongo.Pipeline{
{
{"$match", bson.D{
{
"$or", or,
},
}},
},
{
{"$project", bson.D{
{"msgs", bson.D{
{"$filter", bson.D{
{"input", "$msgs"},
{"as", "item"},
{"cond", bson.D{
{"$and", conditon},
},
}},
}},
},
{"doc_id", 1},
}},
},
}
cursor, err := m.MsgCollection.Aggregate(ctx, pipe)
if err != nil {
return nil, err
}
var msgsDocs []table.MsgDocModel
err = cursor.All(ctx, &msgsDocs)
if err != nil {
return nil, err
}
if len(msgsDocs) == 0 {
return nil, errs.Wrap(mongo.ErrNoDocuments)
}
msgs := make([]*table.MsgInfoModel, 0)
for index, _ := range msgsDocs {
for i := range msgsDocs[index].Msg {
msg := msgsDocs[index].Msg[i]
if msg == nil || msg.Msg == nil {
continue
}
if msg.Revoke != nil {
revokeContent := sdkws.MessageRevokedContent{
RevokerID: msg.Revoke.UserID,
RevokerRole: msg.Revoke.Role,
ClientMsgID: msg.Msg.ClientMsgID,
RevokerNickname: msg.Revoke.Nickname,
RevokeTime: msg.Revoke.Time,
SourceMessageSendTime: msg.Msg.SendTime,
SourceMessageSendID: msg.Msg.SendID,
SourceMessageSenderNickname: msg.Msg.SenderNickname,
SessionType: msg.Msg.SessionType,
Seq: msg.Msg.Seq,
Ex: msg.Msg.Ex,
}
data, err := json.Marshal(&revokeContent)
if err != nil {
return nil, err
}
elem := sdkws.NotificationElem{
Detail: string(data),
}
content, err := json.Marshal(&elem)
if err != nil {
return nil, err
}
msg.Msg.ContentType = constant.MsgRevokeNotification
msg.Msg.Content = string(content)
}
msgs = append(msgs, msg)
}
}
return msgs, nil
}

@ -1,9 +1,18 @@
/* // Copyright © 2023 OpenIM. All rights reserved.
** description(""). //
** copyright('open-im,www.open-im.io'). // Licensed under the Apache License, Version 2.0 (the "License");
** author("fg,Gordon@tuoyun.net"). // you may not use this file except in compliance with the License.
** time(2021/5/27 10:31). // You may obtain a copy of the License at
*/package http //
// 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 http
import ( import (
"bytes" "bytes"

@ -17,12 +17,12 @@ package kafka
import ( import (
"context" "context"
"errors" "errors"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
log "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" log "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"time"
"github.com/Shopify/sarama" "github.com/Shopify/sarama"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@ -30,6 +30,10 @@ import (
prome "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome" prome "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome"
) )
const (
maxRetry = 10 //number of retries
)
var errEmptyMsg = errors.New("binary msg is empty") var errEmptyMsg = errors.New("binary msg is empty")
type Producer struct { type Producer struct {
@ -39,6 +43,7 @@ type Producer struct {
producer sarama.SyncProducer producer sarama.SyncProducer
} }
// NewKafkaProducer Initialize kafka producer
func NewKafkaProducer(addr []string, topic string) *Producer { func NewKafkaProducer(addr []string, topic string) *Producer {
p := Producer{} p := Producer{}
p.config = sarama.NewConfig() //Instantiate a sarama Config p.config = sarama.NewConfig() //Instantiate a sarama Config
@ -53,7 +58,24 @@ func NewKafkaProducer(addr []string, topic string) *Producer {
} }
p.addr = addr p.addr = addr
p.topic = topic p.topic = topic
producer, err := sarama.NewSyncProducer(p.addr, p.config) //Initialize the client var producer sarama.SyncProducer
var err error
for i := 0; i <= maxRetry; i++ {
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
//if packetErr, ok := err.(*sarama.PacketEncodingError); ok {
//if _, ok := packetErr.Err.(sarama.AuthenticationError); ok {
// fmt.Println("Kafka password is wrong.")
//}
//} else {
// fmt.Printf("Failed to create Kafka producer: %v\n", err)
//}
time.Sleep(time.Duration(1) * time.Second)
}
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())
} }

@ -17,7 +17,11 @@ type SqlLogger struct {
SlowThreshold time.Duration SlowThreshold time.Duration
} }
func NewSqlLogger(logLevel gormLogger.LogLevel, ignoreRecordNotFoundError bool, slowThreshold time.Duration) *SqlLogger { func NewSqlLogger(
logLevel gormLogger.LogLevel,
ignoreRecordNotFoundError bool,
slowThreshold time.Duration,
) *SqlLogger {
return &SqlLogger{ return &SqlLogger{
LogLevel: logLevel, LogLevel: logLevel,
IgnoreRecordNotFoundError: ignoreRecordNotFoundError, IgnoreRecordNotFoundError: ignoreRecordNotFoundError,
@ -52,7 +56,17 @@ func (l *SqlLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql s
case err != nil && l.LogLevel >= gormLogger.Error && (!errors.Is(err, gorm.ErrRecordNotFound) || !l.IgnoreRecordNotFoundError): case err != nil && l.LogLevel >= gormLogger.Error && (!errors.Is(err, gorm.ErrRecordNotFound) || !l.IgnoreRecordNotFoundError):
sql, rows := fc() sql, rows := fc()
if rows == -1 { if rows == -1 {
ZError(ctx, "sql exec detail", err, "gorm", gormUtils.FileWithLineNum(), "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "sql", sql) ZError(
ctx,
"sql exec detail",
err,
"gorm",
gormUtils.FileWithLineNum(),
"elapsed time",
fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6),
"sql",
sql,
)
} else { } else {
ZError(ctx, "sql exec detail", err, "gorm", gormUtils.FileWithLineNum(), "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "rows", rows, "sql", sql) ZError(ctx, "sql exec detail", err, "gorm", gormUtils.FileWithLineNum(), "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "rows", rows, "sql", sql)
} }
@ -60,14 +74,35 @@ func (l *SqlLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql s
sql, rows := fc() sql, rows := fc()
slowLog := fmt.Sprintf("SLOW SQL >= %v", l.SlowThreshold) slowLog := fmt.Sprintf("SLOW SQL >= %v", l.SlowThreshold)
if rows == -1 { if rows == -1 {
ZWarn(ctx, "sql exec detail", nil, "gorm", gormUtils.FileWithLineNum(), "slow sql", slowLog, "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "sql", sql) ZWarn(
ctx,
"sql exec detail",
nil,
"gorm",
gormUtils.FileWithLineNum(),
"slow sql",
slowLog,
"elapsed time",
fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6),
"sql",
sql,
)
} else { } else {
ZWarn(ctx, "sql exec detail", nil, "gorm", gormUtils.FileWithLineNum(), "slow sql", slowLog, "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "rows", rows, "sql", sql) ZWarn(ctx, "sql exec detail", nil, "gorm", gormUtils.FileWithLineNum(), "slow sql", slowLog, "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "rows", rows, "sql", sql)
} }
case l.LogLevel == gormLogger.Info: case l.LogLevel == gormLogger.Info:
sql, rows := fc() sql, rows := fc()
if rows == -1 { if rows == -1 {
ZDebug(ctx, "sql exec detail", "gorm", gormUtils.FileWithLineNum(), "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "sql", sql) ZDebug(
ctx,
"sql exec detail",
"gorm",
gormUtils.FileWithLineNum(),
"elapsed time",
fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6),
"sql",
sql,
)
} else { } else {
ZDebug(ctx, "sql exec detail", "gorm", gormUtils.FileWithLineNum(), "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "rows", rows, "sql", sql) ZDebug(ctx, "sql exec detail", "gorm", gormUtils.FileWithLineNum(), "elapsed time", fmt.Sprintf("%f(ms)", float64(elapsed.Nanoseconds())/1e6), "rows", rows, "sql", sql)
} }

@ -31,6 +31,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
) )
// CorsHandler gin cross-domain configuration.
func CorsHandler() gin.HandlerFunc { func CorsHandler() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*") c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
@ -39,19 +40,19 @@ func CorsHandler() gin.HandlerFunc {
c.Header( c.Header(
"Access-Control-Expose-Headers", "Access-Control-Expose-Headers",
"Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers,Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,FooBar", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers,Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,FooBar",
) // 跨域关键设置 让浏览器可以解析 ) // Cross-domain key settings allow browsers to resolve.
c.Header( c.Header(
"Access-Control-Max-Age", "Access-Control-Max-Age",
"172800", "172800",
) // 缓存请求信息 单位为秒 ) // Cache request information in seconds.
c.Header( c.Header(
"Access-Control-Allow-Credentials", "Access-Control-Allow-Credentials",
"false", "false",
) // 跨域请求是否需要带cookie信息 默认设置为true ) // Whether cross-domain requests need to carry cookie information, the default setting is true.
c.Header( c.Header(
"content-type", "content-type",
"application/json", "application/json",
) // 设置返回格式是json ) // Set the return format to json.
//Release all option pre-requests //Release all option pre-requests
if c.Request.Method == http.MethodOptions { if c.Request.Method == http.MethodOptions {
c.JSON(http.StatusOK, "Options Request!") c.JSON(http.StatusOK, "Options Request!")

@ -6,9 +6,10 @@ import (
"io" "io"
"strings" "strings"
"github.com/pkg/errors"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/pkg/errors"
"github.com/go-zookeeper/zk" "github.com/go-zookeeper/zk"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -69,7 +70,11 @@ func (s *ZkClient) GetConnsRemote(serviceName string) (conns []resolver.Address,
return conns, nil return conns, nil
} }
func (s *ZkClient) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]grpc.ClientConnInterface, error) { func (s *ZkClient) GetConns(
ctx context.Context,
serviceName string,
opts ...grpc.DialOption,
) ([]grpc.ClientConnInterface, error) {
s.logger.Printf("get conns from client, serviceName: %s", serviceName) s.logger.Printf("get conns from client, serviceName: %s", serviceName)
opts = append(s.options, opts...) opts = append(s.options, opts...)
s.lock.Lock() s.lock.Lock()
@ -83,12 +88,26 @@ func (s *ZkClient) GetConns(ctx context.Context, serviceName string, opts ...grp
return nil, err return nil, err
} }
if len(addrs) == 0 { if len(addrs) == 0 {
return nil, fmt.Errorf("no conn for service %s, grpc server may not exist, local conn is %v, please check zookeeper server %v, path: %s", serviceName, s.localConns, s.zkServers, s.zkRoot) return nil, fmt.Errorf(
"no conn for service %s, grpc server may not exist, local conn is %v, please check zookeeper server %v, path: %s",
serviceName,
s.localConns,
s.zkServers,
s.zkRoot,
)
} }
for _, addr := range addrs { for _, addr := range addrs {
cc, err := grpc.DialContext(ctx, addr.Addr, append(s.options, opts...)...) cc, err := grpc.DialContext(ctx, addr.Addr, append(s.options, opts...)...)
if err != nil { if err != nil {
log.ZError(context.Background(), "dialContext failed", err, "addr", addr.Addr, "opts", append(s.options, opts...)) log.ZError(
context.Background(),
"dialContext failed",
err,
"addr",
addr.Addr,
"opts",
append(s.options, opts...),
)
return nil, errs.Wrap(err) return nil, errs.Wrap(err)
} }
conns = append(conns, cc) conns = append(conns, cc)
@ -98,8 +117,15 @@ func (s *ZkClient) GetConns(ctx context.Context, serviceName string, opts ...grp
return conns, nil return conns, nil
} }
func (s *ZkClient) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (grpc.ClientConnInterface, error) { func (s *ZkClient) GetConn(
newOpts := append(s.options, grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, s.balancerName))) ctx context.Context,
serviceName string,
opts ...grpc.DialOption,
) (grpc.ClientConnInterface, error) {
newOpts := append(
s.options,
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, s.balancerName)),
)
s.logger.Printf("get conn from client, serviceName: %s", serviceName) s.logger.Printf("get conn from client, serviceName: %s", serviceName)
return grpc.DialContext(ctx, fmt.Sprintf("%s:///%s", s.scheme, serviceName), append(newOpts, opts...)...) return grpc.DialContext(ctx, fmt.Sprintf("%s:///%s", s.scheme, serviceName), append(newOpts, opts...)...)
} }

@ -1,3 +1,17 @@
// 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.
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.29.1 // protoc-gen-go v1.29.1
@ -8,14 +22,13 @@ package auth
import ( import (
context "context" context "context"
reflect "reflect"
sync "sync"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
) )
const ( const (

@ -1,3 +1,17 @@
// 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.
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.29.1 // protoc-gen-go v1.29.1
@ -8,16 +22,14 @@ package conversation
import ( import (
context "context" context "context"
reflect "reflect" wrapperspb "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
sync "sync"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
wrapperspb "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb" sync "sync"
) )
const ( const (

@ -1,3 +1,17 @@
// 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.
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.29.1 // protoc-gen-go v1.29.1
@ -7,11 +21,10 @@
package errinfo package errinfo
import ( import (
reflect "reflect"
sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
) )
const ( const (

@ -1,3 +1,17 @@
// 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.
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.29.1 // protoc-gen-go v1.29.1
@ -8,16 +22,14 @@ package friend
import ( import (
context "context" context "context"
reflect "reflect" sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
sync "sync"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" sync "sync"
) )
const ( const (

@ -1,3 +1,17 @@
// 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.
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.29.1 // protoc-gen-go v1.29.1
@ -8,17 +22,15 @@ package group
import ( import (
context "context" context "context"
reflect "reflect" sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
sync "sync" wrapperspb "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" sync "sync"
wrapperspb "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
) )
const ( const (

File diff suppressed because it is too large Load Diff

@ -232,12 +232,66 @@ message GetActiveGroupResp {
repeated ActiveGroup groups = 4; repeated ActiveGroup groups = 4;
} }
message SearchMessageReq{
string sendID=1;//ID
string recvID=2;//ID
int32 msgType=3;
string sendTime=4;
int32 sessionType=5;
sdkws.RequestPagination pagination = 6;
}
message SearchMessageResp{
repeated ChatLog chatLogs=1;
int32 chatLogsNum = 2;
}
message manageMsgReq{
string recvID=1;
string sendID=2;
string groupID=3;
int64 seq=4;
int32 sessionType=5;
}
message manageMsgResp{
}
message ChatLog {
string serverMsgID = 1;
string clientMsgID = 2;
string sendID = 3;
string recvID = 4;
string groupID = 5;
string recvNickname = 6;
int32 senderPlatformID = 7;
string senderNickname = 8;
string senderFaceURL = 9;
string groupName = 10;
int32 sessionType = 11;
int32 msgFrom = 12;
int32 contentType = 13;
string content = 14;
int32 status = 15;
int64 sendTime = 16;
int64 createTime = 17;
string ex = 18;
string groupFaceURL=19;
uint32 groupMemberCount=20;
int64 seq=21;
string groupOwner=22;
int32 groupType=23;
}
service msg { service msg {
//seq //seq
rpc GetMaxSeq(sdkws.GetMaxSeqReq) returns(sdkws.GetMaxSeqResp); rpc GetMaxSeq(sdkws.GetMaxSeqReq) returns(sdkws.GetMaxSeqResp);
rpc GetConversationMaxSeq(GetConversationMaxSeqReq) returns(GetConversationMaxSeqResp); rpc GetConversationMaxSeq(GetConversationMaxSeqReq) returns(GetConversationMaxSeqResp);
// //
rpc PullMessageBySeqs(sdkws.PullMessageBySeqsReq) returns(sdkws.PullMessageBySeqsResp); rpc PullMessageBySeqs(sdkws.PullMessageBySeqsReq) returns(sdkws.PullMessageBySeqsResp);
rpc SearchMessage(SearchMessageReq) returns(SearchMessageResp);
rpc ManageMsg(manageMsgReq) returns (manageMsgResp);
// //
rpc SendMsg(SendMsgReq) returns(SendMsgResp); rpc SendMsg(SendMsgReq) returns(SendMsgResp);

@ -1,3 +1,17 @@
// 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.
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.29.1 // protoc-gen-go v1.29.1
@ -8,16 +22,14 @@ package msggateway
import ( import (
context "context" context "context"
reflect "reflect" sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
sync "sync"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" sync "sync"
) )
const ( const (

@ -1,3 +1,17 @@
// 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.
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.29.1 // protoc-gen-go v1.29.1
@ -8,16 +22,14 @@ package push
import ( import (
context "context" context "context"
reflect "reflect" sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
sync "sync"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" sync "sync"
) )
const ( const (

@ -1,3 +1,17 @@
// 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.
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.29.1 // protoc-gen-go v1.29.1
@ -7,13 +21,11 @@
package sdkws package sdkws
import ( import (
reflect "reflect" wrapperspb "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
wrapperspb "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb" sync "sync"
) )
const ( const (

@ -1,3 +1,17 @@
// 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.
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.29.1 // protoc-gen-go v1.29.1
@ -7,10 +21,9 @@
package statistics package statistics
import ( import (
reflect "reflect"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
) )
const ( const (

@ -1,3 +1,17 @@
// 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.
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.29.1 // protoc-gen-go v1.29.1
@ -8,14 +22,13 @@ package third
import ( import (
context "context" context "context"
reflect "reflect"
sync "sync"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
) )
const ( const (

@ -1,3 +1,17 @@
// 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.
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.29.1 // protoc-gen-go v1.29.1
@ -8,17 +22,15 @@ package user
import ( import (
context "context" context "context"
reflect "reflect" conversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
sync "sync" sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
conversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation" sync "sync"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
) )
const ( const (

@ -1,3 +1,17 @@
// 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.
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.29.1 // protoc-gen-go v1.29.1
@ -7,11 +21,10 @@
package wrapperspb package wrapperspb
import ( import (
reflect "reflect"
sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
) )
const ( const (

@ -4,11 +4,12 @@ import (
"context" "context"
"fmt" "fmt"
"google.golang.org/grpc"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation" pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
"google.golang.org/grpc"
) )
type Conversation struct { type Conversation struct {
@ -32,7 +33,10 @@ func NewConversationRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) Con
return ConversationRpcClient(*NewConversation(discov)) return ConversationRpcClient(*NewConversation(discov))
} }
func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(ctx context.Context, userID, conversationID string) (int32, error) { func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(
ctx context.Context,
userID, conversationID string,
) (int32, error) {
var req pbConversation.GetConversationReq var req pbConversation.GetConversationReq
req.OwnerUserID = userID req.OwnerUserID = userID
req.ConversationID = conversationID req.ConversationID = conversationID
@ -44,21 +48,51 @@ func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(ctx context.Cont
} }
func (c *ConversationRpcClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID string) error { func (c *ConversationRpcClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID string) error {
_, err := c.Client.CreateSingleChatConversations(ctx, &pbConversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID}) _, err := c.Client.CreateSingleChatConversations(
ctx,
&pbConversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID},
)
return err return err
} }
func (c *ConversationRpcClient) GroupChatFirstCreateConversation(ctx context.Context, groupID string, userIDs []string) error { func (c *ConversationRpcClient) GroupChatFirstCreateConversation(
_, err := c.Client.CreateGroupChatConversations(ctx, &pbConversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID}) ctx context.Context,
groupID string,
userIDs []string,
) error {
_, err := c.Client.CreateGroupChatConversations(
ctx,
&pbConversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID},
)
return err return err
} }
func (c *ConversationRpcClient) SetConversationMaxSeq(ctx context.Context, ownerUserIDs []string, conversationID string, maxSeq int64) error { func (c *ConversationRpcClient) SetConversationMaxSeq(
_, err := c.Client.SetConversationMaxSeq(ctx, &pbConversation.SetConversationMaxSeqReq{OwnerUserID: ownerUserIDs, ConversationID: conversationID, MaxSeq: maxSeq}) ctx context.Context,
ownerUserIDs []string,
conversationID string,
maxSeq int64,
) error {
_, err := c.Client.SetConversationMaxSeq(
ctx,
&pbConversation.SetConversationMaxSeqReq{
OwnerUserID: ownerUserIDs,
ConversationID: conversationID,
MaxSeq: maxSeq,
},
)
return err return err
} }
func (c *ConversationRpcClient) SetConversations(ctx context.Context, userIDs []string, conversation *pbConversation.ConversationReq) error {
_, err := c.Client.SetConversations(ctx, &pbConversation.SetConversationsReq{UserIDs: userIDs, Conversation: conversation}) func (c *ConversationRpcClient) SetConversations(
ctx context.Context,
userIDs []string,
conversation *pbConversation.ConversationReq,
) error {
_, err := c.Client.SetConversations(
ctx,
&pbConversation.SetConversationsReq{UserIDs: userIDs, Conversation: conversation},
)
return err return err
} }
@ -70,16 +104,28 @@ func (c *ConversationRpcClient) GetConversationIDs(ctx context.Context, ownerUse
return resp.ConversationIDs, nil return resp.ConversationIDs, nil
} }
func (c *ConversationRpcClient) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*pbConversation.Conversation, error) { func (c *ConversationRpcClient) GetConversation(
resp, err := c.Client.GetConversation(ctx, &pbConversation.GetConversationReq{OwnerUserID: ownerUserID, ConversationID: conversationID}) ctx context.Context,
ownerUserID, conversationID string,
) (*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversation(
ctx,
&pbConversation.GetConversationReq{OwnerUserID: ownerUserID, ConversationID: conversationID},
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return resp.Conversation, nil return resp.Conversation, nil
} }
func (c *ConversationRpcClient) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*pbConversation.Conversation, error) { func (c *ConversationRpcClient) GetConversationsByConversationID(
resp, err := c.Client.GetConversationsByConversationID(ctx, &pbConversation.GetConversationsByConversationIDReq{ConversationIDs: conversationIDs}) ctx context.Context,
conversationIDs []string,
) ([]*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversationsByConversationID(
ctx,
&pbConversation.GetConversationsByConversationIDReq{ConversationIDs: conversationIDs},
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -89,8 +135,15 @@ func (c *ConversationRpcClient) GetConversationsByConversationID(ctx context.Con
return resp.Conversations, nil return resp.Conversations, nil
} }
func (c *ConversationRpcClient) GetConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*pbConversation.Conversation, error) { func (c *ConversationRpcClient) GetConversations(
resp, err := c.Client.GetConversations(ctx, &pbConversation.GetConversationsReq{OwnerUserID: ownerUserID, ConversationIDs: conversationIDs}) ctx context.Context,
ownerUserID string,
conversationIDs []string,
) ([]*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversations(
ctx,
&pbConversation.GetConversationsReq{OwnerUserID: ownerUserID, ConversationIDs: conversationIDs},
)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -3,6 +3,10 @@ package rpcclient
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
@ -11,8 +15,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
// "google.golang.org/protobuf/proto" // "google.golang.org/protobuf/proto"
) )
@ -136,7 +138,10 @@ func (m *MessageRpcClient) GetMaxSeq(ctx context.Context, req *sdkws.GetMaxSeqRe
return resp, err return resp, err
} }
func (m *MessageRpcClient) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMessageBySeqsReq) (*sdkws.PullMessageBySeqsResp, error) { func (m *MessageRpcClient) PullMessageBySeqList(
ctx context.Context,
req *sdkws.PullMessageBySeqsReq,
) (*sdkws.PullMessageBySeqsResp, error) {
resp, err := m.Client.PullMessageBySeqs(ctx, req) resp, err := m.Client.PullMessageBySeqs(ctx, req)
return resp, err return resp, err
} }
@ -158,7 +163,9 @@ type NotificationSender struct {
type NotificationSenderOptions func(*NotificationSender) type NotificationSenderOptions func(*NotificationSender)
func WithLocalSendMsg(sendMsg func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error)) NotificationSenderOptions { func WithLocalSendMsg(
sendMsg func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error),
) NotificationSenderOptions {
return func(s *NotificationSender) { return func(s *NotificationSender) {
s.sendMsg = sendMsg s.sendMsg = sendMsg
} }
@ -177,7 +184,10 @@ func WithUserRpcClient(userRpcClient *UserRpcClient) NotificationSenderOptions {
} }
func NewNotificationSender(opts ...NotificationSenderOptions) *NotificationSender { func NewNotificationSender(opts ...NotificationSenderOptions) *NotificationSender {
notificationSender := &NotificationSender{contentTypeConf: newContentTypeConf(), sessionTypeConf: newSessionTypeConf()} notificationSender := &NotificationSender{
contentTypeConf: newContentTypeConf(),
sessionTypeConf: newSessionTypeConf(),
}
for _, opt := range opts { for _, opt := range opts {
opt(notificationSender) opt(notificationSender)
} }
@ -196,11 +206,29 @@ func WithRpcGetUserName() NotificationOptions {
} }
} }
func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, sendID, recvID string, contentType, sesstionType int32, m proto.Message, opts ...NotificationOptions) (err error) { func (s *NotificationSender) NotificationWithSesstionType(
ctx context.Context,
sendID, recvID string,
contentType, sesstionType int32,
m proto.Message,
opts ...NotificationOptions,
) (err error) {
n := sdkws.NotificationElem{Detail: utils.StructToJsonString(m)} n := sdkws.NotificationElem{Detail: utils.StructToJsonString(m)}
content, err := json.Marshal(&n) content, err := json.Marshal(&n)
if err != nil { if err != nil {
log.ZError(ctx, "MsgClient Notification json.Marshal failed", err, "sendID", sendID, "recvID", recvID, "contentType", contentType, "msg", m) log.ZError(
ctx,
"MsgClient Notification json.Marshal failed",
err,
"sendID",
sendID,
"recvID",
recvID,
"contentType",
contentType,
"msg",
m,
)
return err return err
} }
notificationOpt := &notificationOpt{} notificationOpt := &notificationOpt{}
@ -247,6 +275,25 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s
return err return err
} }
func (s *NotificationSender) Notification(ctx context.Context, sendID, recvID string, contentType int32, m proto.Message, opts ...NotificationOptions) error { func (s *NotificationSender) Notification(
ctx context.Context,
sendID, recvID string,
contentType int32,
m proto.Message,
opts ...NotificationOptions,
) error {
return s.NotificationWithSesstionType(ctx, sendID, recvID, contentType, s.sessionTypeConf[contentType], m, opts...) return s.NotificationWithSesstionType(ctx, sendID, recvID, contentType, s.sessionTypeConf[contentType], m, opts...)
} }
func (m *Message) GetAllUserID(ctx context.Context, req *user.GetAllUserIDReq) (*user.GetAllUserIDResp, error) {
conn, err := m.discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName)
if err != nil {
panic(err)
}
client := user.NewUserClient(conn)
resp, err := client.GetAllUserID(ctx, req)
if err != nil {
return nil, err
}
return resp, nil
}

@ -16,9 +16,17 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
) )
func NewGroupNotificationSender(db controller.GroupDatabase, msgRpcClient *rpcclient.MessageRpcClient, userRpcClient *rpcclient.UserRpcClient, fn func(ctx context.Context, userIDs []string) ([]CommonUser, error)) *GroupNotificationSender { func NewGroupNotificationSender(
db controller.GroupDatabase,
msgRpcClient *rpcclient.MessageRpcClient,
userRpcClient *rpcclient.UserRpcClient,
fn func(ctx context.Context, userIDs []string) ([]CommonUser, error),
) *GroupNotificationSender {
return &GroupNotificationSender{ return &GroupNotificationSender{
NotificationSender: rpcclient.NewNotificationSender(rpcclient.WithRpcClient(msgRpcClient), rpcclient.WithUserRpcClient(userRpcClient)), NotificationSender: rpcclient.NewNotificationSender(
rpcclient.WithRpcClient(msgRpcClient),
rpcclient.WithUserRpcClient(userRpcClient),
),
getUsersInfo: fn, getUsersInfo: fn,
db: db, db: db,
} }
@ -80,7 +88,11 @@ func (g *GroupNotificationSender) getGroupInfo(ctx context.Context, groupID stri
}, nil }, nil
} }
func (g *GroupNotificationSender) getGroupMembers(ctx context.Context, groupID string, userIDs []string) ([]*sdkws.GroupMemberFullInfo, error) { func (g *GroupNotificationSender) getGroupMembers(
ctx context.Context,
groupID string,
userIDs []string,
) ([]*sdkws.GroupMemberFullInfo, error) {
members, err := g.db.FindGroupMember(ctx, []string{groupID}, userIDs, nil) members, err := g.db.FindGroupMember(ctx, []string{groupID}, userIDs, nil)
if err != nil { if err != nil {
return nil, err return nil, err
@ -95,7 +107,9 @@ func (g *GroupNotificationSender) getGroupMembers(ctx context.Context, groupID s
for _, member := range members { for _, member := range members {
user, ok := users[member.UserID] user, ok := users[member.UserID]
if !ok { if !ok {
return nil, errs.ErrUserIDNotFound.Wrap(fmt.Sprintf("group %s member %s not in user", member.GroupID, member.UserID)) return nil, errs.ErrUserIDNotFound.Wrap(
fmt.Sprintf("group %s member %s not in user", member.GroupID, member.UserID),
)
} }
if member.Nickname == "" { if member.Nickname == "" {
member.Nickname = user.Nickname member.Nickname = user.Nickname
@ -117,7 +131,11 @@ func (g *GroupNotificationSender) getGroupMembers(ctx context.Context, groupID s
return res, nil return res, nil
} }
func (g *GroupNotificationSender) getGroupMemberMap(ctx context.Context, groupID string, userIDs []string) (map[string]*sdkws.GroupMemberFullInfo, error) { func (g *GroupNotificationSender) getGroupMemberMap(
ctx context.Context,
groupID string,
userIDs []string,
) (map[string]*sdkws.GroupMemberFullInfo, error) {
members, err := g.getGroupMembers(ctx, groupID, userIDs) members, err := g.getGroupMembers(ctx, groupID, userIDs)
if err != nil { if err != nil {
return nil, err return nil, err
@ -129,7 +147,11 @@ func (g *GroupNotificationSender) getGroupMemberMap(ctx context.Context, groupID
return m, nil return m, nil
} }
func (g *GroupNotificationSender) getGroupMember(ctx context.Context, groupID string, userID string) (*sdkws.GroupMemberFullInfo, error) { func (g *GroupNotificationSender) getGroupMember(
ctx context.Context,
groupID string,
userID string,
) (*sdkws.GroupMemberFullInfo, error) {
members, err := g.getGroupMembers(ctx, groupID, []string{userID}) members, err := g.getGroupMembers(ctx, groupID, []string{userID})
if err != nil { if err != nil {
return nil, err return nil, err
@ -149,7 +171,11 @@ func (g *GroupNotificationSender) getGroupOwnerAndAdminUserID(ctx context.Contex
return utils.Slice(members, fn), nil return utils.Slice(members, fn), nil
} }
func (g *GroupNotificationSender) groupDB2PB(group *relation.GroupModel, ownerUserID string, memberCount uint32) *sdkws.GroupInfo { func (g *GroupNotificationSender) groupDB2PB(
group *relation.GroupModel,
ownerUserID string,
memberCount uint32,
) *sdkws.GroupInfo {
return &sdkws.GroupInfo{ return &sdkws.GroupInfo{
GroupID: group.GroupID, GroupID: group.GroupID,
GroupName: group.GroupName, GroupName: group.GroupName,
@ -171,7 +197,10 @@ func (g *GroupNotificationSender) groupDB2PB(group *relation.GroupModel, ownerUs
} }
} }
func (g *GroupNotificationSender) groupMemberDB2PB(member *relation.GroupMemberModel, appMangerLevel int32) *sdkws.GroupMemberFullInfo { func (g *GroupNotificationSender) groupMemberDB2PB(
member *relation.GroupMemberModel,
appMangerLevel int32,
) *sdkws.GroupMemberFullInfo {
return &sdkws.GroupMemberFullInfo{ return &sdkws.GroupMemberFullInfo{
GroupID: member.GroupID, GroupID: member.GroupID,
UserID: member.UserID, UserID: member.UserID,
@ -188,7 +217,10 @@ func (g *GroupNotificationSender) groupMemberDB2PB(member *relation.GroupMemberM
} }
} }
func (g *GroupNotificationSender) getUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) { func (g *GroupNotificationSender) getUsersInfoMap(
ctx context.Context,
userIDs []string,
) (map[string]*sdkws.UserInfo, error) {
users, err := g.getUsersInfo(ctx, userIDs) users, err := g.getUsersInfo(ctx, userIDs)
if err != nil { if err != nil {
return nil, err return nil, err
@ -200,7 +232,11 @@ func (g *GroupNotificationSender) getUsersInfoMap(ctx context.Context, userIDs [
return result, nil return result, nil
} }
func (g *GroupNotificationSender) fillOpUser(ctx context.Context, opUser **sdkws.GroupMemberFullInfo, groupID string) error { func (g *GroupNotificationSender) fillOpUser(
ctx context.Context,
opUser **sdkws.GroupMemberFullInfo,
groupID string,
) error {
if opUser == nil { if opUser == nil {
return errs.ErrInternalServer.Wrap("**sdkws.GroupMemberFullInfo is nil") return errs.ErrInternalServer.Wrap("**sdkws.GroupMemberFullInfo is nil")
} }
@ -239,35 +275,70 @@ func (g *GroupNotificationSender) fillOpUser(ctx context.Context, opUser **sdkws
return nil return nil
} }
func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context, tips *sdkws.GroupCreatedTips) (err error) { func (g *GroupNotificationSender) GroupCreatedNotification(
ctx context.Context,
tips *sdkws.GroupCreatedTips,
) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err return err
} }
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupCreatedNotification, tips) return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupCreatedNotification, tips)
} }
func (g *GroupNotificationSender) GroupInfoSetNotification(ctx context.Context, tips *sdkws.GroupInfoSetTips) (err error) { func (g *GroupNotificationSender) GroupInfoSetNotification(
ctx context.Context,
tips *sdkws.GroupInfoSetTips,
) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err return err
} }
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNotification, tips, rpcclient.WithRpcGetUserName()) return g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
tips.Group.GroupID,
constant.GroupInfoSetNotification,
tips,
rpcclient.WithRpcGetUserName(),
)
} }
func (g *GroupNotificationSender) GroupInfoSetNameNotification(ctx context.Context, tips *sdkws.GroupInfoSetNameTips) (err error) { func (g *GroupNotificationSender) GroupInfoSetNameNotification(
ctx context.Context,
tips *sdkws.GroupInfoSetNameTips,
) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err return err
} }
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNameNotification, tips) return g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
tips.Group.GroupID,
constant.GroupInfoSetNameNotification,
tips,
)
} }
func (g *GroupNotificationSender) GroupInfoSetAnnouncementNotification(ctx context.Context, tips *sdkws.GroupInfoSetAnnouncementTips) (err error) { func (g *GroupNotificationSender) GroupInfoSetAnnouncementNotification(
ctx context.Context,
tips *sdkws.GroupInfoSetAnnouncementTips,
) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err return err
} }
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetAnnouncementNotification, tips, rpcclient.WithRpcGetUserName()) return g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
tips.Group.GroupID,
constant.GroupInfoSetAnnouncementNotification,
tips,
rpcclient.WithRpcGetUserName(),
)
} }
func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) (err error) { func (g *GroupNotificationSender) JoinGroupApplicationNotification(
ctx context.Context,
req *pbGroup.JoinGroupReq,
) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID) group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil { if err != nil {
return err return err
@ -291,7 +362,10 @@ func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.C
return nil return nil
} }
func (g *GroupNotificationSender) MemberQuitNotification(ctx context.Context, member *sdkws.GroupMemberFullInfo) (err error) { func (g *GroupNotificationSender) MemberQuitNotification(
ctx context.Context,
member *sdkws.GroupMemberFullInfo,
) (err error) {
defer log.ZDebug(ctx, "return") defer log.ZDebug(ctx, "return")
defer func() { defer func() {
if err != nil { if err != nil {
@ -306,7 +380,10 @@ func (g *GroupNotificationSender) MemberQuitNotification(ctx context.Context, me
return g.Notification(ctx, mcontext.GetOpUserID(ctx), member.GroupID, constant.MemberQuitNotification, tips) return g.Notification(ctx, mcontext.GetOpUserID(ctx), member.GroupID, constant.MemberQuitNotification, tips)
} }
func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) { func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(
ctx context.Context,
req *pbGroup.GroupApplicationResponseReq,
) (err error) {
defer log.ZDebug(ctx, "return") defer log.ZDebug(ctx, "return")
defer func() { defer func() {
if err != nil { if err != nil {
@ -326,7 +403,13 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte
return err return err
} }
for _, userID := range append(userIDs, mcontext.GetOpUserID(ctx)) { for _, userID := range append(userIDs, mcontext.GetOpUserID(ctx)) {
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.GroupApplicationAcceptedNotification, tips) err = g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
userID,
constant.GroupApplicationAcceptedNotification,
tips,
)
if err != nil { if err != nil {
log.ZError(ctx, "failed", err) log.ZError(ctx, "failed", err)
} }
@ -334,7 +417,10 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte
return nil return nil
} }
func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) { func (g *GroupNotificationSender) GroupApplicationRejectedNotification(
ctx context.Context,
req *pbGroup.GroupApplicationResponseReq,
) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID) group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil { if err != nil {
return err return err
@ -348,7 +434,13 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte
return err return err
} }
for _, userID := range append(userIDs, mcontext.GetOpUserID(ctx)) { for _, userID := range append(userIDs, mcontext.GetOpUserID(ctx)) {
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.GroupApplicationRejectedNotification, tips) err = g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
userID,
constant.GroupApplicationRejectedNotification,
tips,
)
if err != nil { if err != nil {
log.ZError(ctx, "failed", err) log.ZError(ctx, "failed", err)
} }
@ -356,7 +448,10 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte
return nil return nil
} }
func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context.Context, req *pbGroup.TransferGroupOwnerReq) (err error) { func (g *GroupNotificationSender) GroupOwnerTransferredNotification(
ctx context.Context,
req *pbGroup.TransferGroupOwnerReq,
) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID) group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil { if err != nil {
return err return err
@ -366,21 +461,38 @@ func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context.
if err != nil { if err != nil {
return err return err
} }
tips := &sdkws.GroupOwnerTransferredTips{Group: group, OpUser: member[opUserID], NewGroupOwner: member[req.NewOwnerUserID]} tips := &sdkws.GroupOwnerTransferredTips{
Group: group,
OpUser: member[opUserID],
NewGroupOwner: member[req.NewOwnerUserID],
}
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err return err
} }
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupOwnerTransferredNotification, tips) return g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
group.GroupID,
constant.GroupOwnerTransferredNotification,
tips,
)
} }
func (g *GroupNotificationSender) MemberKickedNotification(ctx context.Context, tips *sdkws.MemberKickedTips) (err error) { func (g *GroupNotificationSender) MemberKickedNotification(
ctx context.Context,
tips *sdkws.MemberKickedTips,
) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err return err
} }
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.MemberKickedNotification, tips) return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.MemberKickedNotification, tips)
} }
func (g *GroupNotificationSender) MemberInvitedNotification(ctx context.Context, groupID, reason string, invitedUserIDList []string) (err error) { func (g *GroupNotificationSender) MemberInvitedNotification(
ctx context.Context,
groupID, reason string,
invitedUserIDList []string,
) (err error) {
group, err := g.getGroupInfo(ctx, groupID) group, err := g.getGroupInfo(ctx, groupID)
if err != nil { if err != nil {
return err return err
@ -399,7 +511,10 @@ func (g *GroupNotificationSender) MemberInvitedNotification(ctx context.Context,
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberInvitedNotification, tips) return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberInvitedNotification, tips)
} }
func (g *GroupNotificationSender) MemberEnterNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) { func (g *GroupNotificationSender) MemberEnterNotification(
ctx context.Context,
req *pbGroup.GroupApplicationResponseReq,
) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID) group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil { if err != nil {
return err return err
@ -412,14 +527,21 @@ func (g *GroupNotificationSender) MemberEnterNotification(ctx context.Context, r
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberEnterNotification, tips) return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberEnterNotification, tips)
} }
func (g *GroupNotificationSender) GroupDismissedNotification(ctx context.Context, tips *sdkws.GroupDismissedTips) (err error) { func (g *GroupNotificationSender) GroupDismissedNotification(
ctx context.Context,
tips *sdkws.GroupDismissedTips,
) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err return err
} }
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupDismissedNotification, tips) return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupDismissedNotification, tips)
} }
func (g *GroupNotificationSender) GroupMemberMutedNotification(ctx context.Context, groupID, groupMemberUserID string, mutedSeconds uint32) (err error) { func (g *GroupNotificationSender) GroupMemberMutedNotification(
ctx context.Context,
groupID, groupMemberUserID string,
mutedSeconds uint32,
) (err error) {
group, err := g.getGroupInfo(ctx, groupID) group, err := g.getGroupInfo(ctx, groupID)
if err != nil { if err != nil {
return err return err
@ -436,7 +558,10 @@ func (g *GroupNotificationSender) GroupMemberMutedNotification(ctx context.Conte
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberMutedNotification, tips) return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberMutedNotification, tips)
} }
func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) { func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(
ctx context.Context,
groupID, groupMemberUserID string,
) (err error) {
group, err := g.getGroupInfo(ctx, groupID) group, err := g.getGroupInfo(ctx, groupID)
if err != nil { if err != nil {
return err return err
@ -445,11 +570,21 @@ func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(ctx context
if err != nil { if err != nil {
return err return err
} }
tips := &sdkws.GroupMemberCancelMutedTips{Group: group, OpUser: user[mcontext.GetOpUserID(ctx)], MutedUser: user[groupMemberUserID]} tips := &sdkws.GroupMemberCancelMutedTips{
Group: group,
OpUser: user[mcontext.GetOpUserID(ctx)],
MutedUser: user[groupMemberUserID],
}
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err return err
} }
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberCancelMutedNotification, tips) return g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
group.GroupID,
constant.GroupMemberCancelMutedNotification,
tips,
)
} }
func (g *GroupNotificationSender) GroupMutedNotification(ctx context.Context, groupID string) (err error) { func (g *GroupNotificationSender) GroupMutedNotification(ctx context.Context, groupID string) (err error) {
@ -490,7 +625,10 @@ func (g *GroupNotificationSender) GroupCancelMutedNotification(ctx context.Conte
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupCancelMutedNotification, tips) return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupCancelMutedNotification, tips)
} }
func (g *GroupNotificationSender) GroupMemberInfoSetNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) { func (g *GroupNotificationSender) GroupMemberInfoSetNotification(
ctx context.Context,
groupID, groupMemberUserID string,
) (err error) {
group, err := g.getGroupInfo(ctx, groupID) group, err := g.getGroupInfo(ctx, groupID)
if err != nil { if err != nil {
return err return err
@ -499,14 +637,21 @@ func (g *GroupNotificationSender) GroupMemberInfoSetNotification(ctx context.Con
if err != nil { if err != nil {
return err return err
} }
tips := &sdkws.GroupMemberInfoSetTips{Group: group, OpUser: user[mcontext.GetOpUserID(ctx)], ChangedUser: user[groupMemberUserID]} tips := &sdkws.GroupMemberInfoSetTips{
Group: group,
OpUser: user[mcontext.GetOpUserID(ctx)],
ChangedUser: user[groupMemberUserID],
}
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err return err
} }
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberInfoSetNotification, tips) return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberInfoSetNotification, tips)
} }
func (g *GroupNotificationSender) GroupMemberSetToAdminNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) { func (g *GroupNotificationSender) GroupMemberSetToAdminNotification(
ctx context.Context,
groupID, groupMemberUserID string,
) (err error) {
group, err := g.getGroupInfo(ctx, groupID) group, err := g.getGroupInfo(ctx, groupID)
if err != nil { if err != nil {
return err return err
@ -515,14 +660,27 @@ func (g *GroupNotificationSender) GroupMemberSetToAdminNotification(ctx context.
if err != nil { if err != nil {
return err return err
} }
tips := &sdkws.GroupMemberInfoSetTips{Group: group, OpUser: user[mcontext.GetOpUserID(ctx)], ChangedUser: user[groupMemberUserID]} tips := &sdkws.GroupMemberInfoSetTips{
Group: group,
OpUser: user[mcontext.GetOpUserID(ctx)],
ChangedUser: user[groupMemberUserID],
}
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err return err
} }
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberSetToAdminNotification, tips) return g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
group.GroupID,
constant.GroupMemberSetToAdminNotification,
tips,
)
} }
func (g *GroupNotificationSender) GroupMemberSetToOrdinaryUserNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) { func (g *GroupNotificationSender) GroupMemberSetToOrdinaryUserNotification(
ctx context.Context,
groupID, groupMemberUserID string,
) (err error) {
group, err := g.getGroupInfo(ctx, groupID) group, err := g.getGroupInfo(ctx, groupID)
if err != nil { if err != nil {
return err return err
@ -531,14 +689,28 @@ func (g *GroupNotificationSender) GroupMemberSetToOrdinaryUserNotification(ctx c
if err != nil { if err != nil {
return err return err
} }
tips := &sdkws.GroupMemberInfoSetTips{Group: group, OpUser: user[mcontext.GetOpUserID(ctx)], ChangedUser: user[groupMemberUserID]} tips := &sdkws.GroupMemberInfoSetTips{
Group: group,
OpUser: user[mcontext.GetOpUserID(ctx)],
ChangedUser: user[groupMemberUserID],
}
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err return err
} }
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberSetToOrdinaryUserNotification, tips) return g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
group.GroupID,
constant.GroupMemberSetToOrdinaryUserNotification,
tips,
)
} }
func (g *GroupNotificationSender) MemberEnterDirectlyNotification(ctx context.Context, groupID string, entrantUserID string) (err error) { func (g *GroupNotificationSender) MemberEnterDirectlyNotification(
ctx context.Context,
groupID string,
entrantUserID string,
) (err error) {
defer log.ZDebug(ctx, "return") defer log.ZDebug(ctx, "return")
defer func() { defer func() {
if err != nil { if err != nil {

@ -16,7 +16,11 @@ func NewMsgNotificationSender(opts ...rpcclient.NotificationSenderOptions) *MsgN
return &MsgNotificationSender{rpcclient.NewNotificationSender(opts...)} return &MsgNotificationSender{rpcclient.NewNotificationSender(opts...)}
} }
func (m *MsgNotificationSender) UserDeleteMsgsNotification(ctx context.Context, userID, conversationID string, seqs []int64) error { func (m *MsgNotificationSender) UserDeleteMsgsNotification(
ctx context.Context,
userID, conversationID string,
seqs []int64,
) error {
tips := sdkws.DeleteMsgsTips{ tips := sdkws.DeleteMsgsTips{
UserID: userID, UserID: userID,
ConversationID: conversationID, ConversationID: conversationID,
@ -25,7 +29,14 @@ func (m *MsgNotificationSender) UserDeleteMsgsNotification(ctx context.Context,
return m.Notification(ctx, userID, userID, constant.MsgDeleteNotification, &tips) return m.Notification(ctx, userID, userID, constant.MsgDeleteNotification, &tips)
} }
func (m *MsgNotificationSender) MarkAsReadNotification(ctx context.Context, conversationID string, sesstionType int32, sendID, recvID string, seqs []int64, hasReadSeq int64) error { func (m *MsgNotificationSender) MarkAsReadNotification(
ctx context.Context,
conversationID string,
sesstionType int32,
sendID, recvID string,
seqs []int64,
hasReadSeq int64,
) error {
tips := &sdkws.MarkAsReadTips{ tips := &sdkws.MarkAsReadTips{
MarkAsReadUserID: sendID, MarkAsReadUserID: sendID,
ConversationID: conversationID, ConversationID: conversationID,

@ -16,6 +16,9 @@ package rpcclient
import ( import (
"context" "context"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"net/url"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -28,6 +31,7 @@ type Third struct {
conn grpc.ClientConnInterface conn grpc.ClientConnInterface
Client third.ThirdClient Client third.ThirdClient
discov discoveryregistry.SvcDiscoveryRegistry discov discoveryregistry.SvcDiscoveryRegistry
MinioClient *minio.Client
} }
func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third { func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
@ -36,5 +40,30 @@ func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
panic(err) panic(err)
} }
client := third.NewThirdClient(conn) client := third.NewThirdClient(conn)
return &Third{discov: discov, Client: client, conn: conn} minioClient, err := minioInit()
return &Third{discov: discov, Client: client, conn: conn, MinioClient: minioClient}
}
func minioInit() (*minio.Client, error) {
minioClient := &minio.Client{}
var initUrl string
initUrl = config.Config.Object.Minio.Endpoint
minioUrl, err := url.Parse(initUrl)
if err != nil {
return nil, err
}
opts := &minio.Options{
Creds: credentials.NewStaticV4(config.Config.Object.Minio.AccessKeyID, config.Config.Object.Minio.SecretAccessKey, ""),
//Region: config.Config.Credential.Minio.Location,
}
if minioUrl.Scheme == "http" {
opts.Secure = false
} else if minioUrl.Scheme == "https" {
opts.Secure = true
}
minioClient, err = minio.New(minioUrl.Host, opts)
if err != nil {
return nil, err
}
return minioClient, nil
} }

@ -35,8 +35,8 @@ echo -e "${BOLD_PREFIX}_________________________________________________________
bin_dir="$BIN_DIR" bin_dir="$BIN_DIR"
logs_dir="../logs" logs_dir="$OPENIM_ROOT/logs"
sdk_db_dir="../db/sdk/" sdk_db_dir="$OPENIM_ROOT/db/sdk/"
# Automatically created when there is no bin, logs folder # Automatically created when there is no bin, logs folder
if [ ! -d $bin_dir ]; then if [ ! -d $bin_dir ]; then
mkdir -p $bin_dir mkdir -p $bin_dir

@ -43,7 +43,7 @@ for i in ${service_port_name[*]}; do
port=$(ss -tunlp| grep openim | awk '{print $5}' | grep -w ${j} | awk -F '[:]' '{print $NF}') port=$(ss -tunlp| grep openim | awk '{print $5}' | grep -w ${j} | awk -F '[:]' '{print $NF}')
if [[ ${port} -ne ${j} ]]; then if [[ ${port} -ne ${j} ]]; then
echo -e ${BACKGROUND_GREEN}${i}${COLOR_SUFFIX}${RED_PREFIX}" service does not start normally,not initiated port is "${COLOR_SUFFIX}${BACKGROUND_GREEN}${j}${COLOR_SUFFIX} echo -e ${BACKGROUND_GREEN}${i}${COLOR_SUFFIX}${RED_PREFIX}" service does not start normally,not initiated port is "${COLOR_SUFFIX}${BACKGROUND_GREEN}${j}${COLOR_SUFFIX}
echo -e ${RED_PREFIX}"please check $OPENIM_ROOT/logs/openIM.log "${COLOR_SUFFIX} echo -e ${RED_PREFIX}"please check $OPENIM_ROOT/logs/openIM.log"${COLOR_SUFFIX}
exit -1 exit -1
else else
echo -e ${j}${GREEN_PREFIX}" port has been listening,belongs service is "${i}${COLOR_SUFFIX} echo -e ${j}${GREEN_PREFIX}" port has been listening,belongs service is "${i}${COLOR_SUFFIX}

@ -26,7 +26,7 @@
LC_ALL=C LC_ALL=C
local_branch="$(git rev-parse --abbrev-ref HEAD)" local_branch="$(git rev-parse --abbrev-ref HEAD)"
valid_branch_regex="^(main|master|develop|release)$|(feature|feat|openim|hotfix|test|bug|ci|cicd|style|)\/[a-z0-9._-]+$|^HEAD$" valid_branch_regex="^(main|master|develop|release(-[a-zA-Z0-9._-]+)?)$|(feature|feat|openim|hotfix|test|bug|ci|cicd|style|)\/[a-z0-9._-]+$|^HEAD$"
YELLOW="\e[93m" YELLOW="\e[93m"
GREEN="\e[32m" GREEN="\e[32m"

@ -21,6 +21,9 @@ GREEN="\e[32m"
RED="\e[31m" RED="\e[31m"
ENDCOLOR="\e[0m" ENDCOLOR="\e[0m"
local_branch="$(git rev-parse --abbrev-ref HEAD)"
valid_branch_regex="^(main|master|develop|release(-[a-zA-Z0-9._-]+)?)$|(feature|feat|openim|hotfix|test|bug|ci|cicd|style|)\/[a-z0-9._-]+$|^HEAD$"
printMessage() { printMessage() {
printf "${YELLOW}OpenIM : $1${ENDCOLOR}\n" printf "${YELLOW}OpenIM : $1${ENDCOLOR}\n"
} }
@ -96,6 +99,14 @@ print_color "Added Files: ${added_files}" "${BACKGROUND_GREEN}"
print_color "Modified Files: ${modified_files}" "${BACKGROUND_GREEN}" print_color "Modified Files: ${modified_files}" "${BACKGROUND_GREEN}"
print_color "Deleted Files: ${deleted_files}" "${BACKGROUND_GREEN}" print_color "Deleted Files: ${deleted_files}" "${BACKGROUND_GREEN}"
if [[ ! $local_branch =~ $valid_branch_regex ]]
then
printError "There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex.
Your commit will be rejected. You should rename your branch to a valid name(feat/name OR bug/name) and try again."
printError "For more on this, read on: https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694"
exit 1
fi
# #
#printMessage "Running the Flutter analyzer" #printMessage "Running the Flutter analyzer"
#flutter analyze #flutter analyze

@ -61,7 +61,7 @@ sleep 1
cd ${msg_gateway_binary_root} cd ${msg_gateway_binary_root}
for ((i = 0; i < ${#ws_ports[@]}; i++)); do for ((i = 0; i < ${#ws_ports[@]}; i++)); do
echo "==========================start msg_gateway server===========================">>$OPENIM_ROOT/logs/openIM.log echo "==========================start msg_gateway server===========================">>$OPENIM_ROOT/logs/openIM.log
nohup ./${openim_msggateway} --port ${rpc_ports[$i]} --ws_port ${ws_ports[$i]} --prometheus_port ${prome_ports[$i]} --config_folder_path ${configfile_path} >>$OPENIM_ROOT/logs/openIM.log 2>&1 & nohup ./${openim_msggateway} --port ${rpc_ports[$i]} --ws_port ${ws_ports[$i]} --prometheus_port ${prome_ports[$i]} --config_folder_path ${configfile_path} --configFolderPath ${log_path} >>$OPENIM_ROOT/logs/openIM.log 2>&1 &
done done
#Check launched service process #Check launched service process

@ -55,9 +55,9 @@ sleep 1
cd ${msg_transfer_binary_root} cd ${msg_transfer_binary_root}
for ((i = 0; i < ${msg_transfer_service_num}; i++)); do for ((i = 0; i < ${msg_transfer_service_num}; i++)); do
prome_port=${prome_ports[$i]} prome_port=${prome_ports[$i]}
cmd="nohup ./${openim_msgtransfer} --config_folder_path ${configfile_path}" cmd="nohup ./${openim_msgtransfer} --config_folder_path ${configfile_path} --configFolderPath ${log_path}"
if [ $prome_port != "" ]; then if [ $prome_port != "" ]; then
cmd="$cmd --prometheus_port $prome_port --config_folder_path ${configfile_path}" cmd="$cmd --prometheus_port $prome_port --config_folder_path ${configfile_path} --configFolderPath ${log_path}"
fi fi
echo "==========================start msg_transfer server===========================">>$OPENIM_ROOT/logs/openIM.log echo "==========================start msg_transfer server===========================">>$OPENIM_ROOT/logs/openIM.log
$cmd >>$OPENIM_ROOT/logs/openIM.log 2>&1 & $cmd >>$OPENIM_ROOT/logs/openIM.log 2>&1 &

@ -82,6 +82,7 @@ cmd_utils_source_root="$OPENIM_ROOT/cmd/openim-cmdutils/"
# Global configuration file default dir # Global configuration file default dir
config_path="$OPENIM_ROOT/config/config.yaml" config_path="$OPENIM_ROOT/config/config.yaml"
configfile_path="$OPENIM_ROOT/config" configfile_path="$OPENIM_ROOT/config"
log_path="$OPENIM_ROOT/log"
# servicefile dir path # servicefile dir path
service_source_root=( service_source_root=(

@ -35,6 +35,18 @@ bin_dir="$BIN_DIR"
logs_dir="$OPENIM_ROOT/logs" logs_dir="$OPENIM_ROOT/logs"
sdk_db_dir="$OPENIM_ROOT/sdk/db/" sdk_db_dir="$OPENIM_ROOT/sdk/db/"
if [ ! -d "$bin_dir" ]; then
mkdir -p "$bin_dir"
fi
if [ ! -d "$logs_dir" ]; then
mkdir -p "$logs_dir"
fi
if [ ! -d "$sdk_db_dir" ]; then
mkdir -p "$sdk_db_dir"
fi
# Print title # Print title
echo -e "${BOLD_PREFIX}${BLUE_PREFIX}================> OpenIM Server Start${COLOR_SUFFIX}" echo -e "${BOLD_PREFIX}${BLUE_PREFIX}================> OpenIM Server Start${COLOR_SUFFIX}"

@ -100,9 +100,9 @@ for ((i = 0; i < ${#service_filename[*]}; i++)); do
for ((j = 0; j < ${#service_ports[*]}; j++)); do for ((j = 0; j < ${#service_ports[*]}; j++)); do
#Start the service in the background #Start the service in the background
if [ -z "${prome_ports[$j]}" ]; then if [ -z "${prome_ports[$j]}" ]; then
cmd="./${service_filename[$i]} --port ${service_ports[$j]} --config_folder_path ${configfile_path}" cmd="./${service_filename[$i]} --port ${service_ports[$j]} --config_folder_path ${configfile_path} --configFolderPath ${log_path}"
else else
cmd="./${service_filename[$i]} --port ${service_ports[$j]} --prometheus_port ${prome_ports[$j]} --config_folder_path ${configfile_path}" cmd="./${service_filename[$i]} --port ${service_ports[$j]} --prometheus_port ${prome_ports[$j]} --config_folder_path ${configfile_path} --configFolderPath ${log_path}"
fi fi
if [ $i -eq 0 -o $i -eq 1 ]; then if [ $i -eq 0 -o $i -eq 1 ]; then
cmd="./${service_filename[$i]} --port ${service_ports[$j]}" cmd="./${service_filename[$i]} --port ${service_ports[$j]}"

Loading…
Cancel
Save