...
|
...
|
@@ -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() {
|
...
|
...
|
|