74 lines
2.2 KiB
TypeScript
74 lines
2.2 KiB
TypeScript
/**
|
|||
|
|
* 消息列表页 U23
|
||
|
|
*
|
||
|
|
* 不变量(AGENTS.md):
|
||
|
|
* - 第 3 条:Mutual Match 后才能聊天
|
||
|
|
* - 第 4 条:Block/Unmatch 后会话立即停用
|
||
|
|
* - 第 6 条:单向活动意向不泄露
|
||
|
|
* - 第 9 条:DB 是 Source of Truth
|
||
|
|
*/
|
||
|
|
import { messageStore, appStore, authStore } from '../../stores';
|
||
|
|
import { ROUTE, to } from '../../constants';
|
||
|
|
|
||
|
|
Page({
|
||
|
|
data: {
|
||
|
|
conversations: [] as any[],
|
||
|
|
loading: false,
|
||
|
|
unreadTotal: 0,
|
||
|
|
emptyActions: [{ text: '去今日推荐', event: 'home', variant: 'primary' }],
|
||
|
|
},
|
||
|
|
|
||
|
|
onLoad() {
|
||
|
|
(this as any)._unsubMsg = messageStore.bindToPage(this, {
|
||
|
|
conversations: 'conversations',
|
||
|
|
totalUnreadCount: 'unreadTotal',
|
||
|
|
});
|
||
|
|
(this as any)._unsubLoading = messageStore.subscribe((state: any) => {
|
||
|
|
if (state.conversationsLoading !== this.data.loading) {
|
||
|
|
this.setData({ loading: state.conversationsLoading });
|
||
|
|
}
|
||
|
|
});
|
||
|
|
this.setData({ loading: messageStore.state.conversationsLoading });
|
||
|
|
},
|
||
|
|
|
||
|
|
onShow() {
|
||
|
|
if (!authStore.state.isLoggedIn) return;
|
||
|
|
messageStore.fetchConversations().catch((err: any) => appStore.toastError(err));
|
||
|
|
},
|
||
|
|
|
||
|
|
onUnload() {
|
||
|
|
if ((this as any)._unsubMsg) (this as any)._unsubMsg();
|
||
|
|
if ((this as any)._unsubLoading) (this as any)._unsubLoading();
|
||
|
|
},
|
||
|
|
|
||
|
|
onPullDownRefresh() {
|
||
|
|
messageStore.fetchConversations().finally(() => wx.stopPullDownRefresh());
|
||
|
|
},
|
||
|
|
|
||
|
|
onReachBottom() {
|
||
|
|
if (messageStore.state.conversationsHasMore) {
|
||
|
|
messageStore.loadMoreConversations().catch(() => {});
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
onGoChat(e: any) {
|
||
|
|
const { conversationId, canSendMessage } = e.detail;
|
||
|
|
if (!canSendMessage) {
|
||
|
|
appStore.toastError('当前会话已停用,无法继续聊天');
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
wx.navigateTo({ url: to.chat(conversationId) });
|
||
|
|
},
|
||
|
|
|
||
|
|
onShortcutTap(e: any) {
|
||
|
|
const key = e.currentTarget.dataset.key;
|
||
|
|
if (key === 'new-friends') { wx.switchTab({ url: ROUTE.TAB.DISCOVER }); return; }
|
||
|
|
if (key === 'system') { wx.navigateTo({ url: ROUTE.SETTINGS.NOTIFICATIONS }); return; }
|
||
|
|
wx.navigateTo({ url: ROUTE.MAIN.FATE_CENTER });
|
||
|
|
},
|
||
|
|
|
||
|
|
onEmptyAction(e: any) {
|
||
|
|
if (e.detail.event === 'home') wx.switchTab({ url: ROUTE.TAB.HOME });
|
||
|
|
},
|
||
|
|
});
|