Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
wangchuxiao-dev committed Jul 26, 2023
2 parents 7acc584 + a1b4bbd commit 26cc0db
Show file tree
Hide file tree
Showing 30 changed files with 2,000 additions and 492 deletions.
923 changes: 921 additions & 2 deletions .golangci.yml

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,15 @@ changelog:
nfpms:
- id: packages
builds:
- admin_api
- chat_api
- chat_rpc
- admin_rpc
- openim-sdk-core
# Your app's vendor.
vendor: OpenIMSDK
homepage: https://github.com/OpenIMSDK/chat
homepage: https://github.com/OpenIMSDK/openim-sdk-core
maintainer: kubbot <https://github.com/kubbot>
description: |-
Auto sync github labels
kubbot && openimbot
license: MIT
license: Apache-2.0
formats:
- apk
- deb
Expand Down
20 changes: 10 additions & 10 deletions internal/conversation_msg/conversation_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ func (c *Conversation) Work(c2v common.Cmd2Value) {
case constant.CmdNewMsgCome:
c.doMsgNew(c2v)
case constant.CmdSuperGroupMsgCome:
//c.doSuperGroupMsgNew(c2v)
// c.doSuperGroupMsgNew(c2v)
case constant.CmdUpdateConversation:
c.doUpdateConversation(c2v)
case constant.CmdUpdateMessage:
c.doUpdateMessage(c2v)
case constant.CmSyncReactionExtensions:
//c.doSyncReactionExtensions(c2v)
// c.doSyncReactionExtensions(c2v)
case constant.CmdNotification:
c.doNotificationNew(c2v)
}
Expand All @@ -52,13 +52,13 @@ func (c *Conversation) Work(c2v common.Cmd2Value) {
func (c *Conversation) doDeleteConversation(c2v common.Cmd2Value) {
node := c2v.Value.(common.DeleteConNode)
ctx := c2v.Ctx
//Mark messages related to this conversation for deletion
// Mark messages related to this conversation for deletion
err := c.db.UpdateMessageStatusBySourceID(context.Background(), node.SourceID, constant.MsgStatusHasDeleted, int32(node.SessionType))
if err != nil {
log.ZError(ctx, "setMessageStatusBySourceID", err)
return
}
//Reset the session information, empty session
// Reset the session information, empty session
err = c.db.ResetConversation(ctx, node.ConversationID)
if err != nil {
log.ZError(ctx, "ResetConversation err:", err)
Expand All @@ -80,7 +80,7 @@ func (c *Conversation) doUpdateConversation(c2v common.Cmd2Value) {
oc, err := c.db.GetConversation(ctx, lc.ConversationID)
if err == nil {
// log.Info("this is old conversation", *oc)
if lc.LatestMsgSendTime >= oc.LatestMsgSendTime { //The session update of asynchronous messages is subject to the latest sending time
if lc.LatestMsgSendTime >= oc.LatestMsgSendTime { // The session update of asynchronous messages is subject to the latest sending time
err := c.db.UpdateColumnsConversation(ctx, node.ConID, map[string]interface{}{"latest_msg_send_time": lc.LatestMsgSendTime, "latest_msg": lc.LatestMsg})
if err != nil {
// log.Error("internal", "updateConversationLatestMsgModel err: ", err)
Expand Down Expand Up @@ -114,7 +114,7 @@ func (c *Conversation) doUpdateConversation(c2v common.Cmd2Value) {
}

}
//case ConChange:
// case ConChange:
// err, list := u.getAllConversationListModel()
// if err != nil {
// sdkLog("getAllConversationListModel database err:", err.Error())
Expand Down Expand Up @@ -322,7 +322,7 @@ func (c *Conversation) doUpdateMessage(c2v common.Cmd2Value) {

}

//funcation (c *Conversation) doSyncReactionExtensions(c2v common.Cmd2Value) {
// funcation (c *Conversation) doSyncReactionExtensions(c2v common.Cmd2Value) {
// if c.ConversationListener == nil {
// // log.Error("internal", "not set conversationListener")
// return
Expand Down Expand Up @@ -582,7 +582,7 @@ func (c *Conversation) doUpdateMessage(c2v common.Cmd2Value) {
//
// }
//
//}
// }

func (c *Conversation) DoConversationChangedNotification(ctx context.Context, msg *sdkws.MsgData) {
if msg.SendTime < c.LoginTime() || c.LoginTime() == 0 {
Expand Down Expand Up @@ -631,14 +631,14 @@ func (c *Conversation) doNotificationNew(c2v common.Cmd2Value) {
ctx := c2v.Ctx
allMsg := c2v.Value.(sdk_struct.CmdNewMsgComeToConversation).Msgs
syncFlag := c2v.Value.(sdk_struct.CmdNewMsgComeToConversation).SyncFlag
//if c.msgListener == nil || c.ConversationListener == nil {
// if c.msgListener == nil || c.ConversationListener == nil {
// for _, v := range allMsg {
// if v.ContentType > constant.SignalingNotificationBegin && v.ContentType < constant.SignalingNotificationEnd {
// c.signaling.DoNotification(ctx, v, c.GetCh())
// }
// }
// return
//}
// }
switch syncFlag {
case constant.MsgSyncBegin:
c.ConversationListener.OnSyncServerStart()
Expand Down
27 changes: 14 additions & 13 deletions internal/conversation_msg/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func NewUploadFileCallback(ctx context.Context, progress func(progress int), msg
if msg.AttachedInfoElem.Progress == nil {
msg.AttachedInfoElem.Progress = &sdk_struct.UploadProgress{}
}
return &msgUploadFileCallback{ctx: ctx, progress: progress, msg: msg, db: db, conversationID: conversationID}
// return &msgUploadFileCallback{ctx: ctx, progress: progress, msg: msg, db: db, conversationID: conversationID}
return nil
}

type msgUploadFileCallback struct {
Expand Down Expand Up @@ -99,34 +100,34 @@ func (c *msgUploadFileCallback) Complete(size int64, url string, typ int) {
}
}

//func NewFileCallback(ctx context.Context, progress func(progress int), msg *sdk_struct.MsgStruct, conversationID string, db db_interface.DataBase) file.PutFileCallback {
// func NewFileCallback(ctx context.Context, progress func(progress int), msg *sdk_struct.MsgStruct, conversationID string, db db_interface.DataBase) file.PutFileCallback {
// if msg.AttachedInfoElem == nil {
// msg.AttachedInfoElem = &sdk_struct.AttachedInfoElem{}
// }
// if msg.AttachedInfoElem.Progress == nil {
// msg.AttachedInfoElem.Progress = &sdk_struct.UploadProgress{}
// }
// return &FileCallback{ctx: ctx, progress: progress, msg: msg, db: db, conversationID: conversationID}
//}
// }
//
//type FileCallback struct {
// type FileCallback struct {
// ctx context.Context
// db db_interface.DataBase
// msg *sdk_struct.MsgStruct
// conversationID string
// value int
// progress func(progress int)
//}
// }
//
//func (c *FileCallback) Open(size int64) {}
// func (c *FileCallback) Open(size int64) {}
//
//func (c *FileCallback) HashProgress(current, total int64) {}
// func (c *FileCallback) HashProgress(current, total int64) {}
//
//func (c *FileCallback) HashComplete(hash string, total int64) {}
// func (c *FileCallback) HashComplete(hash string, total int64) {}
//
//func (c *FileCallback) PutStart(current, total int64) {}
// func (c *FileCallback) PutStart(current, total int64) {}
//
//func (c *FileCallback) PutProgress(save int64, current, total int64) {
// func (c *FileCallback) PutProgress(save int64, current, total int64) {
// c.msg.AttachedInfoElem.Progress.Save = save
// c.msg.AttachedInfoElem.Progress.Current = current
// c.msg.AttachedInfoElem.Progress.Total = total
Expand All @@ -142,9 +143,9 @@ func (c *msgUploadFileCallback) Complete(size int64, url string, typ int) {
// c.value = value
// c.progress(value)
// }
//}
// }
//
//func (c *FileCallback) PutComplete(total int64, putType int) {
// func (c *FileCallback) PutComplete(total int64, putType int) {
// c.msg.AttachedInfoElem.Progress = nil
// data, err := json.Marshal(c.msg.AttachedInfoElem)
// if err != nil {
Expand All @@ -153,4 +154,4 @@ func (c *msgUploadFileCallback) Complete(size int64, url string, typ int) {
// if err := c.db.UpdateColumnsMessage(c.ctx, c.conversationID, c.msg.ClientMsgID, map[string]any{"attached_info": string(data)}); err != nil {
// log.ZError(c.ctx, "update PutComplete message attached info failed", err)
// }
//}
// }
22 changes: 16 additions & 6 deletions internal/conversation_msg/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"open_im_sdk/open_im_sdk_callback"
"open_im_sdk/pkg/common"
"open_im_sdk/pkg/constant"
"open_im_sdk/pkg/content_type"
"open_im_sdk/pkg/db/model_struct"
"open_im_sdk/pkg/sdkerrs"
"path/filepath"
Expand Down Expand Up @@ -293,8 +294,9 @@ func (c *Conversation) updateMsgStatusAndTriggerConversation(ctx context.Context
}

func (c *Conversation) fileName(ftype string, id string) string {
return fmt.Sprintf("%s_%s_%s", c.loginUserID, ftype, id)
return fmt.Sprintf("msg_%s_%s", ftype, id)
}

func (c *Conversation) checkID(ctx context.Context, s *sdk_struct.MsgStruct,
recvID, groupID string, options map[string]bool) (*model_struct.LocalConversation, error) {
if recvID == "" && groupID == "" {
Expand Down Expand Up @@ -517,7 +519,7 @@ func (c *Conversation) SendMessage(ctx context.Context, s *sdk_struct.MsgStruct,
go func() {
defer wg.Done()
res, err := c.file.UploadFile(ctx, &file.UploadFileReq{
ContentType: s.VideoElem.VideoType,
ContentType: content_type.GetType(s.VideoElem.VideoType, filepath.Ext(s.VideoElem.VideoPath)),
Filepath: videoPath,
Uuid: s.VideoElem.VideoUUID,
Name: c.fileName("video", s.ClientMsgID) + filepath.Ext(videoPath),
Expand All @@ -539,11 +541,19 @@ func (c *Conversation) SendMessage(ctx context.Context, s *sdk_struct.MsgStruct,
s.Content = utils.StructToJsonString(s.FileElem)
break
}
name := s.FileElem.FileName
if name == "" {
name = s.FileElem.FilePath
}
if name == "" {
name = fmt.Sprintf("msg_file_%s.unknown", s.ClientMsgID)
}
res, err := c.file.UploadFile(ctx, &file.UploadFileReq{
Filepath: s.FileElem.FilePath,
Uuid: s.FileElem.UUID,
Name: c.fileName("file", s.ClientMsgID) + filepath.Ext(s.FileElem.FilePath),
Cause: "msg-file",
ContentType: content_type.GetType(s.FileElem.FileType, filepath.Ext(s.FileElem.FilePath), filepath.Ext(s.FileElem.FileName)),
Filepath: s.FileElem.FilePath,
Uuid: s.FileElem.UUID,
Name: c.fileName("file", s.ClientMsgID) + "/" + filepath.Base(name),
Cause: "msg-file",
}, NewUploadFileCallback(ctx, callback.OnProgress, s, lc.ConversationID, c.db))
if err != nil {
c.updateMsgStatusAndTriggerConversation(ctx, s.ClientMsgID, "", s.CreateTime, constant.MsgStatusSendFailed, s, lc)
Expand Down
20 changes: 10 additions & 10 deletions internal/group/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
"github.com/OpenIMSDK/tools/utils"
)

//// deprecated use CreateGroup
//funcation (g *Group) CreateGroup(ctx context.Context, groupBaseInfo sdk_params_callback.CreateGroupBaseInfoParam, memberList sdk_params_callback.CreateGroupMemberRoleParam) (*sdkws.GroupInfo, error) {
// // deprecated use CreateGroup
// funcation (g *Group) CreateGroup(ctx context.Context, groupBaseInfo sdk_params_callback.CreateGroupBaseInfoParam, memberList sdk_params_callback.CreateGroupMemberRoleParam) (*sdkws.GroupInfo, error) {
// req := &group.CreateGroupReq{
// GroupInfo: &sdkws.GroupInfo{
// GroupName: groupBaseInfo.GroupName,
Expand All @@ -59,7 +59,7 @@ import (
// }
// }
// return g.CreateGroup(ctx, req)
//}
// }

func (g *Group) CreateGroup(ctx context.Context, req *group.CreateGroupReq) (*sdkws.GroupInfo, error) {
if req.OwnerUserID == "" {
Expand Down Expand Up @@ -90,10 +90,10 @@ func (g *Group) JoinGroup(ctx context.Context, groupID, reqMsg string, joinSourc
return err
}
// if err := g.SyncJoinedGroup(ctx); err != nil {
// return err
// return err
// }
// if err := g.SyncGroupMember(ctx, groupID); err != nil {
// return err
// return err
// }
return nil
}
Expand All @@ -108,9 +108,9 @@ func (g *Group) QuitGroup(ctx context.Context, groupID string) error {
if err := g.deleteGroup(ctx, groupID); err != nil {
return err
}
//if err := g.SyncGroupMember(ctx, groupID); err != nil {
// if err := g.SyncGroupMember(ctx, groupID); err != nil {
// return err
//}
// }
return nil
}

Expand Down Expand Up @@ -223,7 +223,7 @@ func (g *Group) SearchGroups(ctx context.Context, param sdk_params_callback.Sear
return groups, nil
}

//funcation (g *Group) SetGroupInfo(ctx context.Context, groupInfo *sdk_params_callback.SetGroupInfoParam, groupID string) error {
// funcation (g *Group) SetGroupInfo(ctx context.Context, groupInfo *sdk_params_callback.SetGroupInfoParam, groupID string) error {
// return g.SetGroupInfo(ctx, &sdkws.GroupInfoForSet{
// GroupID: groupID,
// GroupName: groupInfo.GroupName,
Expand All @@ -233,7 +233,7 @@ func (g *Group) SearchGroups(ctx context.Context, param sdk_params_callback.Sear
// Ex: groupInfo.Ex,
// NeedVerification: wrapperspb.Int32Ptr(groupInfo.NeedVerification),
// })
//}
// }

func (g *Group) SetGroupVerification(ctx context.Context, groupID string, verification int32) error {
return g.SetGroupInfo(ctx, &sdkws.GroupInfoForSet{GroupID: groupID, NeedVerification: wrapperspb.Int32(verification)})
Expand Down Expand Up @@ -299,7 +299,7 @@ func (g *Group) TransferGroupOwner(ctx context.Context, groupID, newOwnerUserID

func (g *Group) InviteUserToGroup(ctx context.Context, groupID, reason string, userIDList []string) error {
if err := util.ApiPost(ctx, constant.InviteUserToGroupRouter, &group.InviteUserToGroupReq{GroupID: groupID, Reason: reason, InvitedUserIDs: userIDList}, nil); err != nil {
return nil
return err
}
if err := g.SyncGroups(ctx, groupID); err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion open_im_sdk/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ import (
func UploadFile(callback open_im_sdk_callback.Base, operationID string, req string, progress open_im_sdk_callback.UploadFileCallback) {
call(callback, operationID, UserForSDK.File().UploadFile, req, file.UploadFileCallback(progress))
}

15 changes: 10 additions & 5 deletions pkg/constant/server_api_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
UpdateSelfUserInfoRouter = "/user/update_user_info"
SetGlobalRecvMessageOptRouter = "/user/set_global_msg_recv_opt"
GetUsersInfoFromCacheRouter = "/user/get_users_info_from_cache"
AccountCheck = "/user/account_check"
UserRegister = "/user/user_register"

AddFriendRouter = "/friend/add_friend"
DeleteFriendRouter = "/friend/delete_friend"
Expand All @@ -41,7 +43,7 @@ const (
PullUserMsgBySeqRouter = "/chat/pull_msg_by_seq"
NewestSeqRouter = "/chat/newest_seq"

//msg
// msg
ClearConversationMsgRouter = RouterMsg + "/clear_conversation_msg" // Clear the message of the specified conversation
ClearAllMsgRouter = RouterMsg + "/user_clear_all_msg" // Clear all messages of the current user
DeleteMsgsRouter = RouterMsg + "/delete_msgs" // Delete the specified message
Expand All @@ -63,7 +65,7 @@ const (
MinioStorageCredentialRouter = "/third/minio_storage_credential"
AwsStorageCredentialRouter = "/third/aws_storage_credential"

//group
// group
CreateGroupRouter = RouterGroup + "/create_group"
SetGroupInfoRouter = RouterGroup + "/set_group_info"
JoinGroupRouter = RouterGroup + "/join_group"
Expand Down Expand Up @@ -100,18 +102,21 @@ const (
ModifyConversationFieldRouter = ConversationGroup + "/modify_conversation_field"
SetConversationsRouter = ConversationGroup + "/set_conversations"

//organization
// organization
GetSubDepartmentRouter = RouterOrganization + "/get_sub_department"
GetDepartmentMemberRouter = RouterOrganization + "/get_department_member"
ParseTokenRouter = RouterAuth + "/parse_token"

//super_group
// super_group
GetJoinedSuperGroupListRouter = RouterSuperGroup + "/get_joined_group_list"
GetSuperGroupsInfoRouter = RouterSuperGroup + "/get_groups_info"

//third
// third
FcmUpdateTokenRouter = RouterThird + "/fcm_update_token"
SetAppBadgeRouter = RouterThird + "/set_app_badge"

// auth
GetUsersToken = RouterAuth + "/user_token"
)
const (
RouterGroup = "/group"
Expand Down
Loading

0 comments on commit 26cc0db

Please sign in to comment.