Module: ChatStore

Pinia Store,用于管理聊天会话、消息、实时通信事件和消息搜索功能。 它是聊天功能的核心状态管理模块。
Source:

Methods

(inner) clearActiveConversation() → {void}

清除当前活跃会话的状态。
Source:
Returns:
Type
void

(inner) clearReplyingTo() → {void}

清除当前回复的消息状态。
Source:
Returns:
Type
void

(inner) clearSearchResults() → {void}

清空所有消息搜索结果并重置搜索状态。
Source:
Returns:
Type
void

(inner) getConversations() → {Promise.<void>}

获取当前用户的所有会话列表。 在用户未登录时,清空会话列表。
Source:
Throws:
如果获取会话列表失败,会打印错误信息。
Type
Error
Returns:
Type
Promise.<void>

(inner) getMessages(conversationId, pageToLoadopt) → {Promise.<void>}

获取指定会话的消息列表。 支持分页加载,新消息会追加到现有列表。
Parameters:
Name Type Attributes Default Description
conversationId string 要获取消息的会话 ID。
pageToLoad number <optional>
1 要加载的页码。
Source:
Throws:
如果获取消息失败,会打印错误信息并清空消息列表。
Type
Error
Returns:
Type
Promise.<void>

(inner) handleNewRealTimeMessage(newMessage) → {void}

处理实时接收到的新消息。 更新当前会话的消息列表,并更新会话列表中的最新消息和未读计数,同时触发桌面通知。
Parameters:
Name Type Description
newMessage object 新消息数据对象。
Properties
Name Type Attributes Description
conversationId string 消息所属会话的 ID。
content string 消息内容。
messageType string 消息类型(如 'text', 'image')。
sender._id string 消息发送者的用户 ID。
sender.username string 消息发送者的用户名。
conversationType string 会话类型('private' 或 'group')。
groupInfo object <optional>
如果是群组消息,包含群组信息。
Source:
Returns:
Type
void

(inner) loadMoreSearchResults(conversationId, searchTerm) → {Promise.<void>}

加载更多消息搜索结果。 仅在还有更多结果且当前未在搜索中时触发。
Parameters:
Name Type Description
conversationId string 当前活跃会话 ID。
searchTerm string 当前搜索关键词。
Source:
Returns:
Type
Promise.<void>

(inner) searchMessagesInConversation(conversationId, searchTerm, pageopt) → {Promise.<void>}

在指定会话中搜索消息。 支持分页和加载更多搜索结果。
Parameters:
Name Type Attributes Default Description
conversationId string 要搜索的会话 ID。
searchTerm string 搜索关键词。
page number <optional>
1 要加载的搜索结果页码。
Source:
Returns:
Type
Promise.<void>

(inner) selectFriendToChat(friend) → {Promise.<void>}

通过好友信息选择一个私聊会话。 如果会话不存在,则创建新的会话。
Parameters:
Name Type Description
friend object 好友对象,包含 _id, username, avatar 等。
Source:
Returns:
Type
Promise.<void>

(inner) selectGroupChannelToChat(channel) → {Promise.<void>}

通过群组频道信息选择一个群组会话。
Parameters:
Name Type Description
channel object 群组频道对象,包含 _id, name 等信息。
Source:
Returns:
Type
Promise.<void>

(inner) setActiveConversation(conversation) → {Promise.<void>}

设置当前活跃的会话,并加载其消息列表。 如果会话有未读消息,会标记为已读。
Parameters:
Name Type Description
conversation object 要激活的会话对象。
Source:
Returns:
Type
Promise.<void>

(inner) setActiveFriend(friend) → {void}

设置活跃会话的伙伴信息(主要用于私聊显示)。
Parameters:
Name Type Description
friend object 好友对象。
Source:
Returns:
Type
void

(inner) setReplyingTo(message) → {void}

设置要回复的消息内容。
Parameters:
Name Type Description
message object 要回复的消息对象。
Source:
Returns:
Type
void

(inner) useChatStore() → {Object}

Pinia Store,用于管理聊天相关的所有状态和操作。 包含会话列表、消息列表、活跃会话、加载状态、消息回复以及消息搜索功能。
Properties:
Name Type Description
conversations Ref.<Array.<object>> 用户的所有会话列表。
messages Ref.<Array.<object>> 当前活跃会话的消息列表。
activeConversation Ref.<(object|null)> 当前活跃的会话对象。
isLoadingConversations Ref.<boolean> 会话列表是否正在加载中。
currentMessagePage Ref.<number> 当前消息列表已加载的页码。
totalMessagePages Ref.<number> 当前活跃会话的总消息页数。
canLoadMoreMessages Ref.<boolean> 是否可以加载更多消息。
isLoadingMessages Ref.<boolean> 消息列表是否正在加载中。
messageLimitPerPage Ref.<number> 每页加载的消息数量限制。
replyingToMessage Ref.<(object|null)> 当前正在回复的消息对象。
searchResults Ref.<Array.<object>> 消息搜索结果列表。
isSearchingMessages Ref.<boolean> 消息是否正在搜索中。
currentSearchPage Ref.<number> 当前搜索结果已加载的页码。
totalSearchPages Ref.<number> 搜索结果的总页数。
canLoadMoreSearchResults Ref.<boolean> 是否可以加载更多搜索结果。
currentSearchTerm Ref.<string> 当前的搜索关键词。
activeConversationPartner Ref.<object> 当前活跃私聊会话的伙伴用户信息。
handleNewRealTimeMessage function 处理实时接收到的新消息。
getConversations function 获取用户所有会话列表。
getMessages function 获取指定会话的消息列表。
setActiveConversation function 设置当前活跃的会话。
selectFriendToChat function 通过好友信息选择并激活聊天会话。
selectGroupChannelToChat function 通过群组频道信息选择并激活聊天会话。
clearActiveConversation function 清除当前活跃会话状态。
setActiveFriend function 设置活跃会话伙伴(用于私聊)。
setReplyingTo function 设置要回复的消息。
clearReplyingTo function 清除回复消息状态。
searchMessagesInConversation function 在指定会话中搜索消息。
loadMoreSearchResults function 加载更多消息搜索结果。
clearSearchResults function 清空消息搜索结果。
Source:
Returns:
Type
Object