mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-10-31 08:29:33 +08:00 
			
		
		
		
	* Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * feat: add code lint * feat: add code lint * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * feat: code format * Script Refactoring * Script Refactoring * Script Refactoring * Adjust MinIO configuration settings * Adjust configuration settings * Adjust configuration settings * refactor: config change. * refactor: webhooks update. * Adjust configuration settings * refactor: webhooks update. * Adjust configuration settings * Adjust configuration settings * Adjust configuration settings * feat: s3 api addr * refactor: webhooks update. * Adjust configuration settings * Adjust configuration settings * Adjust configuration settings * Adjust configuration settings * Adjust configuration settings * Adjust configuration settings * Adjust configuration settings * refactor: webhooks update. * refactor: kafka update. * Simplify the Docker Compose configuration, remove unnecessary environment variables, and eliminate the gateway service. * refactor: kafka update. * refactor: kafka update. * Simplify the Docker Compose configuration, remove unnecessary environment variables, and eliminate the gateway service. * Simplify the Docker Compose configuration, remove unnecessary environment variables, and eliminate the gateway service. * Windows can compile and run. * Windows can compile and run. * refactor: kafka update. * feat: msg cache split * refactor: webhooks update * refactor: webhooks update * refactor: friends update * refactor: group update * refactor: third update * refactor: api update * refactor: crontab update * refactor: msggateway update * mage * mage * refactor: all module update. * check * refactor: all module update. * load config * load config * load config * load config * refactor: all module update. * refactor: all module update. * refactor: all module update. * refactor: all module update. * refactor: all module update. * Optimize Docker configuration and script. * refactor: all module update. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * refactor: all module update. * Optimize Docker configuration and script. * refactor: all module update. * refactor: all module update. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * update tools * update tools * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * update protocol * Optimize Docker configuration and script. * Optimize Docker configuration and script. * refactor: all module update. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * refactor: api remove token auth by redis directly. * Code Refactoring * refactor: websocket auth change to call rpc of auth. * refactor: kick online user and remove token change to call auth rpc. * refactor: kick online user and remove token change to call auth rpc. * refactor: remove msggateway redis. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor webhook * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor webhook * refactor: cmd update. * refactor: cmd update. * fix: runtime: goroutine stack exceeds * refactor: cmd update. * refactor notification * refactor notification * refactor * refactor: cmd update. * refactor: cmd update. * refactor * refactor * refactor * protojson * protojson * protojson * go mod * wrapperspb * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: context update. * refactor: websocket update info. * refactor: websocket update info. * refactor: websocket update info. * refactor: websocket update info. * refactor: api name change. * refactor: debug info. * refactor: debug info. * refactor: debug info. * fix: update file * refactor * refactor * refactor: debug info. * refactor: debug info. * refactor: debug info. * refactor: debug info. * refactor: debug info. * refactor: debug info. * fix: callback update. * fix: callback update. * refactor * fix: update message. * fix: msg cache timeout. * refactor * refactor * fix: push update. * fix: push update. * fix: push update. * fix: push update. * fix: push update. * fix: push update. * fix: push update. * fix: websocket handle error remove when upgrade error. --------- Co-authored-by: skiffer-git <44203734@qq.com> Co-authored-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> Co-authored-by: withchao <993506633@qq.com>
		
			
				
	
	
		
			200 lines
		
	
	
		
			5.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			200 lines
		
	
	
		
			5.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright © 2023 OpenIM. All rights reserved.
 | |
| //
 | |
| // Licensed under the Apache License, Version 2.0 (the "License");
 | |
| // you may not use this file except in compliance with the License.
 | |
| // You may obtain a copy of the License at
 | |
| //
 | |
| //     http://www.apache.org/licenses/LICENSE-2.0
 | |
| //
 | |
| // Unless required by applicable law or agreed to in writing, software
 | |
| // distributed under the License is distributed on an "AS IS" BASIS,
 | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | |
| // See the License for the specific language governing permissions and
 | |
| // limitations under the License.
 | |
| 
 | |
| package msgprocessor
 | |
| 
 | |
| import (
 | |
| 	"sort"
 | |
| 	"strings"
 | |
| 
 | |
| 	"github.com/openimsdk/protocol/constant"
 | |
| 	"github.com/openimsdk/protocol/sdkws"
 | |
| 	"github.com/openimsdk/tools/errs"
 | |
| 	"google.golang.org/protobuf/proto"
 | |
| )
 | |
| 
 | |
| func GetNotificationConversationIDByMsg(msg *sdkws.MsgData) string {
 | |
| 	switch msg.SessionType {
 | |
| 	case constant.SingleChatType:
 | |
| 		l := []string{msg.SendID, msg.RecvID}
 | |
| 		sort.Strings(l)
 | |
| 		return "n_" + strings.Join(l, "_")
 | |
| 	case constant.WriteGroupChatType:
 | |
| 		return "n_" + msg.GroupID
 | |
| 	case constant.ReadGroupChatType:
 | |
| 		return "n_" + msg.GroupID
 | |
| 	case constant.NotificationChatType:
 | |
| 		return "n_" + msg.SendID + "_" + msg.RecvID
 | |
| 	}
 | |
| 	return ""
 | |
| }
 | |
| 
 | |
| func GetChatConversationIDByMsg(msg *sdkws.MsgData) string {
 | |
| 	switch msg.SessionType {
 | |
| 	case constant.SingleChatType:
 | |
| 		l := []string{msg.SendID, msg.RecvID}
 | |
| 		sort.Strings(l)
 | |
| 		return "si_" + strings.Join(l, "_")
 | |
| 	case constant.WriteGroupChatType:
 | |
| 		return "g_" + msg.GroupID
 | |
| 	case constant.ReadGroupChatType:
 | |
| 		return "sg_" + msg.GroupID
 | |
| 	case constant.NotificationChatType:
 | |
| 		return "sn_" + msg.SendID + "_" + msg.RecvID
 | |
| 	}
 | |
| 
 | |
| 	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 {
 | |
| 	case constant.SingleChatType:
 | |
| 		l := []string{msg.SendID, msg.RecvID}
 | |
| 		sort.Strings(l)
 | |
| 		if !options.IsNotNotification() {
 | |
| 			return "n_" + strings.Join(l, "_")
 | |
| 		}
 | |
| 		return "si_" + strings.Join(l, "_") // single chat
 | |
| 	case constant.WriteGroupChatType:
 | |
| 		if !options.IsNotNotification() {
 | |
| 			return "n_" + msg.GroupID // group chat
 | |
| 		}
 | |
| 		return "g_" + msg.GroupID // group chat
 | |
| 	case constant.ReadGroupChatType:
 | |
| 		if !options.IsNotNotification() {
 | |
| 			return "n_" + msg.GroupID // super group chat
 | |
| 		}
 | |
| 		return "sg_" + msg.GroupID // super group chat
 | |
| 	case constant.NotificationChatType:
 | |
| 		if !options.IsNotNotification() {
 | |
| 			return "n_" + msg.SendID + "_" + msg.RecvID // super group chat
 | |
| 		}
 | |
| 		return "sn_" + msg.SendID + "_" + msg.RecvID // server notification chat
 | |
| 	}
 | |
| 	return ""
 | |
| }
 | |
| 
 | |
| func GetConversationIDBySessionType(sessionType int, ids ...string) string {
 | |
| 	sort.Strings(ids)
 | |
| 	if len(ids) > 2 || len(ids) < 1 {
 | |
| 		return ""
 | |
| 	}
 | |
| 	switch sessionType {
 | |
| 	case constant.SingleChatType:
 | |
| 		return "si_" + strings.Join(ids, "_") // single chat
 | |
| 	case constant.WriteGroupChatType:
 | |
| 		return "g_" + ids[0] // group chat
 | |
| 	case constant.ReadGroupChatType:
 | |
| 		return "sg_" + ids[0] // super group chat
 | |
| 	case constant.NotificationChatType:
 | |
| 		return "sn_" + ids[0] // server notification chat
 | |
| 	}
 | |
| 	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_")
 | |
| }
 | |
| 
 | |
| 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 {
 | |
| 	return len(s)
 | |
| }
 | |
| 
 | |
| func (s MsgBySeq) Less(i, j int) bool {
 | |
| 	return s[i].Seq < s[j].Seq
 | |
| }
 | |
| 
 | |
| func (s MsgBySeq) Swap(i, j int) {
 | |
| 	s[i], s[j] = s[j], s[i]
 | |
| }
 | |
| 
 | |
| func Pb2String(pb proto.Message) (string, error) {
 | |
| 	s, err := proto.Marshal(pb)
 | |
| 	if err != nil {
 | |
| 		return "", errs.Wrap(err)
 | |
| 	}
 | |
| 	return string(s), nil
 | |
| }
 | |
| 
 | |
| func String2Pb(s string, pb proto.Message) error {
 | |
| 	return proto.Unmarshal([]byte(s), pb)
 | |
| }
 |