feat: add customer online status to conversation response and update UI accordingly

This commit is contained in:
mlogclub
2026-04-14 20:28:48 +08:00
parent 2d5f229828
commit 12fd382abb
6 changed files with 40 additions and 3 deletions
@@ -37,6 +37,7 @@ func BuildConversation(item *models.Conversation) response.ConversationResponse
AgentLastReadMessageID: readStateMessageID(agentReadState),
AgentLastReadSeqNo: readStateSeqNo(agentReadState),
AgentLastReadAt: readStateAt(agentReadState),
CustomerOnline: services.WsService.IsVisitorOnline(item.ExternalID),
ClosedAt: utils.FormatTimePtr(item.ClosedAt),
ClosedBy: item.ClosedBy,
CloseReason: item.CloseReason,
@@ -41,6 +41,7 @@ type ConversationResponse struct {
AgentLastReadMessageID int64 `json:"agentLastReadMessageId"`
AgentLastReadSeqNo int64 `json:"agentLastReadSeqNo"`
AgentLastReadAt string `json:"agentLastReadAt,omitempty"`
CustomerOnline bool `json:"customerOnline"`
ClosedAt string `json:"closedAt,omitempty"`
ClosedBy int64 `json:"closedBy"`
ClosedByName string `json:"closedByName,omitempty"`
@@ -104,6 +104,14 @@ func (m *WsConnectionManager) FindByTopics(topics []string) []*ClientSession {
return ret
}
func (m *WsConnectionManager) HasTopic(topic string) bool {
m.mu.RLock()
defer m.mu.RUnlock()
sessions := m.topics[topic]
return len(sessions) > 0
}
func (m *WsConnectionManager) subscribeLocked(session *ClientSession, topic string) {
if _, exists := session.Topics[topic]; exists {
return
+8
View File
@@ -386,6 +386,14 @@ func (s *wsService) PublishToTopics(topics []string, event RealtimeEvent) {
}
}
func (s *wsService) IsVisitorOnline(visitorID string) bool {
visitorID = strings.TrimSpace(visitorID)
if visitorID == "" {
return false
}
return s.manager.HasTopic(s.visitorTopic(visitorID))
}
func (s *wsService) routeConversationTopics(conversation *models.Conversation) []string {
if conversation == nil {
return nil