import React, { Component } from 'react';
import { Row, Col, List, Avatar, Space, Pagination } from 'antd';
import { stores_Context } from '../config';
import { observer } from 'mobx-react';
import 'moment/locale/zh-cn';
class WhatsApp_session extends Component {
static contextType = stores_Context;
constructor(props) {
super(props);
}
componentDidMount() {
console.info('Wechat_session.componentDidMount');
const { whatsAppStore } = this.context;
whatsAppStore.fetchWechatUserList();
}
handleUserClick(user) {
const { whatsAppStore } = this.context;
whatsAppStore.fetchContactList(user);
}
handleContactClick(contact) {
const { whatsAppStore } = this.context;
whatsAppStore.fetchChatMsgList(contact, 0, 20);
}
handlePageChanged(page, pageSize) {
const { whatsAppStore } = this.context;
whatsAppStore.fetchChatMsgList(whatsAppStore.selectedContact, page, pageSize);
}
renderMsgItem(chatMsg) {
const msgDate = new Date(chatMsg.msgtime);
const msgDateText = msgDate.toLocaleDateString() + ' ' + msgDate.toLocaleTimeString();
return (
}
title={chatMsg.from_name}
description={msgDateText}
/>
{this.renderMsgContent(chatMsg)}
);
}
renderMsgContent(chatMsg) {
if (chatMsg.msgtype === 'file') {
return {chatMsg.content.filename};
} else if (chatMsg.msgtype === 'image') {
return
;
} else if (chatMsg.msgtype === 'text') {
return <>{chatMsg.content.text}>;
} else if (chatMsg.msgtype === 'link') {
return {chatMsg.content.title};
} else {
return <>未知消息[{chatMsg.msgtype}]>;
}
}
render() {
const { whatsAppStore } = this.context;
const userList = whatsAppStore.userList;
const contactList = whatsAppStore.contactList;
const chatMsgList = whatsAppStore.chatMsgList;
const chatMsgPage = whatsAppStore.chatMsgPage;
return (
<>
(
{
this.handleUserClick(user);
}}
>
} title={user.username} />
)}
/>
(
{
this.handleContactClick(contact);
}}
>
} title={contact.username} />
)}
/>
this.renderMsgItem(chatMsg)}
/>
{
this.handlePageChanged(page, pageSize);
}}
/>
>
);
}
}
export default observer(WhatsApp_session);