修复了聊天数据异常丢失的bug
This commit is contained in:
+5
-3
@@ -5,8 +5,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ChatMessage struct {
|
type ChatMessage struct {
|
||||||
UserID string
|
UserID string // 发言对象
|
||||||
UserName string
|
UserName string // 发言对象名字
|
||||||
|
TarUserID string // 接收对象
|
||||||
CreateTx time.Time
|
CreateTx time.Time
|
||||||
Type string
|
Type string
|
||||||
Text string
|
Text string
|
||||||
@@ -17,10 +18,11 @@ const (
|
|||||||
ChatTypeCard = "CARD" // 工具卡片分享
|
ChatTypeCard = "CARD" // 工具卡片分享
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewTextChatMsg(user *Users, text string) *ChatMessage {
|
func NewTextChatMsg(user *Users, tarUid string, text string) *ChatMessage {
|
||||||
return &ChatMessage{
|
return &ChatMessage{
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
UserName: user.Name,
|
UserName: user.Name,
|
||||||
|
TarUserID: tarUid,
|
||||||
CreateTx: time.Now(),
|
CreateTx: time.Now(),
|
||||||
Type: ChatTypeText,
|
Type: ChatTypeText,
|
||||||
Text: text,
|
Text: text,
|
||||||
|
|||||||
+3
-1
@@ -12,7 +12,9 @@ var ChatMsg = &chatMessageRepo{}
|
|||||||
func (*chatMessageRepo) GetUserMsgs(db *gorm.DB, uuid string, limit int) []models.ChatMessage {
|
func (*chatMessageRepo) GetUserMsgs(db *gorm.DB, uuid string, limit int) []models.ChatMessage {
|
||||||
var msgs []models.ChatMessage
|
var msgs []models.ChatMessage
|
||||||
// ASC:升序(默认),DESC:降序。
|
// ASC:升序(默认),DESC:降序。
|
||||||
db.Order("create_tx ASC").Limit(limit).Where("user_id = ?", uuid).Find(&msgs)
|
db.Order("create_tx ASC").Limit(limit).
|
||||||
|
Where("user_id = ? OR tar_user_id = ?", uuid, uuid).
|
||||||
|
Find(&msgs)
|
||||||
return msgs
|
return msgs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -89,7 +89,10 @@ func (s *serverService) StartListenServer() error {
|
|||||||
message := &models.Message{
|
message := &models.Message{
|
||||||
Cmd: "chat",
|
Cmd: "chat",
|
||||||
User: *user,
|
User: *user,
|
||||||
ChatMessage: *models.NewTextChatMsg(&user.Users, msg["text"].(string)),
|
ChatMessage: *models.NewTextChatMsg(
|
||||||
|
&user.Users,
|
||||||
|
repo.User.GetUserInfo(global.DB).ID,
|
||||||
|
msg["text"].(string)),
|
||||||
}
|
}
|
||||||
global.Send.SendChan <- message
|
global.Send.SendChan <- message
|
||||||
c.JSON(200, gin.H{"message": "ok"})
|
c.JSON(200, gin.H{"message": "ok"})
|
||||||
|
|||||||
+1
-1
@@ -87,7 +87,7 @@ func OpenChat(user models.Users) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
my := repo.User.GetUserInfo(global.DB)
|
my := repo.User.GetUserInfo(global.DB)
|
||||||
chatItem := models.NewTextChatMsg(my, en.Text)
|
chatItem := models.NewTextChatMsg(my, user.ID, en.Text)
|
||||||
userInfo.messages = append(userInfo.messages, *chatItem)
|
userInfo.messages = append(userInfo.messages, *chatItem)
|
||||||
_ = repo.ChatMsg.Create(global.DB, chatItem)
|
_ = repo.ChatMsg.Create(global.DB, chatItem)
|
||||||
list.Add(itemMessage(*chatItem))
|
list.Add(itemMessage(*chatItem))
|
||||||
|
|||||||
+5
-2
@@ -53,7 +53,10 @@ func StartGameListen() {
|
|||||||
case "/close_game":
|
case "/close_game":
|
||||||
g := global.GetGameInfo(msg.GameUuid)
|
g := global.GetGameInfo(msg.GameUuid)
|
||||||
if g != nil {
|
if g != nil {
|
||||||
dialog.ShowInformation("提示", "对方已退出", g.Obj.(*TenGame).w)
|
dialog.NewConfirm("提示", "对方已退出", func(b bool) {
|
||||||
|
g.Obj.(*TenGame).w.Close()
|
||||||
|
}, g.Obj.(*TenGame).w).Show()
|
||||||
|
//dialog.ShowInformation("提示", "对方已退出", g.Obj.(*TenGame).w)
|
||||||
}
|
}
|
||||||
case "/start_game":
|
case "/start_game":
|
||||||
g := global.GetGameInfo(msg.GameUuid)
|
g := global.GetGameInfo(msg.GameUuid)
|
||||||
@@ -244,7 +247,7 @@ func (t *TenGame) advance() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TenGame) setTitle() {
|
func (t *TenGame) setTitle() {
|
||||||
title := fmt.Sprintf("Game %0.f*%0.f win:%d", t.itemX, t.itemY, t.winSum)
|
title := fmt.Sprintf("让我们来下棋 %0.f*%0.f win:%d", t.itemX, t.itemY, t.winSum)
|
||||||
if t.isNet {
|
if t.isNet {
|
||||||
title += fmt.Sprintf(" | 我 vs %s", t.user.Name)
|
title += fmt.Sprintf(" | 我 vs %s", t.user.Name)
|
||||||
if t.currentRoundPlayer == t.myIndex {
|
if t.currentRoundPlayer == t.myIndex {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package views
|
package views
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/dialog"
|
"fyne.io/fyne/v2/dialog"
|
||||||
@@ -44,12 +45,17 @@ func baseCardView(
|
|||||||
baseCardV = widget.NewCard(baseCardCopy.Title, baseCardCopy.Text, container.NewBorder(nil, widget.NewToolbar(
|
baseCardV = widget.NewCard(baseCardCopy.Title, baseCardCopy.Text, container.NewBorder(nil, widget.NewToolbar(
|
||||||
widget.NewToolbarAction(theme.ContentAddIcon(), func() {}),
|
widget.NewToolbarAction(theme.ContentAddIcon(), func() {}),
|
||||||
widget.NewToolbarAction(theme.DeleteIcon(), func() {
|
widget.NewToolbarAction(theme.DeleteIcon(), func() {
|
||||||
|
dialog.NewConfirm("提示", fmt.Sprintf("确定删除:%s?", baseCardCopy.Title), func(b bool) {
|
||||||
|
if b {
|
||||||
err := service.BaseCard.Delete(global.DB, baseCardCopy)
|
err := service.BaseCard.Delete(global.DB, baseCardCopy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dialog.ShowInformation("删除失败", err.Error(), w)
|
dialog.ShowInformation("删除失败", err.Error(), w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gridWrap.Remove(baseCardV)
|
gridWrap.Remove(baseCardV)
|
||||||
|
}
|
||||||
|
}, w).Show()
|
||||||
|
|
||||||
}),
|
}),
|
||||||
widget.NewToolbarAction(theme.SettingsIcon(), func() {
|
widget.NewToolbarAction(theme.SettingsIcon(), func() {
|
||||||
info := cardTypeMap[baseCardCopy.ToolType]
|
info := cardTypeMap[baseCardCopy.ToolType]
|
||||||
|
|||||||
Reference in New Issue
Block a user