mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-10-03 22:10:05 +08:00
feat: golang fix apt test design (#2084)
* feat: make lint format * feat: make lint format * feat: make lint format * fix: fix make lint * feat: add scripts verify shell check * feat: add scripts verify shell check
This commit is contained in:
parent
b67c6bacd0
commit
7c25c91e9b
@ -745,7 +745,7 @@ linters:
|
|||||||
- misspell # Spelling mistakes
|
- misspell # Spelling mistakes
|
||||||
- staticcheck # Static analysis
|
- staticcheck # Static analysis
|
||||||
- unused # Checks for unused code
|
- unused # Checks for unused code
|
||||||
- goimports # Checks if imports are correctly sorted and formatted
|
# - goimports # Checks if imports are correctly sorted and formatted
|
||||||
- godot # Checks for comment punctuation
|
- godot # Checks for comment punctuation
|
||||||
- bodyclose # Ensures HTTP response body is closed
|
- bodyclose # Ensures HTTP response body is closed
|
||||||
- stylecheck # Style checker for Go code
|
- stylecheck # Style checker for Go code
|
||||||
|
@ -186,23 +186,6 @@ services:
|
|||||||
# server:
|
# server:
|
||||||
# ipv4_address: ${OPENIM_SERVER_NETWORK_ADDRESS:-172.28.0.8}
|
# ipv4_address: ${OPENIM_SERVER_NETWORK_ADDRESS:-172.28.0.8}
|
||||||
|
|
||||||
### TODO: mysql is required to deploy the openim-chat component
|
|
||||||
# mysql:
|
|
||||||
# image: mysql:${MYSQL_IMAGE_VERSION:-5.7}
|
|
||||||
# platform: linux/amd64
|
|
||||||
# ports:
|
|
||||||
# - "${MYSQL_PORT:-13306}:3306"
|
|
||||||
# container_name: mysql
|
|
||||||
# volumes:
|
|
||||||
# - "${DATA_DIR:-./}/components/mysql/data:/var/lib/mysql"
|
|
||||||
# - "/etc/localtime:/etc/localtime"
|
|
||||||
# environment:
|
|
||||||
# MYSQL_ROOT_PASSWORD: "${MYSQL_PASSWORD:-openIM123}"
|
|
||||||
# restart: always
|
|
||||||
# networks:
|
|
||||||
# server:
|
|
||||||
# ipv4_address: ${MYSQL_NETWORK_ADDRESS:-172.28.0.15}
|
|
||||||
|
|
||||||
# openim-chat:
|
# openim-chat:
|
||||||
# image: ${IMAGE_REGISTRY:-ghcr.io/openimsdk}/openim-chat:${CHAT_IMAGE_VERSION:-main}
|
# image: ${IMAGE_REGISTRY:-ghcr.io/openimsdk}/openim-chat:${CHAT_IMAGE_VERSION:-main}
|
||||||
# container_name: openim-chat
|
# container_name: openim-chat
|
||||||
|
@ -215,25 +215,22 @@ func (m *MessageApi) SendMessage(c *gin.Context) {
|
|||||||
// Set the receiver ID in the message data.
|
// Set the receiver ID in the message data.
|
||||||
sendMsgReq.MsgData.RecvID = req.RecvID
|
sendMsgReq.MsgData.RecvID = req.RecvID
|
||||||
|
|
||||||
// Declare a variable to store the message sending status.
|
|
||||||
var status int
|
|
||||||
|
|
||||||
// Attempt to send the message using the client.
|
// Attempt to send the message using the client.
|
||||||
respPb, err := m.Client.SendMsg(c, sendMsgReq)
|
respPb, err := m.Client.SendMsg(c, sendMsgReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Set the status to failed and respond with an error if sending fails.
|
// Set the status to failed and respond with an error if sending fails.
|
||||||
status = constant.MsgSendFailed
|
|
||||||
apiresp.GinError(c, err)
|
apiresp.GinError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the status to successful if the message is sent.
|
// Set the status to successful if the message is sent.
|
||||||
status = constant.MsgSendSuccessed
|
var status int = constant.MsgSendSuccessed
|
||||||
|
|
||||||
// Attempt to update the message sending status in the system.
|
// Attempt to update the message sending status in the system.
|
||||||
_, err = m.Client.SetSendMsgStatus(c, &msg.SetSendMsgStatusReq{
|
_, err = m.Client.SetSendMsgStatus(c, &msg.SetSendMsgStatusReq{
|
||||||
Status: int32(status),
|
Status: int32(status),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Log the error if updating the status fails.
|
// Log the error if updating the status fails.
|
||||||
apiresp.GinError(c, err)
|
apiresp.GinError(c, err)
|
||||||
|
@ -141,7 +141,6 @@ func (c *UserConnContext) GetBackground() bool {
|
|||||||
b, err := strconv.ParseBool(c.Req.URL.Query().Get(BackgroundStatus))
|
b, err := strconv.ParseBool(c.Req.URL.Query().Get(BackgroundStatus))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
} else {
|
|
||||||
return b
|
|
||||||
}
|
}
|
||||||
|
return b
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/tools/log"
|
"github.com/OpenIMSDK/tools/log"
|
||||||
"github.com/OpenIMSDK/tools/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserMap struct {
|
type UserMap struct {
|
||||||
@ -71,48 +70,65 @@ func (u *UserMap) Set(key string, v *Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserMap) delete(key string, connRemoteAddr string) (isDeleteUser bool) {
|
func (u *UserMap) delete(key string, connRemoteAddr string) (isDeleteUser bool) {
|
||||||
|
// Attempt to load the clients associated with the key.
|
||||||
allClients, existed := u.m.Load(key)
|
allClients, existed := u.m.Load(key)
|
||||||
if existed {
|
if !existed {
|
||||||
oldClients := allClients.([]*Client)
|
// Return false immediately if the key does not exist.
|
||||||
var a []*Client
|
return false
|
||||||
for _, client := range oldClients {
|
}
|
||||||
if client.ctx.GetRemoteAddr() != connRemoteAddr {
|
|
||||||
a = append(a, client)
|
// Convert allClients to a slice of *Client.
|
||||||
}
|
oldClients := allClients.([]*Client)
|
||||||
}
|
var remainingClients []*Client
|
||||||
if len(a) == 0 {
|
for _, client := range oldClients {
|
||||||
u.m.Delete(key)
|
// Keep clients that do not match the connRemoteAddr.
|
||||||
return true
|
if client.ctx.GetRemoteAddr() != connRemoteAddr {
|
||||||
} else {
|
remainingClients = append(remainingClients, client)
|
||||||
u.m.Store(key, a)
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return existed
|
|
||||||
|
// If no clients remain after filtering, delete the key from the map.
|
||||||
|
if len(remainingClients) == 0 {
|
||||||
|
u.m.Delete(key)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, update the key with the remaining clients.
|
||||||
|
u.m.Store(key, remainingClients)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserMap) deleteClients(key string, clients []*Client) (isDeleteUser bool) {
|
func (u *UserMap) deleteClients(key string, clientsToDelete []*Client) (isDeleteUser bool) {
|
||||||
m := utils.SliceToMapAny(clients, func(c *Client) (string, struct{}) {
|
// Convert the slice of clients to delete into a map for efficient lookup.
|
||||||
return c.ctx.GetRemoteAddr(), struct{}{}
|
deleteMap := make(map[string]struct{})
|
||||||
})
|
for _, client := range clientsToDelete {
|
||||||
|
deleteMap[client.ctx.GetRemoteAddr()] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the current clients associated with the key.
|
||||||
allClients, existed := u.m.Load(key)
|
allClients, existed := u.m.Load(key)
|
||||||
if existed {
|
if !existed {
|
||||||
oldClients := allClients.([]*Client)
|
// If the key doesn't exist, return false.
|
||||||
var a []*Client
|
return false
|
||||||
for _, client := range oldClients {
|
}
|
||||||
if _, ok := m[client.ctx.GetRemoteAddr()]; !ok {
|
|
||||||
a = append(a, client)
|
// Filter out clients that are in the deleteMap.
|
||||||
}
|
oldClients := allClients.([]*Client)
|
||||||
}
|
var remainingClients []*Client
|
||||||
if len(a) == 0 {
|
for _, client := range oldClients {
|
||||||
u.m.Delete(key)
|
if _, shouldBeDeleted := deleteMap[client.ctx.GetRemoteAddr()]; !shouldBeDeleted {
|
||||||
return true
|
remainingClients = append(remainingClients, client)
|
||||||
} else {
|
|
||||||
u.m.Store(key, a)
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return existed
|
|
||||||
|
// Update or delete the key based on the remaining clients.
|
||||||
|
if len(remainingClients) == 0 {
|
||||||
|
u.m.Delete(key)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
u.m.Store(key, remainingClients)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserMap) DeleteAll(key string) {
|
func (u *UserMap) DeleteAll(key string) {
|
||||||
|
@ -184,12 +184,11 @@ func (och *OnlineHistoryRedisConsumerHandler) getPushStorageMsgList(
|
|||||||
options2 := msgprocessor.Options(msg.Options)
|
options2 := msgprocessor.Options(msg.Options)
|
||||||
if options2.IsHistory() {
|
if options2.IsHistory() {
|
||||||
return true
|
return true
|
||||||
} else {
|
|
||||||
// if !(!options2.IsSenderSync() && conversationID == msg.MsgData.SendID) {
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
// if !(!options2.IsSenderSync() && conversationID == msg.MsgData.SendID) {
|
||||||
|
// return false
|
||||||
|
// }
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
for _, v := range totalMsgs {
|
for _, v := range totalMsgs {
|
||||||
options := msgprocessor.Options(v.message.Options)
|
options := msgprocessor.Options(v.message.Options)
|
||||||
|
@ -90,9 +90,8 @@ func (g *Client) Push(ctx context.Context, userIDs []string, title, content stri
|
|||||||
for i, v := range s.GetSplitResult() {
|
for i, v := range s.GetSplitResult() {
|
||||||
go func(index int, userIDs []string) {
|
go func(index int, userIDs []string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if err := g.batchPush(ctx, token, userIDs, pushReq); err != nil {
|
if err = g.batchPush(ctx, token, userIDs, pushReq); err != nil {
|
||||||
log.ZError(ctx, "batchPush failed", err, "index", index, "token", token, "req", pushReq)
|
log.ZError(ctx, "batchPush failed", err, "index", index, "token", token, "req", pushReq)
|
||||||
err = err
|
|
||||||
}
|
}
|
||||||
}(i, v.Item)
|
}(i, v.Item)
|
||||||
}
|
}
|
||||||
|
@ -90,9 +90,8 @@ func (r *pushServer) PushMsg(ctx context.Context, pbData *pbpush.PushMsgReq) (re
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if err != errNoOfflinePusher {
|
if err != errNoOfflinePusher {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
|
||||||
log.ZWarn(ctx, "offline push failed", err, "msg", pbData.String())
|
|
||||||
}
|
}
|
||||||
|
log.ZWarn(ctx, "offline push failed", err, "msg", pbData.String())
|
||||||
}
|
}
|
||||||
return &pbpush.PushMsgResp{}, nil
|
return &pbpush.PushMsgResp{}, nil
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ func GetContent(msg *sdkws.MsgData) string {
|
|||||||
_ = proto.Unmarshal(msg.Content, &tips)
|
_ = proto.Unmarshal(msg.Content, &tips)
|
||||||
content := tips.JsonDetail
|
content := tips.JsonDetail
|
||||||
return content
|
return content
|
||||||
} else {
|
|
||||||
return string(msg.Content)
|
|
||||||
}
|
}
|
||||||
|
return string(msg.Content)
|
||||||
}
|
}
|
||||||
|
@ -79,9 +79,14 @@ func (s *friendServer) AddBlack(ctx context.Context, req *pbfriend.AddBlackReq)
|
|||||||
CreateTime: time.Now(),
|
CreateTime: time.Now(),
|
||||||
Ex: req.Ex,
|
Ex: req.Ex,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.blackDatabase.Create(ctx, []*relation.BlackModel{&black}); err != nil {
|
if err := s.blackDatabase.Create(ctx, []*relation.BlackModel{&black}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.notificationSender.BlackAddedNotification(ctx, req)
|
|
||||||
|
if err := s.notificationSender.BlackAddedNotification(ctx, req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &pbfriend.AddBlackResp{}, nil
|
return &pbfriend.AddBlackResp{}, nil
|
||||||
}
|
}
|
||||||
|
@ -114,26 +114,36 @@ func (s *friendServer) ApplyToAddFriend(ctx context.Context, req *pbfriend.Apply
|
|||||||
if err := authverify.CheckAccessV3(ctx, req.FromUserID, s.config); err != nil {
|
if err := authverify.CheckAccessV3(ctx, req.FromUserID, s.config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.ToUserID == req.FromUserID {
|
if req.ToUserID == req.FromUserID {
|
||||||
return nil, errs.ErrCanNotAddYourself.Wrap("req.ToUserID", req.ToUserID)
|
return nil, errs.ErrCanNotAddYourself.Wrap("req.ToUserID", req.ToUserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = CallbackBeforeAddFriend(ctx, s.config, req); err != nil && err != errs.ErrCallbackContinue {
|
if err = CallbackBeforeAddFriend(ctx, s.config, req); err != nil && err != errs.ErrCallbackContinue {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := s.userRpcClient.GetUsersInfoMap(ctx, []string{req.ToUserID, req.FromUserID}); err != nil {
|
if _, err := s.userRpcClient.GetUsersInfoMap(ctx, []string{req.ToUserID, req.FromUserID}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
in1, in2, err := s.friendDatabase.CheckIn(ctx, req.FromUserID, req.ToUserID)
|
in1, in2, err := s.friendDatabase.CheckIn(ctx, req.FromUserID, req.ToUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if in1 && in2 {
|
if in1 && in2 {
|
||||||
return nil, errs.ErrRelationshipAlready.Wrap()
|
return nil, errs.ErrRelationshipAlready.Wrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = s.friendDatabase.AddFriendRequest(ctx, req.FromUserID, req.ToUserID, req.ReqMsg, req.Ex); err != nil {
|
if err = s.friendDatabase.AddFriendRequest(ctx, req.FromUserID, req.ToUserID, req.ReqMsg, req.Ex); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.notificationSender.FriendApplicationAddNotification(ctx, req)
|
|
||||||
|
if err = s.notificationSender.FriendApplicationAddNotification(ctx, req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if err = CallbackAfterAddFriend(ctx, s.config, req); err != nil && err != errs.ErrCallbackContinue {
|
if err = CallbackAfterAddFriend(ctx, s.config, req); err != nil && err != errs.ErrCallbackContinue {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -197,7 +207,9 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbfriend.Res
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.notificationSender.FriendApplicationAgreedNotification(ctx, req)
|
if err := s.notificationSender.FriendApplicationAgreedNotification(ctx, req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
if req.HandleResult == constant.FriendResponseRefuse {
|
if req.HandleResult == constant.FriendResponseRefuse {
|
||||||
|
@ -637,6 +637,7 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbgroup.GetG
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupApplicationList handles functions that get a list of group requests
|
||||||
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) {
|
||||||
groupIDs, err := s.db.FindUserManagedGroupID(ctx, req.FromUserID)
|
groupIDs, err := s.db.FindUserManagedGroupID(ctx, req.FromUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -126,10 +126,7 @@ func (f *FriendNotificationSender) UserInfoUpdatedNotification(ctx context.Conte
|
|||||||
return f.Notification(ctx, mcontext.GetOpUserID(ctx), changedUserID, constant.UserInfoUpdatedNotification, &tips)
|
return f.Notification(ctx, mcontext.GetOpUserID(ctx), changedUserID, constant.UserInfoUpdatedNotification, &tips)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendNotificationSender) FriendApplicationAddNotification(
|
func (f *FriendNotificationSender) FriendApplicationAddNotification(ctx context.Context, req *pbfriend.ApplyToAddFriendReq) error {
|
||||||
ctx context.Context,
|
|
||||||
req *pbfriend.ApplyToAddFriendReq,
|
|
||||||
) error {
|
|
||||||
tips := sdkws.FriendApplicationTips{FromToUserID: &sdkws.FromToUserID{
|
tips := sdkws.FriendApplicationTips{FromToUserID: &sdkws.FromToUserID{
|
||||||
FromUserID: req.FromUserID,
|
FromUserID: req.FromUserID,
|
||||||
ToUserID: req.ToUserID,
|
ToUserID: req.ToUserID,
|
||||||
|
@ -932,7 +932,7 @@ openim::test::set_group_info() {
|
|||||||
{
|
{
|
||||||
"groupInfoForSet": {
|
"groupInfoForSet": {
|
||||||
"groupID": "${1}",
|
"groupID": "${1}",
|
||||||
"groupName": "new-name",
|
"groupName": "new group name",
|
||||||
"notification": "new notification",
|
"notification": "new notification",
|
||||||
"introduction": "new introduction",
|
"introduction": "new introduction",
|
||||||
"faceURL": "www.newfaceURL.com",
|
"faceURL": "www.newfaceURL.com",
|
||||||
@ -1076,6 +1076,7 @@ function openim::test::group() {
|
|||||||
|
|
||||||
local GROUP_ID=$RANDOM
|
local GROUP_ID=$RANDOM
|
||||||
local GROUP_ID2=$RANDOM
|
local GROUP_ID2=$RANDOM
|
||||||
|
|
||||||
# Assumes that TEST_GROUP_ID, USER_ID, and other necessary IDs are set as environment variables before running this suite.
|
# Assumes that TEST_GROUP_ID, USER_ID, and other necessary IDs are set as environment variables before running this suite.
|
||||||
# 0. Register a friend user.
|
# 0. Register a friend user.
|
||||||
openim::test::user_register "${USER_ID}" "group00" "new_face_url"
|
openim::test::user_register "${USER_ID}" "group00" "new_face_url"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user