Authored by 于良

Merge branch 'local' into develop

... ... @@ -15,6 +15,7 @@ import {
} from 'react-native';
import timeago from 'timeago.js';
import HomeService from '../../services/HomeService';
import SlicedImage from '../../../common/components/SlicedImage';
const {
SUBJECT_CONTENT_REQUEST,
... ... @@ -304,15 +305,9 @@ export function requestPostContent(sid,postsId) {
let params = {postsId, uid};
new PostingService().getPostContent(params)
.then(json => {
NativeModules.YH_CommunityHelper.uid()
.then(uid => {
json.LZ = (uid == json.authorInfo.uid);
dispatch(contentSuccess(sid,json));
})
.catch(error => {
json.LZ = false;
dispatch(contentSuccess(sid,json));
});
let payload = parsePostContent(json);
payload.LZ = uid == payload.authorInfo.uid;
dispatch(contentSuccess(sid,payload));
})
.catch(error => {
Actions.pop();
... ... @@ -343,6 +338,111 @@ export function contentRequestFailure(sid,error) {
}
}
function parsePostContent(json) {
let {blocks, praiseUsers} = json;
let largeImages = [];
let index = 0;
let newBlocks = [];
blocks && blocks.map((item, i) => {
let newBlock = {
templateKey: item.templateKey || '',
order: item.order || 0,
contentData: item.contentData || '',
size: item.size || '',
};
if (newBlock.templateKey == 'image') {
let urlStr = newBlock.contentData || '';
let size = getImageSizeFromStr(urlStr, 320, 320);
let width = 320;
let height = parseInt(width / size.width * size.height);
let newSrc = SlicedImage.getSlicedUrl(urlStr, width, height);
largeImages.push(newSrc);
newBlock.index = index;
index++;
}
newBlocks.push(newBlock);
});
let newPraiseUsers = [];
praiseUsers && praiseUsers.map((item, i) => {
let newPraiseUser = {
uid: item.uid || 0,
headIcon: item.headIcon || '',
nickName: item.nickName || '',
signature: item.signature || '',
bgPic: item.bgPic || '',
};
newPraiseUsers.push(newPraiseUser);
});
let goodsImage = json.shareGoods && json.shareGoods.goodsImage || '';
let array = goodsImage.split('?');
goodsImage = array[0];
let newJson = {
authorInfo: {
uid: json.authorInfo && json.authorInfo.uid || 0,
headIcon: json.authorInfo && json.authorInfo.headIcon || '',
nickName: json.authorInfo && json.authorInfo.nickName || '',
signature: json.authorInfo && json.authorInfo.signature || '',
bgPic: json.authorInfo && json.authorInfo.bgPic || '',
},
blocks: newBlocks,
browse: json.browse || 0,
createTime: json.createTime || 0,
id: json.id || 0,
forumCode: json.forumCode || 0,
forumName: json.forumName || '',
hasPraise: json.hasPraise || '',
isForumTop: json.isForumTop || 0,
isHot: json.isHot || '',
isIndexTop: json.isIndexTop || 0,
postsTitle: json.postsTitle || '',
praise: json.praise || 0,
praiseUsers: newPraiseUsers,
shareGoods: {
productId: json.shareGoods && json.shareGoods.productId || 0,
productName: json.shareGoods && json.shareGoods.productName || '',
productUrl: json.shareGoods && json.shareGoods.productUrl || '',
salesPrice: json.shareGoods && json.shareGoods.salesPrice || '',
goodsImage,
},
revieweState: json.revieweState || 0,
revieweTime: json.revieweTime || 0,
status: json.status || 0,
updateTime: json.updateTime || 0,
largeImages,
};
return newJson;
}
function getImageSizeFromStr(sizeStr, defaultWidth=320, defaultHeight=320) {
if (sizeStr.length == 0) {
return {
width: defaultWidth,
height: defaultHeight,
};
}
let sizeArray = sizeStr.split('x');
let width = parseInt(sizeArray[0]);
let height = parseInt(sizeArray[1]);
if (width && height) {
return {
width,
height,
};
} else {
return {
width: defaultWidth,
height: defaultHeight,
};
}
}
export function requestPostComments(sid, postsId, lastedTime) {
return dispatch => {
dispatch(doRequestComments(sid));
... ...
... ... @@ -42,8 +42,6 @@ let item = new (Record({
goodsImage: '',
productId:'',
})),
publishTimeString: '',
shareProductSkn: 0,
LZ: false,//楼主
lastedTime: 0,
totalPages: 0,
... ...
... ... @@ -56,8 +56,6 @@ export default function postingReducer(state = initialState, action) {
switch (action.type) {
case GO_TO_POST: {
console.log(state);
console.log('bbbbbbbbbbbbbbbbbbbbbb');
let currentSid = state.sid;
let newItems = state.items;
let newSid = currentSid;
... ... @@ -90,68 +88,8 @@ export default function postingReducer(state = initialState, action) {
break;
case SUBJECT_CONTENT_SUCCESS:{
let {sid,json} = action.payload;
let {
authorInfo,
blocks,// contentData order templateKey
browse,
createTime,
forumCode,
forumName,
id,
isForumTop,
isHot,
isIndexTop,
postsTitle,
praise,
praiseUsers,//headIcon nickName uid
shareGoods,
publishTimeString,
shareProductSkn,
revieweState,
hasPraise,
largeImages,
LZ,
} = json;
let item = state.items.get(sid);
item = item.set('blocks',Immutable.fromJS(blocks))
.set('browse',browse)
.set('createTime',createTime)
.set('forumCode',forumCode)
.set('forumName',forumName)
.set('id',id)
.set('isForumTop',isForumTop)
.set('isHot',isHot)
.set('isIndexTop',isIndexTop)
.set('postsTitle',postsTitle)
.set('praise',praise)
.set('praiseUsers',Immutable.fromJS(praiseUsers.reverse()))
.set('publishTimeString',publishTimeString)
.set('shareProductSkn',shareProductSkn)
.set('LZ',LZ)
.set('isContentFetching', false)
.set('contentError', null)
.set('revieweState',revieweState)
.set('largeImages',largeImages)
.set('hasPraise',hasPraise||'N');
if (shareGoods) {
let imgUrl = '';
if (shareGoods.goodsImage.length) {
let ary=shareGoods.goodsImage.split('?');
imgUrl = ary[0];
}
item = item.setIn(['shareGoods','productName'],shareGoods.productName||'')
.setIn(['shareGoods','productUrl'],shareGoods.productUrl||'')
.setIn(['shareGoods','salesPrice'],shareGoods.salesPrice||'')
.setIn(['shareGoods','goodsImage'],imgUrl||'')
.setIn(['shareGoods','productId'],shareGoods.productId)
}
if (authorInfo) {
item = item.setIn(['authorInfo','headIcon'],authorInfo.headIcon||'')
.setIn(['authorInfo','nickName'],authorInfo.nickName||'')
.setIn(['authorInfo','uid'],authorInfo.uid||'')
.setIn(['authorInfo','url'],authorInfo.url||'')
}
item = postContentSuccess(item, json);
let nextState = state.setIn(['items', sid], item);
return nextState;
}
... ... @@ -315,3 +253,55 @@ export default function postingReducer(state = initialState, action) {
break;
}
}
function postContentSuccess(item, json) {
let {
authorInfo,
blocks,// contentData order templateKey
browse,
createTime,
forumCode,
forumName,
id,
isForumTop,
isHot,
isIndexTop,
postsTitle,
praise,
praiseUsers,//headIcon nickName uid
shareGoods,
revieweState,
hasPraise,
largeImages,
LZ,
} = json;
item = item.set('isContentFetching', false)
.set('contentError', null)
.set('blocks',Immutable.fromJS(blocks))
.set('browse',browse)
.set('createTime',createTime)
.set('forumCode',forumCode)
.set('forumName',forumName)
.set('id',id)
.set('isForumTop',isForumTop)
.set('isHot',isHot)
.set('isIndexTop',isIndexTop)
.set('postsTitle',postsTitle)
.set('praise',praise)
.set('praiseUsers',Immutable.fromJS(praiseUsers.reverse()))
.set('LZ',LZ)
.set('revieweState',revieweState)
.set('largeImages',largeImages)
.set('hasPraise',hasPraise||'N')
.setIn(['shareGoods','productName'],shareGoods.productName)
.setIn(['shareGoods','productUrl'],shareGoods.productUrl)
.setIn(['shareGoods','salesPrice'],shareGoods.salesPrice)
.setIn(['shareGoods','goodsImage'],shareGoods.goodsImage)
.setIn(['shareGoods','productId'],shareGoods.productId)
.setIn(['authorInfo','headIcon'],authorInfo.headIcon)
.setIn(['authorInfo','nickName'],authorInfo.nickName)
.setIn(['authorInfo','uid'],authorInfo.uid);
return item;
}
... ...