Skip to content

Commit adfc372

Browse files
authored
fix: solve uncorrect delete conversation. (#848)
1 parent 8e5f68c commit adfc372

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

internal/conversation_msg/delete.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package conversation_msg
1616

1717
import (
1818
"context"
19+
"errors"
1920

2021
"github.com/openimsdk/openim-sdk-core/v3/pkg/common"
2122
"github.com/openimsdk/openim-sdk-core/v3/pkg/constant"
@@ -25,27 +26,34 @@ import (
2526
"github.com/openimsdk/openim-sdk-core/v3/sdk_struct"
2627

2728
"github.com/openimsdk/protocol/sdkws"
29+
"github.com/openimsdk/tools/errs"
2830
"github.com/openimsdk/tools/log"
2931
)
3032

3133
// Delete the local and server
32-
// Delete the local, do not change the server data
33-
// To delete the server, you need to change the local message status to delete
3434
func (c *Conversation) clearConversationFromLocalAndServer(ctx context.Context, conversationID string, f func(ctx context.Context, conversationID string) error) error {
3535
_, err := c.db.GetConversation(ctx, conversationID)
3636
if err != nil {
3737
return err
3838
}
39+
3940
// Use conversationID to remove conversations and messages from the server first
4041
err = c.clearConversationMsgFromServer(ctx, conversationID)
4142
if err != nil {
42-
return err
43+
if errors.Is(errs.Unwrap(err), errs.ErrRecordNotFound) {
44+
log.ZWarn(ctx, "clearConversationMsgFromServer err", err, "conversationID", conversationID)
45+
} else {
46+
return err
47+
}
4348
}
49+
4450
if err := c.clearConversationAndDeleteAllMsg(ctx, conversationID, false, f); err != nil {
4551
return err
4652
}
53+
4754
c.doUpdateConversation(common.Cmd2Value{Value: common.UpdateConNode{Action: constant.ConChange, Args: []string{conversationID}}})
4855
c.doUpdateConversation(common.Cmd2Value{Value: common.UpdateConNode{Action: constant.TotalUnreadMessageChanged}})
56+
4957
return nil
5058
}
5159

test/conversation_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ func Test_ClearConversationAndDeleteAllMsg(t *testing.T) {
228228
}
229229
}
230230

231+
func Test_DeleteConversationAndDeleteAllMsg(t *testing.T) {
232+
err := open_im_sdk.UserForSDK.Conversation().DeleteConversationAndDeleteAllMsg(ctx, "si_3271407977_7152307910")
233+
if err != nil {
234+
t.Fatal(err)
235+
}
236+
}
237+
231238
// func Test_RevokeMessage(t *testing.T) {
232239
// err := open_im_sdk.UserForSDK.Conversation().RevokeMessage(ctx, &sdk_struct.MsgStruct{SessionType: 1, ContentType: 101,
233240
// ClientMsgID: "380e2eb1709875340d769880982ebb21", Seq: 57, SendID: "9169012630", RecvID: "2456093263"})

0 commit comments

Comments
 (0)