Skip to content

Commit

Permalink
fix: sn_ not sort
Browse files Browse the repository at this point in the history
  • Loading branch information
withchao committed Sep 29, 2024
1 parent 627e2be commit 0e5d0d6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 396 deletions.
66 changes: 4 additions & 62 deletions pkg/msgprocessor/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@ func GetChatConversationIDByMsg(msg *sdkws.MsgData) string {
return ""
}

func GenConversationUniqueKey(msg *sdkws.MsgData) string {
switch msg.SessionType {
case constant.SingleChatType, constant.NotificationChatType:
l := []string{msg.SendID, msg.RecvID}
sort.Strings(l)
return strings.Join(l, "_")
case constant.ReadGroupChatType:
return msg.GroupID
}
return ""
}

func GetConversationIDByMsg(msg *sdkws.MsgData) string {
options := Options(msg.Options)
switch msg.SessionType {
Expand All @@ -98,10 +86,12 @@ func GetConversationIDByMsg(msg *sdkws.MsgData) string {
}
return "sg_" + msg.GroupID // super group chat
case constant.NotificationChatType:
l := []string{msg.SendID, msg.RecvID}
sort.Strings(l)
if !options.IsNotNotification() {
return "n_" + msg.SendID + "_" + msg.RecvID // super group chat
return "n_" + strings.Join(l, "_")
}
return "sn_" + msg.SendID + "_" + msg.RecvID // server notification chat
return "sn_" + strings.Join(l, "_")
}
return ""
}
Expand All @@ -124,30 +114,6 @@ func GetConversationIDBySessionType(sessionType int, ids ...string) string {
return ""
}

func GetNotificationConversationIDByConversationID(conversationID string) string {
l := strings.Split(conversationID, "_")
if len(l) > 1 {
l[0] = "n"
return strings.Join(l, "_")
}

return ""
}

func GetNotificationConversationID(sessionType int, ids ...string) string {
sort.Strings(ids)
if len(ids) > 2 || len(ids) < 1 {
return ""
}
switch sessionType {
case constant.SingleChatType:
return "n_" + strings.Join(ids, "_") // single chat
case constant.ReadGroupChatType:
return "n_" + ids[0] // super group chat
}
return ""
}

func IsNotification(conversationID string) bool {
return strings.HasPrefix(conversationID, "n_")
}
Expand All @@ -156,30 +122,6 @@ func IsNotificationByMsg(msg *sdkws.MsgData) bool {
return !Options(msg.Options).IsNotNotification()
}

func ParseConversationID(msg *sdkws.MsgData) (isNotification bool, conversationID string) {
options := Options(msg.Options)
switch msg.SessionType {
case constant.SingleChatType:
l := []string{msg.SendID, msg.RecvID}
sort.Strings(l)
if !options.IsNotNotification() {
return true, "n_" + strings.Join(l, "_")
}
return false, "si_" + strings.Join(l, "_") // single chat
case constant.ReadGroupChatType:
if !options.IsNotNotification() {
return true, "n_" + msg.GroupID // super group chat
}
return false, "sg_" + msg.GroupID // super group chat
case constant.NotificationChatType:
if !options.IsNotNotification() {
return true, "n_" + msg.SendID + "_" + msg.RecvID // super group chat
}
return false, "sn_" + msg.SendID + "_" + msg.RecvID // server notification chat
}
return false, ""
}

type MsgBySeq []*sdkws.MsgData

func (s MsgBySeq) Len() int {
Expand Down
Loading

0 comments on commit 0e5d0d6

Please sign in to comment.