Merge branch 'chat' into dev
This commit is contained in:
commit
2455067913
@ -18,17 +18,40 @@ import (
|
|||||||
"fonchain-fiee/pkg/service/asChat/dto"
|
"fonchain-fiee/pkg/service/asChat/dto"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"log"
|
"log"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var cacheMap = make(map[int64]dto.NewMessageRequest)
|
||||||
|
var newMessageLocker sync.Mutex
|
||||||
|
|
||||||
func NewMessage(ctx context.Context, cache *chatCache.ChatCache, sender *accountFiee.ChatUserData, request dto.NewMessageRequest) (err error) {
|
func NewMessage(ctx context.Context, cache *chatCache.ChatCache, sender *accountFiee.ChatUserData, request dto.NewMessageRequest) (err error) {
|
||||||
|
newMessageLocker.Lock()
|
||||||
|
defer newMessageLocker.Unlock()
|
||||||
if request.SessionId == "" {
|
if request.SessionId == "" {
|
||||||
return errors.New("sessionId不能为空")
|
return errors.New("sessionId不能为空")
|
||||||
}
|
}
|
||||||
if request.MsgType == 0 {
|
if request.MsgType == 0 {
|
||||||
return errors.New("msgType不能为空")
|
return errors.New("msgType不能为空")
|
||||||
}
|
}
|
||||||
fmt.Println("NewMessage 1111111111111111111111111111111")
|
//短时间重复消息不发送
|
||||||
fmt.Println("NewMessage 22222222222222222222222222222222222")
|
if request.AtUserId != 0 && request.Robot {
|
||||||
|
if msgRecord, ok := cacheMap[request.AtUserId]; ok {
|
||||||
|
if msgRecord.SessionId == "" {
|
||||||
|
cacheMap[request.AtUserId] = request
|
||||||
|
} else {
|
||||||
|
fmt.Println(request.LocalStamp - msgRecord.LocalStamp)
|
||||||
|
if msgRecord.Message.Text == request.Message.Text && request.LocalStamp-msgRecord.LocalStamp < 10 {
|
||||||
|
cacheMap[request.AtUserId] = request
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
cacheMap[request.AtUserId] = request
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cacheMap[request.AtUserId] = request
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//存储入库
|
//存储入库
|
||||||
if sender.NickName == "" {
|
if sender.NickName == "" {
|
||||||
sender.NickName = fmt.Sprintf("未知用户(%d)", sender.ID)
|
sender.NickName = fmt.Sprintf("未知用户(%d)", sender.ID)
|
||||||
|
Loading…
Reference in New Issue
Block a user