tam add chat

This commit is contained in:
2026-06-30 10:53:51 +07:00
parent 6e284e66fa
commit dc86524ff0
6 changed files with 298 additions and 176 deletions

View File

@@ -975,18 +975,21 @@ func (a *App) connectWS() {
case "chat:message":
senderRole, _ := msg.Data["senderRole"].(string)
if senderRole == "staff" {
from := "Giảng viên"
if n, ok := msg.Data["staffName"].(string); ok && n != "" {
from = n
}
preview := ""
if b, ok := msg.Data["body"].(string); ok {
preview = b
}
if staffVal, ok := msg.Data["staffId"].(float64); ok {
a.mu.Lock()
a.replyStaffID = uint(staffVal)
a.chatUnread++
unread := a.chatUnread
a.mu.Unlock()
runtime.EventsEmit(a.ctx, "chat:notify", map[string]any{
"unread": unread,
"preview": msg.Data["body"],
"from": msg.Data["staffName"],
})
}
a.alertChatIncoming(from, preview)
}
runtime.EventsEmit(a.ctx, "chat:message", msg.Data)
}
@@ -1059,6 +1062,32 @@ func (a *App) stopScreenshotStream() {
log.Println("[WS] Screenshot screen-streaming stopped.")
}
func (a *App) alertChatIncoming(from, preview string) {
if preview == "" {
preview = "Bạn có tin nhắn mới"
}
if len(preview) > 120 {
preview = preview[:120] + "…"
}
winapi.PlayNotifySound()
winapi.ActivateAppWindow("Simple Care")
runtime.WindowUnminimise(a.ctx)
runtime.WindowShow(a.ctx)
a.mu.Lock()
unread := a.chatUnread
staffID := a.replyStaffID
a.mu.Unlock()
runtime.EventsEmit(a.ctx, "chat:notify", map[string]any{
"unread": unread,
"preview": preview,
"from": from,
"staffId": staffID,
})
}
// UnlockChatAudio — gọi từ UI sau lần click đầu để mở khóa Web Audio (dự phòng)
func (a *App) UnlockChatAudio() {}
func (a *App) GetChatUnread() int {
a.mu.Lock()
defer a.mu.Unlock()