Authored by 王钱钧

添加系统消息代码。 code review by 于良

... ... @@ -48,7 +48,7 @@ import SubjectPostContainer from './containers/SubjectPostContainer';
import PostingContainer from './containers/PostingContainer';
import SettingContainer from './containers/UserSettingContainer';
import LikeListContainer from './containers/LikeListContainer';
import SystemMessageContainer from './containers/SystemMessageContainer';
import NavBar from './components/NavBar';
import {
... ... @@ -254,6 +254,15 @@ export default function community(platform) {
/>
<Scene
key="SystemMessage"
title="系统消息"
hideNavBar={false}
component={SystemMessageContainer}
initial={false}
onBack={this.onBack}
/>
<Scene
key="Setting"
title="社区资料"
hideNavBar={false}
... ...
... ... @@ -56,6 +56,8 @@ export default class MessageCenter extends React.Component {
onPressLike: React.PropTypes.func,
onPressSection: React.PropTypes.func,
onRefresh: React.PropTypes.func,
onPressSystemCell: React.PropTypes.func,
onPressLikeCell: React.PropTypes.func,
};
constructor(props) {
... ... @@ -86,12 +88,13 @@ export default class MessageCenter extends React.Component {
}
_renderRow(rowData, sectionID, rowID, highlightRow) {
console.log('fuck ================ ' + rowData);
switch (sectionID) {
case 'sysMsg':
return (<MsgCenterCatgoryCell
title={'系统消息'}
data={rowData}
onPressCell={this.props.onPressSystemCell}
defaultSource={require('../../images/message/sysmessage.png')}
/>);
break;
... ... @@ -101,12 +104,16 @@ export default class MessageCenter extends React.Component {
<MsgCenterCatgoryCell
title={'收到的赞'}
data={rowData}
onPressCell={this.props.onPressLikeCell}
defaultSource={require('../../images/message/like.png')}
/>
);
break;
case 'list':
if (rowData.size === 0) {
return null;
}
return (
<MsgCenterNormalCell
data={rowData}
... ... @@ -156,12 +163,16 @@ export default class MessageCenter extends React.Component {
this.props.onEndReached && this.props.onEndReached(this.currentPage);
}}
renderFooter={() => {
console.log('render footer !!!!!!!!!!!!!!!!!');
if (endReached) {
console.log('没有更多啦');
return <LoadMoreIndicator
isVisible={true}
text={'没有更多啦'}
/>
} else {
console.log('加载更多');
return <LoadMoreIndicator
isVisible={isLoadingMore}
animating={isFetching}
... ...
... ... @@ -18,10 +18,12 @@ export default class MsgCenterCatgoryCell extends React.Component {
static propTypes = {
data: ImmutablePropTypes.contains({
timeagoStr:React.PropTypes.string,
tips:React.PropTypes.string,
isRead: React.PropTypes.bool,
timeagoStr:React.PropTypes.string,
tips:React.PropTypes.string,
isRead: React.PropTypes.bool,
}),
onPressCell: React.PropTypes.func,
};
constructor(props) {
... ... @@ -30,45 +32,58 @@ export default class MsgCenterCatgoryCell extends React.Component {
render() {
let data = this.props.data.toJS();
console.log('================ data' + data);
let {timeagoStr, tips, isRead} = data;
return (
<TouchableOpacity
activeOpacity={0.8}
onPress={() => {
this.props.onPressCell && this.props.onPressCell();
}}
>
<View style={styles.container}>
<View style={styles.left}>
<LittleRedDotImage
isRedDot={isRead}
defaultSource={this.props.defaultSource}
/>
</View>
<View style={styles.left}>
<LittleRedDotImage
isRedDot={isRead}
defaultSource={this.props.defaultSource}
/>
</View>
<View style={styles.middle}>
<Text style={styles.title}>{tips}</Text>
<View style={styles.middle}>
<Text style={styles.title}
numberOfLines={1}
>{this.props.title}</Text>
<View style={styles.contentContainer}>
<Text style={styles.content}>{tips}</Text>
<Text style={styles.timeago}>{timeagoStr}</Text>
</View>
<View style={styles.contentContainer}>
<Text style={styles.content} numberOfLines={1}>{tips}</Text>
<Text style={styles.timeago}>{timeagoStr}</Text>
</View>
</View>
</View>
<View style={styles.right}>
<View style={styles.right}>
<Image style={styles.rightIcon}
defaultSource={require('../../images/message/right.png')}
/>
<Image style={styles.rightIcon}
defaultSource={require('../../images/message/right.png')}
/>
</View>
</View>
</View>
</TouchableOpacity>
);
}
}
let {width, height} = Dimensions.get('window');
let contentMaxLenght = (200 / 375) * width;
let styles = StyleSheet.create({
container: {
backgroundColor:'white',
... ... @@ -100,8 +115,12 @@ let styles = StyleSheet.create({
content: {
// marginTop: 15,
// flex:1,
fontFamily: 'Helvetica Light',
fontSize: 10,
minWidth: 80,
maxWidth: contentMaxLenght,
// backgroundColor:'red',
},
... ...
... ... @@ -18,10 +18,23 @@ export default class MsgCenterNormalCell extends React.Component {
static propTypes = {
data: ImmutablePropTypes.contains({
timeagoStr:React.PropTypes.string,
tips:React.PropTypes.string,
isRead: React.PropTypes.bool,
user: ImmutablePropTypes.contains({
avatar: React.PropTypes.string,
uid: React.PropTypes.number,
nickName: React.PropTypes.string,
}),
title:React.PropTypes.string,
subTitle:React.PropTypes.string,
timeago:React.PropTypes.string,
isRead: React.PropTypes.bool,
post:ImmutablePropTypes.contains({
sectionId: React.PropTypes.number,
sectionName: React.PropTypes.string,
}),
}),
onPressPost: React.PropTypes.func,
onPressAvatar: React.PropTypes.func,
};
constructor(props) {
... ... @@ -29,8 +42,8 @@ export default class MsgCenterNormalCell extends React.Component {
}
render() {
// let data = this.props.data;
// let {timeagoStr, tips, isRead} = data;
let data = this.props.data.toJS();
let {user, title, timeago, post, subTitle} = data;
return (
<View style={styles.container}>
... ... @@ -38,17 +51,17 @@ export default class MsgCenterNormalCell extends React.Component {
<View style={styles.topContainer}>
<LittleRedDotImage
isRedDot={true}
image={'https://img11.static.yhbimg.com/yhb-img01/2016/06/28/11/01f429fffdff555ed0c141a5ec2b4fd421.jpg?imageView2/2/w/640/h/240'}
image={user.avatar}
/>
<View style={styles.topRight}>
<Text style={styles.name}>Wine</Text>
<Text style={styles.timeago}>2 时前</Text>
<Text style={styles.name}>{user.nickName}</Text>
<Text style={styles.timeago}>{timeago}</Text>
</View>
</View>
<View style={styles.middleContainer}>
<Text style={styles.content}>这是我在太晚买的这是我在太晚买的这是我在太晚买的这是我在太晚买的这是我在太晚买的</Text>
<Text style={styles.content}>{title}</Text>
</View>
<View style={styles.buttomContainer}>
... ... @@ -59,13 +72,13 @@ export default class MsgCenterNormalCell extends React.Component {
<Text style={styles.reply}
numberOfLines={1}
>
回复我的回复:好赞,在哪里买的?fdsafdsafdasfdasfdasfasd哪里
{subTitle}
</Text>
</Image>
<View style={styles.section}>
<SectionItem
name={'section.name'}
name={post.sectionName}
onPressSection={() => {
this.props.onPressSectionTag && this.props.onPressSectionTag();
}}
... ... @@ -183,10 +196,4 @@ let styles = StyleSheet.create({
backgroundColor: '#e0e0e0',
},
replyTouch: {
backgroundColor: 'red',
// padding: 0,
width:80,
height: 40,
},
});
... ...
... ... @@ -3,7 +3,7 @@
import React from 'react';
import ReactNative from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';
import UserBrief from '../home/UserBrief';
import SectionItem from '../home/SectionItem';
// import Thumbs from './Thumbs';
// import SectionItem from './SectionItem';
// import NumberButton from './NumberButton';
... ... @@ -20,116 +20,72 @@ export default class ReplyCell extends React.Component {
static propTypes = {
data: ImmutablePropTypes.contains({
id: React.PropTypes.number,
postId: React.PropTypes.number,
createTime: React.PropTypes.number.isRequired,
authorUid: React.PropTypes.number,
// 帖子
postInfo: ImmutablePropTypes.contains({
title: React.PropTypes.string,
type: React.PropTypes.string.isRequired,
}),
// 回复的内容
blocks: ImmutablePropTypes.listOf(
ImmutablePropTypes.contains({
commentId: React.PropTypes.number,
orderBy: React.PropTypes.number,
content: React.PropTypes.string,
templateKey: React.PropTypes.string.isRequired,
})
),
// 我的信息
reply: ImmutablePropTypes.contains({
headIcon: React.PropTypes.string,
user: ImmutablePropTypes.contains({
avatar: React.PropTypes.string,
uid: React.PropTypes.number,
name: React.PropTypes.string,
nickName: React.PropTypes.string,
}),
// 被回复者信息
replyTo: ImmutablePropTypes.contains({
headIcon: React.PropTypes.string,
uid: React.PropTypes.number,
name: React.PropTypes.string,
title:React.PropTypes.string,
subTitle:React.PropTypes.string,
timeago:React.PropTypes.string,
isRead: React.PropTypes.bool,
post:ImmutablePropTypes.contains({
sectionId: React.PropTypes.number,
sectionName: React.PropTypes.string,
}),
onPressAvatar: React.PropTypes.func,
onPressReply: React.PropTypes.func,
onPressPosts: React.PropTypes.func,
}),
// TODO 添加点击事件
onPressPost: React.PropTypes.func,
onPressAvatar: React.PropTypes.func,
};
constructor(props) {
super(props);
}
render() {
let data = this.props.data.toJS();
let {
id,
postId,
createTime,
authorUid,
postInfo,
blocks,
reply,
replyTo,
} = data;
let {user, title, timeago, post, subTitle} = data;
return (
<View style={styles.container}>
<View style={styles.topContainer}>
<UserBrief
avatar={reply.headIcon}
name={reply.name}
timeago={createTime.toString()}
// isOwner={isOwner}
onPressAvatar={() => {
this.props.onPressAvatar && this.props.onPressAvatar();
}}
/>
<View style={styles.topContainer}>
<View style={styles.topRight}>
<Text style={styles.name}>{title}</Text>
<Text style={styles.timeago}>{timeago}</Text>
</View>
<View style={styles.reply}>
<Text style={[styles.text,{fontSize:14}]}>
回复
<Text style={{color: '#4a90e2', fontSize: 14,}}
onPress={() => {
this.props.onPressReply && this.props.onPressReply();
}}
>
小草莓
</Text>
:如果你无法表单房间诶哦我就佛大发了瓦解偶发的拉萨减肥劳动局撒了附件二范德萨范德萨
</Text>
</View>
</View>
<View style={styles.lineInCell}/>
<View style={styles.middleContainer}>
<Text style={styles.content}
numberOfLines={2}
>{subTitle}</Text>
</View>
<View style={styles.bottomContainer}>
<Text
style={[styles.text,{margin:15, fontSize: 18}]}
<View style={styles.bottomContainer}>
<Image
defaultSource={require('../../images/message/duihuakuang.png')}
style={styles.bubble}
>
<Text style={styles.reply}
numberOfLines={1}
onPress={() => {
this.props.onPressPosts && this.props.onPressPosts();
}}
>
帖子:港南爱上米彩妆,看叫啥呢我发的是fdsafdsafdsafdasfd剪短发搜富哦为福建省的
{post.thumb}
</Text>
</Image>
<View style={styles.section}>
<SectionItem
name={post.sectionName}
onPressSection={() => {
this.props.onPressSectionTag && this.props.onPressSectionTag();
}}
/>
</View>
</View>
</View>
... ... @@ -141,41 +97,100 @@ export default class ReplyCell extends React.Component {
let styles = StyleSheet.create({
container: {
backgroundColor:'white',
// flex:1,
// backgroundColor:'green',
flexDirection:'column',
// justifyContent:'center',
// alignItems:'center',
// height: 60,
// backgroundColor: 'yellow',
},
topContainer: {
margin: 15,
// width: 60,
height: 60,
flexDirection: 'row',
padding: 15,
// justifyContent: 'center',
// backgroundColor:'yellow',
},
reply: {
// backgroundColor: 'red',
marginLeft: 15,
marginRight: 15,
topRight: {
backgroundColor: 'white',
marginLeft:0,
flexDirection: 'column',
},
text: {
name: {
// marginTop: 13,
fontFamily: 'Helvetica Light',
fontSize: 15,
// backgroundColor:'red',
},
timeago: {
fontFamily: 'Helvetica Light',
fontSize: 10,
// marginLeft:15,
color: '#b0b0b0',
// backgroundColor:'red',
},
bottomContainer: {
backgroundColor:'white'
middleContainer: {
// flex: 1,
backgroundColor:'white',
},
content: {
marginLeft: 15,
marginRight: 15,
fontFamily: 'Helvetica Light',
fontSize: 14,
// backgroundColor:'red',
// height: 60,
},
lineInCell: {
height: 1,
bottomContainer: {
// flex:1,
// backgroundColor:'yellow',
height: 90,
// margin: 15,
marginLeft: 15,
marginRight: 15,
marginTop:0,
// marginBottom:15,
// padding: 15,
},
bubble: {
// flex:1,
backgroundColor:'white',
flexDirection:'row',
// justifyContent: 'center',
alignItems:'center',
height:40,
padding:10,
},
reply: {
// flex:1,
backgroundColor: 'transparent',
fontFamily: 'Helvetica Light',
fontSize: 12,
color: '#8b8b8b',
marginTop:8,
},
section: {
flexDirection: 'row',
justifyContent: 'space-between',
marginTop: 15,
// backgroundColor:'red',
// marginBottom: 15,
backgroundColor: '#e0e0e0',
},
replyTouch: {
backgroundColor: 'red',
// padding: 0,
width:80,
height: 40,
},
});
... ...
... ... @@ -2,6 +2,12 @@
import React from 'react';
import ReactNative from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';
import SysMsgCell from './SysMsgCell';
import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';
const {
View,
... ... @@ -11,30 +17,102 @@ const {
StyleSheet,
Platform,
Dimensions,
InteractionManager,
ListView,
} = ReactNative;
export default class SystemMessage extends React.Component {
static propTypes = {
userInfo: React.PropTypes.shape({
name: React.PropTypes.string,
sign: React.PropTypes.string,
}),
list: ImmutablePropTypes.listOf(
ImmutablePropTypes.contains({
author: ImmutablePropTypes.contains({
avatar: React.PropTypes.string,
uid: React.PropTypes.number,
name: React.PropTypes.string,
}),
timeago:React.PropTypes.string,
title:React.PropTypes.string,
reply:React.PropTypes.string,
section: ImmutablePropTypes.contains({
id: React.PropTypes.number,
name: React.PropTypes.string,
}),
}),
),
onPressSection: React.PropTypes.func,
onRefresh: React.PropTypes.func,
onEndReached: React.PropTypes.func,
}
constructor(props) {
super(props);
this._renderRow = this._renderRow.bind(this);
this._renderSeparator = this._renderSeparator.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
}
componentDidMount() {
// InteractionManager.runAfterInteractions(() => {
// this.listView && this.listView.getScrollResponder().startPullToRefresh();
// });
}
_renderRow(rowData, sectionID, rowID, highlightRow) {
return (
<SysMsgCell
data={rowData}
/>
);
}
_renderSeparator() {
_renderSeparator(sectionID,rowID) {
console.log('=====> ' + 'separator' + rowID) ;
return (
<View style={styles.separator}/>
<View key={'separator' + rowID} style={styles.separator}/>
);
}
render() {
let {list, endReached, isLoadingMore, isFetching, isRefreshing} = this.props;
return (
<View style={styles.container}>
<Text>系统消息</Text>
<ListView
ref={(c) => {
this.listView = c;
}}
dataSource={this.dataSource.cloneWithRows(list.toArray())}
renderRow={this._renderRow}
renderSeparator={this._renderSeparator}
enableEmptySections={true}
enablePullToRefresh={false}
isOnPullToRefresh={isRefreshing}
onEndReached={() => {
this.props.onEndReached && this.props.onEndReached();
}}
onRefreshData={() => {
this.props.onRefresh && this.props.onRefresh();
}}
renderFooter={()=>{
if (endReached) {
return <LoadMoreIndicator
isVisible={true}
text={'没有更多啦'}
/>
} else {
return <LoadMoreIndicator
isVisible={isLoadingMore}
animating={isFetching}
/>
}
}}
/>
</View>
... ... @@ -53,4 +131,9 @@ let styles = StyleSheet.create({
backgroundColor: 'white',
},
separator: {
height: 0.5,
backgroundColor: '#e0e0e0',
},
});
... ...
... ... @@ -9,16 +9,8 @@ import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import MessageCenter from '../components/message/MessageCenter';
import * as messageActions from '../reducers/message/messageActions';
const {
GO_TO_SYS_MESSAGE,
GO_TO_LIKE_MESSAGE,
} = require('../constants/actionTypes').default;
const {
Text,
... ... @@ -60,11 +52,14 @@ class MessageCenterContainer extends React.Component {
this._onPressSection = this._onPressSection.bind(this);
this._onRefresh = this._onRefresh.bind(this);
this._onEndReached = this._onEndReached.bind(this);
this._onPressLikeCell = this._onPressLikeCell.bind(this);
this._onPressSystemCell = this._onPressSystemCell.bind(this);
}
_onPressLike() {
console.log('on press like');
}
_onPressSystemMsg() {
... ... @@ -77,7 +72,6 @@ class MessageCenterContainer extends React.Component {
}
_onRefresh() {
console.log('====================== _onRefresh=============');
InteractionManager.runAfterInteractions(() => {
this.props.actions.messageInfo(true);
this.props.actions.replyMessage(true);
... ... @@ -91,12 +85,21 @@ class MessageCenterContainer extends React.Component {
});
}
_onPressSystemCell() {
console.log('system cell press');
this.props.actions.goToSystemMessage();
}
_onPressLikeCell() {
console.log('like cell press');
this.props.actions.goToLikeMessage();
}
render() {
let {centerMsg} = this.props.message;
let {ptr, isFetching, sysMsg, likeMsg, list, endReached} = centerMsg;
let isRefreshing = ptr;
console.log('ptr =====================>>>>>>' + ptr);
let isLoadingMore = !ptr && isFetching;
return (
... ... @@ -104,7 +107,7 @@ class MessageCenterContainer extends React.Component {
<MessageCenter
sysMsg={Immutable.fromJS([sysMsg])}
likeMsg={Immutable.fromJS([likeMsg])}
list={Immutable.fromJS([list])}
list={list}
onRefresh={this._onRefresh}
onPressSystemMsg={this._onPressSystemMsg}
onPressLike={this._onPressLike}
... ... @@ -114,6 +117,8 @@ class MessageCenterContainer extends React.Component {
endReached={endReached}
isRefreshing={isRefreshing}
isLoadingMore={isLoadingMore}
onPressSystemCell={this._onPressSystemCell}
onPressLikeCell={this._onPressLikeCell}
/>
</View>
);
... ...
... ... @@ -9,24 +9,15 @@ import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import SystemMessage from '../components/message/SystemMessage';
import * as messageActions from '../reducers/message/messageActions';
const {
SETTING_SAVE_REQUEST,
SETTING_SAVE_SUCCESS,
SETTING_SAVE_FAILURE,
} = require('../constants/actionTypes').default;
const {
Text,
View,
StyleSheet,
Dimensions,
Platform,
InteractionManager,
} = ReactNative;
const actions = [
... ... @@ -54,13 +45,55 @@ function mapDispatchToProps(dispatch) {
class SystemMessageContainer extends React.Component {
constructor(props) {
super(props);
this._onPressSection = this._onPressSection.bind(this);
this._onRefresh = this._onRefresh.bind(this);
this._onEndReached = this._onEndReached.bind(this);
}
componentDidMount() {
this._onEndReached();
}
_onPressSection(id) {
console.log('_onPressSection id =' + id);
// this.props.actions.goToPost(id);
}
_onRefresh() {
// console.log('_onRefresh id =' + id);
InteractionManager.runAfterInteractions(() => {
this.props.actions.systemMessage(true);
});
}
_onEndReached() {
InteractionManager.runAfterInteractions(() => {
this.props.actions.systemMessage(false);
});
}
render() {
let {system} = this.props.message;
let {ptr, isFetching, list, endReached} = system;
let isRefreshing = ptr;
let isLoadingMore = isFetching;
return (
<View style={styles.container}>
<SystemMessage
list={list}
isFetching={isFetching}
ptr={ptr}
endReached={endReached}
isRefreshing={isRefreshing}
isLoadingMore={isLoadingMore}
onRefresh={this._onRefresh}
onPressSection={this._onPressSection}
onEndReached={this._onEndReached}
/>
</View>
);
... ...
... ... @@ -244,10 +244,6 @@ class UserContainer extends React.Component {
endReached = replyData.endReached;
}
console.log('isRefreshing=====>' + isRefreshing);
console.log('endReached=====>' + endReached);
console.log('isLoadingMore=====>' + isLoadingMore);
console.log('isFetching=====>' + isFetching);
return (
<View style={styles.container}>
<User
... ...
... ... @@ -54,47 +54,6 @@ export function likeMessageFailue(error) {
};
}
export function likeMessage(ptr = false) {
return (dispatch, getState) => {
let {user, message} = getState();
// 接口请求跳出的条件:
// 前置条件:下拉刷新优先级高于上拉加载
if (ptr) {
//下拉刷新直接执行
} else {
// 1.当次请求不是下拉刷新,同时正在进行下拉刷新的请求,跳出
// 2.当次请求不是下拉刷新,同时接口请求正在加载中, 跳出
// 3.当次请求不是下拉刷新,数据已全部加载完成,跳出
if (message.like.ptr || message.like.isFetching || message.like.endReached || message.like.error) {
return;
}
}
dispatch(likeMessageRequest(ptr));
let uid = user.profile.uid;
let lastedTime = 0;
if (!ptr) {
lastedTime = message.like.lastedTime;
}
let type = 2; // 点赞列表
let limit = 10;
return new MessageService().messageList(uid, type, lastedTime, limit)
.then(json => {
let payload = parseLikeMessage(json);
if (!ptr) {
let oldList = message.like.list.toJS();
let list = [...oldList, ...payload.list];
payload.list = list;
}
dispatch(likeMessageSuccess(payload));
});
}
}
export function messageInfoRequest(ptr) {
return {
type: MESSAGE_INFO_REQUEST,
... ... @@ -137,6 +96,71 @@ export function replyMessageFailue(error) {
};
}
export function systemMessageRequest(ptr) {
return {
type: MESSAGE_SYST_REQUEST,
payload: ptr,
};
}
export function systemMessageSuccess(json) {
return {
type: MESSAGE_SYST_SUCCESS,
payload: json,
};
}
export function systemMessageFailue(error) {
return {
type: MESSAGE_SYST_FAILURE,
payload: error,
};
}
export function likeMessage(ptr = false) {
return (dispatch, getState) => {
let {user, message} = getState();
// 接口请求跳出的条件:
// 前置条件:下拉刷新优先级高于上拉加载
if (ptr) {
//下拉刷新直接执行
} else {
// 1.当次请求不是下拉刷新,同时正在进行下拉刷新的请求,跳出
// 2.当次请求不是下拉刷新,同时接口请求正在加载中, 跳出
// 3.当次请求不是下拉刷新,数据已全部加载完成,跳出
if (message.like.ptr || message.like.isFetching || message.like.endReached || message.like.error) {
return;
}
}
dispatch(likeMessageRequest(ptr));
let uid = user.profile.uid;
let lastedTime = 0;
if (!ptr) {
lastedTime = message.like.lastedTime;
}
let limit = 10;
return new MessageService().messageList(uid, 2, lastedTime, limit)
.then(json => {
let payload = parseMessageList(json);
if (!ptr) {
let oldList = message.like.list.toJS();
let list = [...oldList, ...payload.list];
payload.list = list;
}
dispatch(likeMessageSuccess(payload));
});
}
}
export function messageInfo(ptr = false) {
return (dispatch, getState) => {
let {user, message} = getState();
... ... @@ -148,7 +172,6 @@ export function messageInfo(ptr = false) {
.then(json => {
// console.log('');
let payload = parseMessageInfo(json);
console.log('message info paylod = ' + payload);
dispatch(messageInfoSuccess(payload));
})
.catch(error => {
... ... @@ -168,11 +191,24 @@ export function replyMessage(ptr = false) {
lastedTime = message.centerMsg.lastedTime;
}
if (!ptr) {
if (message.centerMsg.ptr || message.centerMsg.isFetching || message.centerMsg.endReached || message.centerMsg.error) {
return;
}
}
dispatch(replyMessageRequest(ptr));
return new MessageService().messageList(3, uid, lastedTime, limit)
return new MessageService().messageList(uid, 3, lastedTime, limit)
.then(json => {
let payload = parseMessageList(json);
if (!ptr) {
let oldList = message.centerMsg.list.toJS();
let list = [...oldList, ...payload.list];
payload.list = list;
}
dispatch(replyMessageSuccess(payload));
})
.catch(error => {
... ... @@ -181,28 +217,91 @@ export function replyMessage(ptr = false) {
};
}
export function systemMessage() {
export function systemMessage(ptr = false) {
return (dispatch, getState) => {
let {user} = getState();
dispatch();
let limit = 10;
let {user, message} = getState();
let uid = user.profile.uid;
return new MessageService().messageList(1, uid)
.then(json => {
let lastedTime = 0;
if (!ptr) {
lastedTime = message.system.lastedTime;
}
if (!ptr) {
if (message.system.ptr || message.system.isFetching || message.system.endReached || message.system.error) {
return;
}
}
dispatch(systemMessageRequest(ptr));
return new MessageService().messageList(uid, 1, lastedTime, limit)
.then(json => {
let payload = parseMessageList(json);
if (!ptr) {
let oldList = message.system.list.toJS();
let list = [...oldList, ...payload.list];
payload.list = list;
}
dispatch(systemMessageSuccess(payload));
})
.catch(error => {
dispatch(systemMessageFailue(error));
});
};
}
export function goToLikeMessage() {
Actions.LikeMessage();
return {
type: GO_TO_LIKE_MESSAGE,
// payload:
};
}
export function goToSystemMessage() {
Actions.SystemMessage();
return {
type: GO_TO_SYS_MESSAGE,
// payload:
};
}
function parseMessageInfo(json) {
let {praiseMsg, systemMsg} = json;
let like={} , sys={};
function parseLikeMessage(json) {
if (praiseMsg) {
like = {
tips: praiseMsg.title || '',
isRead: (praiseMsg.isRead === 'N')?false:true,
timeagoStr:timeago(praiseMsg.createTime),
};
}
if (systemMsg) {
sys = {
tips: systemMsg.title || '',
isRead: (systemMsg.isRead === 'N')?false:true,
timeagoStr:timeago(systemMsg.createTime),
};
}
let result = {
likeMsg: like,
sysMsg: sys,
};
return result;
}
function parseMessageList(json) {
let {lastedTime, list} = json;
let messages = [];
list && list.map((item, i) => {
let messages = [];
list && list.map((item, i) => {
let id = item.id ? item.id : 0;
let title = item.title ? item.title : '';
... ... @@ -214,6 +313,7 @@ function parseLikeMessage(json) {
let user = {};
let post = {};
let {content} = item;
let {subTitle} = content;
if (content) {
let {userInfo, postInfo} = content;
if (userInfo) {
... ... @@ -231,14 +331,16 @@ function parseLikeMessage(json) {
};
}
if (postInfo) {
let sectionId = postInfo.sectionId ? postInfo.sectionId : '';
let sectionId = postInfo.forumCode ? postInfo.forumCode : '';
let postId = postInfo.postId ? postInfo.postId : 0;
let sectionName = postInfo.forumName ? postInfo.forumName : '';
postId = parseInt(postId);
let thumb = postInfo.content ? postInfo.content : '';
post = {
id: postId,
thumb,
sectionId,
sectionName,
};
}
}
... ... @@ -252,6 +354,7 @@ function parseLikeMessage(json) {
timeago: timeagoStr,
user,
post,
subTitle,
};
messages.push(message);
... ... @@ -264,37 +367,3 @@ function parseLikeMessage(json) {
endReached,
};
}
function parseMessageInfo(json) {
let {praiseMsg, systemMsg} = json;
let like={} , sys={};
if (praiseMsg) {
like = {
tips: praiseMsg.title || '',
isRead: (praiseMsg.isRead === 'N')?false:true,
timeagoStr:timeago(praiseMsg.createTime),
};
}
if (systemMsg) {
sys = {
tips: systemMsg.title || '',
isRead: (systemMsg.isRead === 'N')?false:true,
timeagoStr:timeago(systemMsg.createTime),
};
}
let result = {
likeMsg: like,
sysMsg: sys,
};
console.log('result ======== ' + result);
return result;
}
function parseMessageList(json) {
console.log('========>', json);
}
... ...
... ... @@ -36,7 +36,7 @@ let InitialState = Record({
})),
system: new (Record({
ptr: true,
ptr: false,
isFetching: false,
error: null,
lastedTime: 0,
... ...
... ... @@ -78,6 +78,63 @@ export default function message(state = initialState, action) {
}
break;
case MESSAGE_CENTER_REQUEST:
{
let nextState = state.setIn(['centerMsg', 'isFetching'], true)
.setIn(['centerMsg', 'error'], null);
return nextState;
}
break;
case MESSAGE_CENTER_SUCCESS:
{
let {lastedTime, list, endReached} = action.payload;
let nextState = state.setIn(['centerMsg', 'isFetching'], false)
.setIn(['centerMsg', 'error'], null)
.setIn(['centerMsg', 'lastedTime'], lastedTime)
.setIn(['centerMsg', 'endReached'], endReached)
.setIn(['centerMsg', 'list'], Immutable.fromJS(list))
.setIn(['centerMsg', 'ptr'], false);
return nextState;
}
break;
case MESSAGE_CENTER_FAILURE:
{
return state.setIn(['centerMsg', 'isFetching'], false)
.setIn(['centerMsg', 'error'], action.payload);
}
break;
case MESSAGE_SYST_REQUEST:
{
let nextState = state.setIn(['system', 'isFetching'], true)
.setIn(['system', 'error'], null);
return nextState;
}
break;
case MESSAGE_SYST_SUCCESS:
{
let {lastedTime, list, endReached} = action.payload;
let nextState = state.setIn(['system', 'isFetching'], false)
.setIn(['system', 'error'], null)
.setIn(['system', 'lastedTime'], lastedTime)
.setIn(['system', 'endReached'], endReached)
.setIn(['system', 'list'], Immutable.fromJS(list))
.setIn(['system', 'ptr'], false);
return nextState;
}
break;
case MESSAGE_SYST_FAILURE:
{
return state.setIn(['system', 'isFetching'], false)
.setIn(['system', 'error'], action.payload);
}
break;
default:
}
... ...