mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 02:42:19 +08:00
Merge branch 'release-v3.5local' into add_set_ex_friend
This commit is contained in:
commit
7e3fca1d5a
2
go.mod
2
go.mod
@ -4,7 +4,7 @@ go 1.19
|
||||
|
||||
require (
|
||||
firebase.google.com/go v3.13.0+incompatible
|
||||
github.com/OpenIMSDK/protocol v0.0.46
|
||||
github.com/OpenIMSDK/protocol v0.0.47
|
||||
github.com/OpenIMSDK/tools v0.0.23
|
||||
github.com/bwmarrin/snowflake v0.3.0 // indirect
|
||||
github.com/dtm-labs/rockscache v0.1.1
|
||||
|
||||
@ -33,8 +33,8 @@ func (o *ConversationApi) GetAllConversations(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.GetAllConversations, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *ConversationApi) GetConversationsList(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.GetConversationList, o.Client, c)
|
||||
func (o *ConversationApi) GetSortedConversationList(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.GetSortedConversationList, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *ConversationApi) GetConversation(c *gin.Context) {
|
||||
|
||||
@ -205,7 +205,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
|
||||
conversationGroup := r.Group("/conversation", ParseToken)
|
||||
{
|
||||
c := NewConversationApi(*conversationRpc)
|
||||
conversationGroup.POST("/get_conversations_list", c.GetConversationsList)
|
||||
conversationGroup.POST("/get_sorted_conversation_list", c.GetSortedConversationList)
|
||||
conversationGroup.POST("/get_all_conversations", c.GetAllConversations)
|
||||
conversationGroup.POST("/get_conversation", c.GetConversation)
|
||||
conversationGroup.POST("/get_conversations", c.GetConversations)
|
||||
|
||||
@ -89,8 +89,8 @@ func (c *conversationServer) GetConversation(ctx context.Context, req *pbconvers
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (m *conversationServer) GetConversationList(ctx context.Context, req *pbconversation.GetConversationListReq) (resp *pbconversation.GetConversationListResp, err error) {
|
||||
log.ZDebug(ctx, "GetConversationList", "seqs", req, "userID", req.UserID)
|
||||
func (m *conversationServer) GetSortedConversationList(ctx context.Context, req *pbconversation.GetSortedConversationListReq) (resp *pbconversation.GetSortedConversationListResp, err error) {
|
||||
log.ZDebug(ctx, "GetSortedConversationList", "seqs", req, "userID", req.UserID)
|
||||
var conversationIDs []string
|
||||
if len(req.ConversationIDs) == 0 {
|
||||
conversationIDs, err = m.conversationDatabase.GetConversationIDs(ctx, req.UserID)
|
||||
@ -129,30 +129,37 @@ func (m *conversationServer) GetConversationList(ctx context.Context, req *pbcon
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var unreadTotal int64
|
||||
conversation_unreadCount := make(map[string]int64)
|
||||
for conversationID, maxSeq := range maxSeqs {
|
||||
conversation_unreadCount[conversationID] = maxSeq - hasReadSeqs[conversationID]
|
||||
unreadCount := maxSeq - hasReadSeqs[conversationID]
|
||||
conversation_unreadCount[conversationID] = unreadCount
|
||||
unreadTotal += unreadCount
|
||||
}
|
||||
|
||||
conversation_isPinkTime := make(map[int64]string)
|
||||
conversation_notPinkTime := make(map[int64]string)
|
||||
conversation_isPinTime := make(map[int64]string)
|
||||
conversation_notPinTime := make(map[int64]string)
|
||||
for _, v := range conversations {
|
||||
conversationID := v.ConversationID
|
||||
time := conversationMsg[conversationID].MsgInfo.LatestMsgRecvTime
|
||||
conversationMsg[conversationID].RecvMsgOpt = v.RecvMsgOpt
|
||||
if v.IsPinned {
|
||||
conversationMsg[conversationID].IsPinned = v.IsPinned
|
||||
conversation_isPinkTime[time] = conversationID
|
||||
conversation_isPinTime[time] = conversationID
|
||||
continue
|
||||
}
|
||||
conversation_notPinkTime[time] = conversationID
|
||||
conversation_notPinTime[time] = conversationID
|
||||
}
|
||||
resp = &pbconversation.GetConversationListResp{
|
||||
resp = &pbconversation.GetSortedConversationListResp{
|
||||
ConversationTotal: int64(len(chatLogs)),
|
||||
ConversationElems: []*pbconversation.ConversationElem{},
|
||||
UnreadTotal: unreadTotal,
|
||||
}
|
||||
|
||||
m.conversationSort(conversation_isPinkTime, resp, conversation_unreadCount, conversationMsg)
|
||||
m.conversationSort(conversation_notPinkTime, resp, conversation_unreadCount, conversationMsg)
|
||||
m.conversationSort(conversation_isPinTime, resp, conversation_unreadCount, conversationMsg)
|
||||
m.conversationSort(conversation_notPinTime, resp, conversation_unreadCount, conversationMsg)
|
||||
|
||||
resp.ConversationElems = utils.Paginate(resp.ConversationElems, int(req.Pagination.GetPageNumber()), int(req.Pagination.GetShowNumber()))
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@ -425,7 +432,7 @@ func (c *conversationServer) GetConversationOfflinePushUserIDs(
|
||||
|
||||
func (c *conversationServer) conversationSort(
|
||||
conversations map[int64]string,
|
||||
resp *pbconversation.GetConversationListResp,
|
||||
resp *pbconversation.GetSortedConversationListResp,
|
||||
conversation_unreadCount map[string]int64,
|
||||
conversationMsg map[string]*pbconversation.ConversationElem,
|
||||
) {
|
||||
|
||||
@ -59,6 +59,11 @@ type userServer struct {
|
||||
RegisterCenter registry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func (s *userServer) ProcessUserCommandGetAll(ctx context.Context, req *pbuser.ProcessUserCommandGetAllReq) (*pbuser.ProcessUserCommandGetAllResp, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||
rdb, err := cache.NewRedis()
|
||||
if err != nil {
|
||||
@ -229,7 +234,7 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckR
|
||||
}
|
||||
|
||||
func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPaginationUsersReq) (resp *pbuser.GetPaginationUsersResp, err error) {
|
||||
total, users, err := s.PageFindUser(ctx, constant.IMOrdinaryUser, req.Pagination)
|
||||
total, users, err := s.PageFindUser(ctx, constant.IMOrdinaryUser, constant.AppOrdinaryUsers, req.Pagination)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -542,6 +547,7 @@ func (s *userServer) AddNotificationAccount(ctx context.Context, req *pbuser.Add
|
||||
}
|
||||
|
||||
user := &tablerelation.UserModel{
|
||||
UserID: req.UserID,
|
||||
UserID: req.UserID,
|
||||
Nickname: req.NickName,
|
||||
FaceURL: req.FaceURL,
|
||||
@ -557,6 +563,11 @@ func (s *userServer) AddNotificationAccount(ctx context.Context, req *pbuser.Add
|
||||
NickName: req.NickName,
|
||||
FaceURL: req.FaceURL,
|
||||
}, nil
|
||||
return &pbuser.AddNotificationAccountResp{
|
||||
UserID: req.UserID,
|
||||
NickName: req.NickName,
|
||||
FaceURL: req.FaceURL,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *userServer) UpdateNotificationAccountInfo(ctx context.Context, req *pbuser.UpdateNotificationAccountInfoReq) (*pbuser.UpdateNotificationAccountInfoResp, error) {
|
||||
@ -590,6 +601,10 @@ func (s *userServer) SearchNotificationAccount(ctx context.Context, req *pbuser.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var users []*relation.UserModel
|
||||
var err error
|
||||
if req.Keyword != "" {
|
||||
users, err = s.UserDatabase.Find(ctx, []string{req.Keyword})
|
||||
var users []*relation.UserModel
|
||||
var err error
|
||||
if req.Keyword != "" {
|
||||
@ -616,6 +631,7 @@ func (s *userServer) SearchNotificationAccount(ctx context.Context, req *pbuser.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp := s.userModelToResp(users, req.Pagination)
|
||||
resp := s.userModelToResp(users, req.Pagination)
|
||||
return resp, nil
|
||||
}
|
||||
@ -668,4 +684,8 @@ func (s *userServer) userModelToResp(users []*relation.UserModel, pagination pag
|
||||
notificationAccounts := utils.Paginate(accounts, int(pagination.GetPageNumber()), int(pagination.GetShowNumber()))
|
||||
|
||||
return &pbuser.SearchNotificationAccountResp{Total: total, NotificationAccounts: notificationAccounts}
|
||||
|
||||
notificationAccounts := utils.Paginate(accounts, int(pagination.GetPageNumber()), int(pagination.GetShowNumber()))
|
||||
|
||||
return &pbuser.SearchNotificationAccountResp{Total: total, NotificationAccounts: notificationAccounts}
|
||||
}
|
||||
|
||||
@ -48,6 +48,8 @@ type UserDatabase interface {
|
||||
//Update(ctx context.Context, user *relation.UserModel) (err error)
|
||||
// UpdateByMap update (zero value) external guarantee userID exists
|
||||
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
|
||||
// FindUser
|
||||
PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
|
||||
// Page If not found, no error is returned
|
||||
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
|
||||
// FindUser
|
||||
@ -185,8 +187,8 @@ func (u *userDatabase) Page(ctx context.Context, pagination pagination.Paginatio
|
||||
return u.userDB.Page(ctx, pagination)
|
||||
}
|
||||
|
||||
func (u *userDatabase) PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
|
||||
return u.userDB.PageFindUser(ctx, level, pagination)
|
||||
func (u *userDatabase) PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
|
||||
return u.userDB.PageFindUser(ctx, level1, level2, pagination)
|
||||
}
|
||||
|
||||
// IsExist Does userIDs exist? As long as there is one, it will be true.
|
||||
|
||||
@ -78,12 +78,19 @@ func (u *UserMgo) Page(ctx context.Context, pagination pagination.Pagination) (c
|
||||
return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, bson.M{}, pagination)
|
||||
}
|
||||
|
||||
func (u *UserMgo) PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
|
||||
return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, bson.M{"app_manger_level": level}, pagination)
|
||||
func (u *UserMgo) PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
|
||||
query := bson.M{
|
||||
"$or": []bson.M{
|
||||
{"app_manager_level": level1},
|
||||
{"app_manager_level": level2},
|
||||
},
|
||||
}
|
||||
|
||||
return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, query, pagination)
|
||||
}
|
||||
|
||||
func (u *UserMgo) GetAllUserID(ctx context.Context, pagination pagination.Pagination) (int64, []string, error) {
|
||||
return mgoutil.FindPage[string](ctx, u.coll, bson.M{}, pagination, options.Find().SetProjection(bson.M{"user_id": 1}))
|
||||
return mgoutil.FindPage[string](ctx, u.coll, bson.M{}, pagination, options.Find().SetProjection(bson.M{"_id": 0, "user_id": 1}))
|
||||
}
|
||||
|
||||
func (u *UserMgo) Exist(ctx context.Context, userID string) (exist bool, err error) {
|
||||
@ -91,7 +98,7 @@ func (u *UserMgo) Exist(ctx context.Context, userID string) (exist bool, err err
|
||||
}
|
||||
|
||||
func (u *UserMgo) GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error) {
|
||||
return mgoutil.FindOne[int](ctx, u.coll, bson.M{"user_id": userID}, options.FindOne().SetProjection(bson.M{"global_recv_msg_opt": 1}))
|
||||
return mgoutil.FindOne[int](ctx, u.coll, bson.M{"user_id": userID}, options.FindOne().SetProjection(bson.M{"_id": 0, "global_recv_msg_opt": 1}))
|
||||
}
|
||||
|
||||
func (u *UserMgo) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) {
|
||||
|
||||
@ -56,7 +56,7 @@ type UserModelInterface interface {
|
||||
TakeNotification(ctx context.Context, level int64) (user []*UserModel, err error)
|
||||
TakeByNickname(ctx context.Context, nickname string) (user []*UserModel, err error)
|
||||
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
|
||||
PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
|
||||
PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
|
||||
Exist(ctx context.Context, userID string) (exist bool, err error)
|
||||
GetAllUserID(ctx context.Context, pagination pagination.Pagination) (count int64, userIDs []string, err error)
|
||||
GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)
|
||||
|
||||
@ -409,11 +409,16 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tips := &sdkws.GroupApplicationAcceptedTips{Group: group, HandleMsg: req.HandledMsg, ReceiverAs: 1}
|
||||
tips := &sdkws.GroupApplicationAcceptedTips{Group: group, HandleMsg: req.HandledMsg}
|
||||
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, userID := range append(userIDs, mcontext.GetOpUserID(ctx)) {
|
||||
for _, userID := range append(userIDs, req.FromUserID) {
|
||||
if userID == req.FromUserID {
|
||||
tips.ReceiverAs = 0
|
||||
} else {
|
||||
tips.ReceiverAs = 1
|
||||
}
|
||||
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.GroupApplicationAcceptedNotification, tips)
|
||||
if err != nil {
|
||||
log.ZError(ctx, "failed", err)
|
||||
@ -441,7 +446,12 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte
|
||||
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, userID := range append(userIDs, mcontext.GetOpUserID(ctx)) {
|
||||
for _, userID := range append(userIDs, req.FromUserID) {
|
||||
if userID == req.FromUserID {
|
||||
tips.ReceiverAs = 0
|
||||
} else {
|
||||
tips.ReceiverAs = 1
|
||||
}
|
||||
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.GroupApplicationRejectedNotification, tips)
|
||||
if err != nil {
|
||||
log.ZError(ctx, "failed", err)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user