Skip to content

Commit

Permalink
feat: get group list add page function.
Browse files Browse the repository at this point in the history
  • Loading branch information
FGadvancer committed Jun 27, 2024
1 parent 6994376 commit 5e51f9f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
3 changes: 1 addition & 2 deletions internal/conversation_msg/conversation_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (c *Conversation) doNotificationNew(c2v common.Cmd2Value) {
}

syncFunctions := []func(c context.Context) error{
c.group.SyncAllJoinedGroupsAndMembers, c.friend.IncrSyncFriends,
c.group.SyncAllJoinedGroupsAndMembers, c.friend.IncrSyncFriends, c.SyncAllConversations,
}

for _, syncFunc := range syncFunctions {
Expand All @@ -92,7 +92,6 @@ func (c *Conversation) doNotificationNew(c2v common.Cmd2Value) {
case constant.MsgSyncEnd:
log.ZDebug(ctx, "MsgSyncEnd", "time", time.Since(c.startTime).Milliseconds())
defer c.ConversationListener().OnSyncServerFinish()
go c.SyncAllConversations(ctx)
}

for conversationID, msgs := range allMsg {
Expand Down
8 changes: 4 additions & 4 deletions internal/conversation_msg/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/openimsdk/tools/log"
)

func (c *Conversation) SyncConversationsAndTriggerCallback(ctx context.Context, conversationsOnServer []*model_struct.LocalConversation) error {
func (c *Conversation) SyncConversationsAndTriggerCallback(ctx context.Context, conversationsOnServer []*model_struct.LocalConversation, skipNotice bool) error {
conversationsOnLocal, err := c.db.GetAllConversations(ctx)
if err != nil {
return err
Expand All @@ -39,7 +39,7 @@ func (c *Conversation) SyncConversationsAndTriggerCallback(ctx context.Context,
c.doUpdateConversation(common.Cmd2Value{Value: common.UpdateConNode{ConID: server.ConversationID, Action: constant.ConChange, Args: []string{server.ConversationID}}})
}
return nil
}, true); err != nil {
}, true, skipNotice); err != nil {
return err
}
return nil
Expand All @@ -50,7 +50,7 @@ func (c *Conversation) SyncConversations(ctx context.Context, conversationIDs []
if err != nil {
return err
}
return c.SyncConversationsAndTriggerCallback(ctx, conversationsOnServer)
return c.SyncConversationsAndTriggerCallback(ctx, conversationsOnServer, false)
}

func (c *Conversation) SyncAllConversations(ctx context.Context) error {
Expand All @@ -60,7 +60,7 @@ func (c *Conversation) SyncAllConversations(ctx context.Context) error {
return err
}
log.ZDebug(ctx, "get server cost time", "cost time", time.Since(ccTime), "conversation on server", conversationsOnServer)
return c.SyncConversationsAndTriggerCallback(ctx, conversationsOnServer)
return c.SyncConversationsAndTriggerCallback(ctx, conversationsOnServer, true)
}

func (c *Conversation) SyncAllConversationHashReadSeqs(ctx context.Context) error {
Expand Down
36 changes: 24 additions & 12 deletions pkg/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,13 @@ func (s *Syncer[T, RESP, V]) Sync(ctx context.Context, serverData []T, localData
}
}()
skipDeletion := false
skipNotice := false
if len(skipDeletionAndNotice) > 0 {
skipDeletion = skipDeletionAndNotice[0]
}
if len(skipDeletionAndNotice) > 1 {
skipNotice = skipDeletionAndNotice[1]
}

// If both server and local data are empty, log and return.
if len(serverData) == 0 && len(localData) == 0 {
Expand All @@ -271,9 +275,11 @@ func (s *Syncer[T, RESP, V]) Sync(ctx context.Context, serverData []T, localData
log.ZError(ctx, "sync insert failed", err, "type", s.ts, "server", server, "local", local)
return err
}
if err := s.onNotice(ctx, Insert, server, local, notice); err != nil {
log.ZError(ctx, "sync notice insert failed", err, "type", s.ts, "server", server, "local", local)
return err
if !skipNotice {
if err := s.onNotice(ctx, Insert, server, local, notice); err != nil {
log.ZError(ctx, "sync notice insert failed", err, "type", s.ts, "server", server, "local", local)
return err
}
}
continue
}
Expand All @@ -283,9 +289,11 @@ func (s *Syncer[T, RESP, V]) Sync(ctx context.Context, serverData []T, localData

// If the local and server items are equal, notify and continue.
if s.eq(server, local) {
if err := s.onNotice(ctx, Unchanged, local, server, notice); err != nil {
log.ZError(ctx, "sync notice unchanged failed", err, "type", s.ts, "server", server, "local", local)
return err
if !skipNotice {
if err := s.onNotice(ctx, Unchanged, local, server, notice); err != nil {
log.ZError(ctx, "sync notice unchanged failed", err, "type", s.ts, "server", server, "local", local)
return err
}
}
continue
}
Expand All @@ -296,9 +304,11 @@ func (s *Syncer[T, RESP, V]) Sync(ctx context.Context, serverData []T, localData
log.ZError(ctx, "sync update failed", err, "type", s.ts, "server", server, "local", local)
return err
}
if err := s.onNotice(ctx, Update, server, local, notice); err != nil {
log.ZError(ctx, "sync notice update failed", err, "type", s.ts, "server", server, "local", local)
return err
if !skipNotice {
if err := s.onNotice(ctx, Update, server, local, notice); err != nil {
log.ZError(ctx, "sync notice update failed", err, "type", s.ts, "server", server, "local", local)
return err
}
}
}

Expand All @@ -315,9 +325,11 @@ func (s *Syncer[T, RESP, V]) Sync(ctx context.Context, serverData []T, localData
return err
}
var server T
if err := s.onNotice(ctx, Delete, server, local, notice); err != nil {
log.ZError(ctx, "sync notice delete failed", err, "type", s.ts, "local", local)
return err
if !skipNotice {
if err := s.onNotice(ctx, Delete, server, local, notice); err != nil {
log.ZError(ctx, "sync notice delete failed", err, "type", s.ts, "local", local)
return err
}
}
}
return nil
Expand Down

0 comments on commit 5e51f9f

Please sign in to comment.