Authored by 于良

Merge branch 'local' into develop

... ... @@ -64,7 +64,7 @@ export default class MsgCenterNormalCell extends React.Component {
image={user.avatar}
/>
<View style={styles.topRight}>
<Text style={styles.name}>{user.nickName}</Text>
<Text style={styles.name} numberOfLines={1}>{user.nickName}</Text>
<Text style={styles.timeago}>{timeago}</Text>
</View>
... ... @@ -106,6 +106,7 @@ export default class MsgCenterNormalCell extends React.Component {
}
let {width, height} = Dimensions.get('window');
let nameWidth = Math.ceil((300 / 750) * width);
let styles = StyleSheet.create({
container: {
... ... @@ -137,7 +138,7 @@ let styles = StyleSheet.create({
// marginTop: 13,
fontFamily: 'Helvetica Light',
fontSize: 15,
// backgroundColor:'red',
maxWidth: nameWidth,
},
timeago: {
... ...
... ... @@ -108,7 +108,7 @@ class SubjectPostContainer extends Component {
onEndReached() {
let item = this.props.subject.items.get(this.sid);
if (item.commentReachEnd) {
if (item.isCommentsFetching || item.commentReachEnd) {
return;
}
this.props.actions.requestPostComments(this.sid, item.id, item.lastedTime);
... ...
... ... @@ -283,12 +283,12 @@ function parseMessageInfo(json) {
let likeMsg = {
tips: praiseMsg && praiseMsg.title || '',
isRead: praiseMsg && (praiseMsg.isRead === 'N') ? false : true,
timeagoStr: praiseMsg && timeago(praiseMsg.createTime) || '',
timeagoStr: praiseMsg && praiseMsg.createTime && timeago(praiseMsg.createTime) || '',
};
let sysMsg = {
tips: systemMsg && systemMsg.title || '',
isRead: systemMsg && (systemMsg.isRead === 'N') ? false : true,
timeagoStr: systemMsg && timeago(systemMsg.createTime) || '',
timeagoStr: systemMsg && systemMsg.createTime && timeago(systemMsg.createTime) || '',
};
let result = {
... ...
... ... @@ -13,7 +13,7 @@ import {
ActionSheetIOS,
Alert,
} from 'react-native';
import timeago from 'timeago.js';
import timeago from '../../utils/timeago';
import HomeService from '../../services/HomeService';
import SlicedImage from '../../../common/components/SlicedImage';
... ... @@ -45,6 +45,8 @@ const {
SUBJECT_CLEAN,
} = require('../../constants/actionTypes').default;
const LIMIT = 10;
export function subjectClean(sid) {
return {
type: SUBJECT_CLEAN,
... ... @@ -194,14 +196,17 @@ export function onRightPressed(sid) {
}
export function prepareShareData(sid, postId) {
return dispatch => {
return (dispatch, getState) => {
let {app} = getState();
let params = {
postsId: postId,
appType: 1,
appType: app.container,
};
new PostingService().getShareUrl(params).then(json => {
new PostingService().getShareUrl(params)
.then(json => {
dispatch(shareDataPrepared(sid, json));
}).catch(error => {
})
.catch(error => {
});
}
... ... @@ -216,7 +221,7 @@ export function shareDataPrepared(sid, json) {
export function onRight(sid) {
return {
type:'SUBJECT_DO_NOTHING',
type:SUBJECT_DO_NOTHING,
payload:sid,
}
}
... ... @@ -224,7 +229,7 @@ export function onRight(sid) {
export function doShare(sid,shareInfo) {
NativeModules.YH_CommunityHelper.showShare(shareInfo);
return {
type:'SUBJECT_DO_NOTHING',
type:SUBJECT_DO_NOTHING,
payload: sid,
}
}
... ... @@ -242,7 +247,7 @@ export function doDelete(sid,postsId, forumCode) {
})
}}]);
return {
type:'SUBJECT_DO_NOTHING',
type:SUBJECT_DO_NOTHING,
payload:sid,
}
}
... ... @@ -255,49 +260,12 @@ export function doReport(sid, params) {
});
return {
type:'SUBJECT_DO_NOTHING',
type:SUBJECT_DO_NOTHING,
payload:sid,
}
}
export function contentSuccess(sid,json) {
return dispatch => {
let largeImages = [];
let index=0;
for (var i = 0; i < json.blocks.length; i++) {
let item = json.blocks[i];
if (item.templateKey == 'image') {
let urlStr = item.contentData||'';
let imgWidth = 640;
let imgHeight = imgWidth;
let sizeStr = item.size || '';
if (sizeStr.length) {
let ary=sizeStr.split('x');
let w = parseInt(ary[0]);
let h = parseInt(ary[1]);
if (w&&h) {
imgHeight = parseInt(imgWidth/w*h);
}
}
let newSrc = urlStr;
if (urlStr.indexOf('imageView') === -1) {
newSrc = urlStr + '?imageView2/' + '1' + '/w/' + imgWidth + '/h/' + imgHeight;
} else {
newSrc = urlStr.replace('{mode}', '1')
.replace('{width}', imgWidth)
.replace('{height}', imgHeight);
}
largeImages.push(newSrc);
json.blocks[i].index=index;
index++;
}
}
json.largeImages = largeImages;
dispatch(contentRequestSuccess(sid,json));
}
}
export function requestPostContent(sid,postsId) {
export function requestPostContent(sid, postsId) {
return (dispatch, getState) => {
dispatch(doRequestContent(sid));
let {user} = getState();
... ... @@ -307,12 +275,12 @@ export function requestPostContent(sid,postsId) {
.then(json => {
let payload = parsePostContent(json);
payload.LZ = uid == payload.authorInfo.uid;
dispatch(contentSuccess(sid,payload));
dispatch(contentRequestSuccess(sid, payload));
})
.catch(error => {
Actions.pop();
Alert.alert('提示','帖子不存在或已被删除!');
dispatch(contentRequestFailure(sid,error));
Alert.alert('提示', '帖子不存在或已被删除!');
dispatch(contentRequestFailure(sid, error));
});
}
}
... ... @@ -443,21 +411,30 @@ function getImageSizeFromStr(sizeStr, defaultWidth=320, defaultHeight=320) {
}
}
export function requestPostComments(sid, postsId, lastedTime) {
return dispatch => {
export function requestPostComments(sid, postsId, lastedTime=0) {
return (dispatch, getState) => {
let {subject} = getState();
let item = subject.items.get(sid);
if (!item) {
return;
}
dispatch(doRequestComments(sid));
let params = {
postsId,
lastedTime,
limit: 10,
limit: LIMIT,
};
new PostingService().getPostComments(params)
.then(json => {
dispatch(commentsRequestSuccess(sid,json));
let payload = parseComments(json);
let oldList = item.commentList.toJS();
let list = [...oldList, ...payload.list];
payload.list = list;
dispatch(commentsRequestSuccess(sid, payload));
})
.catch(error => {
dispatch(commentsRequestFailure(sid,error));
dispatch(commentsRequestFailure(sid, error));
});
}
}
... ... @@ -470,43 +447,55 @@ export function doRequestComments(sid) {
}
export function commentsRequestSuccess(sid,json) {
let {list} = json;
return {
type: SUBJECT_COMMENTS_SUCCESS,
payload: {sid, json},
};
}
function parseComments(json) {
let {lastedTime, list, total} = json;
let newList = [];
list && list.map((obj,i)=> {
let {createTime, reply, replyTo, blocks,postInfo,id} = obj;
let timeagoStr = timeago().format(createTime, 'zh_CN');
list && list.map((obj, i)=> {
let {createTime, reply, replyTo, blocks, postInfo, id} = obj;
let timeagoStr = timeago(createTime);
let newBlocks = [];
blocks && blocks.map((blockItem, i) => {
let {commentId,contentData,templateKey,orderBy} = blockItem;
let {commentId, contentData, templateKey, orderBy} = blockItem;
let newItem = {
"contentData": contentData||'',
"order": orderBy||'',
"templateKey": templateKey||'',
"contentData": contentData || '',
"order": orderBy || 0,
"templateKey": templateKey || '',
};
newBlocks.push(newItem);
})
if (replyTo) {
let nickName = replyTo.nickName||'';
replyTo.nickName = nickName;
}
let newObj={
commentId: id||'',
cidTo: reply.uid||'',
timeago: timeagoStr||'',
headIcon: reply.headIcon||'',
nickName: reply.nickName||'',
LZ:(postInfo.authorUid == reply.uid),
blocks: newBlocks||[],
replyTo,
}
let newObj = {
commentId: id || 0,
cidTo: reply && reply.uid || 0,
timeago: timeagoStr || '',
headIcon: reply && reply.headIcon || '',
nickName: reply && reply.nickName || '',
LZ: (postInfo.authorUid == reply.uid),
blocks: newBlocks,
replyTo: {
uid: replyTo && replyTo.uid || 0,
nickName: replyTo && replyTo.nickName || '',
headIcon: replyTo && replyTo.headIcon || '',
signature: replyTo && replyTo.signature || '',
bgPic: replyTo && replyTo.bgPic || '',
},
};
newList.push(newObj);
})
json.list = newList;
let endReached = newList.length < LIMIT;
return {
type: SUBJECT_COMMENTS_SUCCESS,
payload: {sid,json},
}
lastedTime,
list: newList,
endReached,
total,
};
}
function createFakeComment() {
... ...
... ... @@ -19,7 +19,6 @@ let item = new (Record({
headIcon: '',
nickName: '',
uid: 0,
url: ''
})),
blocks: List(),// contentData order templateKey
browse: 0,
... ... @@ -32,7 +31,7 @@ let item = new (Record({
isIndexTop: false,
postsTitle: '',
praise: 0,
hasPraise:'N',
hasPraise: 'N',
revieweState: 0,
praiseUsers: List(),//headIcon nickName uid
shareGoods: new(Record({
... ... @@ -40,12 +39,10 @@ let item = new (Record({
productUrl: '',
salesPrice: 0,
goodsImage: '',
productId:'',
productId: 0,
})),
LZ: false,//楼主
lastedTime: 0,
totalPages: 0,
currentPage: 0,
commentCount: 0,
commentList: List(),//
... ... @@ -59,7 +56,7 @@ let item = new (Record({
largeImages:[],
shareUrl: '',
defaultShareImage: '',
commentReachEnd:false,
commentReachEnd: false,
}));
let InitialState = Record({
... ...
... ... @@ -104,25 +104,15 @@ export default function postingReducer(state = initialState, action) {
}
break;
case SUBJECT_COMMENTS_SUCCESS:{
let {sid,json} = action.payload;
let {sid, json} = action.payload;
let item = state.items.get(sid);
let {lastedTime, total, list, pageSize} = json;
let tailCount = (total%pageSize)>0?1:0;
let totalPages = total/pageSize + tailCount;
let existedAry = item.commentList.toJS();
let nextData = [...existedAry,...list];
let page = item.currentPage;
page++;
let endReached = list.length<10;
item = item.set('commentList',Immutable.fromJS(nextData))
.set('lastedTime',lastedTime)
.set('totalPages',totalPages)
.set('currentPage',page)
.set('commentCount',total)
.set('commentReachEnd',endReached);
let {lastedTime, list, endReached, total} = json;
item = item.set('isCommentsFetching', false)
.set('commentsError', null)
.set('commentList', Immutable.fromJS(list))
.set('lastedTime', lastedTime)
.set('commentCount', total)
.set('commentReachEnd', endReached);
let nextState = state.setIn(['items', sid], item);
return nextState;
}
... ...