...
|
...
|
@@ -10,8 +10,11 @@ import PostingService from '../../services/PostingService'; |
|
|
import Immutable, {List, Record} from 'immutable';
|
|
|
import {
|
|
|
NativeModules,
|
|
|
ActionSheetIOS,
|
|
|
Alert,
|
|
|
} from 'react-native';
|
|
|
import timeago from 'timeago.js';
|
|
|
import HomeService from '../../services/HomeService';
|
|
|
|
|
|
const {
|
|
|
SUBJECT_CONTENT_REQUEST,
|
...
|
...
|
@@ -28,6 +31,11 @@ const { |
|
|
SUBJECT_REPLY_UPDATE,
|
|
|
|
|
|
GO_TO_LIKE_LIST,
|
|
|
SUBJECT_DO_NOTHING,
|
|
|
SUBJECT_LIKE_SUCCESS,
|
|
|
SUBJECT_UNLIKE_SUCCESS,
|
|
|
SUBJECT_LIKE_REQUEST,
|
|
|
SUBJECT_UNLIKE_REQUEST,
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
export function goToLikeList(postId, likeCount) {
|
...
|
...
|
@@ -38,6 +46,168 @@ export function goToLikeList(postId, likeCount) { |
|
|
};
|
|
|
}
|
|
|
|
|
|
export function subjectLikeRequest(json) {
|
|
|
return {
|
|
|
type: SUBJECT_LIKE_REQUEST,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function subjectLike(postId) {
|
|
|
return (dispatch, getState) => {
|
|
|
dispatch(subjectLikeRequest(postId));
|
|
|
let {user} = getState();
|
|
|
return new HomeService().postLike(postId, user.profile.uid)
|
|
|
.then(json => {
|
|
|
dispatch({
|
|
|
type: SUBJECT_LIKE_SUCCESS
|
|
|
})
|
|
|
__DEV__ && console.log(json);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
__DEV__ && console.log(error);
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function subjectUnlikeRequest(json) {
|
|
|
return {
|
|
|
type: SUBJECT_UNLIKE_REQUEST,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function subjectUnlike(postId) {
|
|
|
return (dispatch, getState) => {
|
|
|
dispatch(subjectUnlikeRequest(postId));
|
|
|
let {user} = getState();
|
|
|
return new HomeService().postUnlike(postId, user.profile.uid)
|
|
|
.then(json => {
|
|
|
dispatch({
|
|
|
type: UBJECT_UNLIKE_SUCCESS
|
|
|
})
|
|
|
__DEV__ && console.log(json);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
__DEV__ && console.log(error);
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
export function onRightPressed() {
|
|
|
return (dispatch, getState) => {
|
|
|
dispatch(onRight());
|
|
|
let {subject} = getState();
|
|
|
if (subject.LZ && !subject.revieweState) {
|
|
|
const BUTTONS = ['删除','取消'];
|
|
|
ActionSheetIOS.showActionSheetWithOptions({
|
|
|
options: BUTTONS,
|
|
|
cancelButtonIndex: 1,
|
|
|
},
|
|
|
|
|
|
(buttonIndex) => {
|
|
|
if (buttonIndex == 0) {
|
|
|
dispatch(doDelete(subject.id));
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
let params = {
|
|
|
postsId: subject.id,
|
|
|
appType: 1,
|
|
|
}
|
|
|
new PostingService().getShareUrl(params).then(json => {
|
|
|
let {subject} = getState();
|
|
|
let blockAry = subject.blocks.toJS();
|
|
|
let content = '';
|
|
|
for (var i = 0; i < blockAry.length; i++) {
|
|
|
if (blockAry[i].templateKey == 'text') {
|
|
|
content = blockAry[i].contentData||'';
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
let picUrl = '';
|
|
|
for (var i = 0; i < blockAry.length; i++) {
|
|
|
if (blockAry[i].templateKey == 'image') {
|
|
|
picUrl = blockAry[i].contentData||'';
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
let newSrc = picUrl;
|
|
|
if (picUrl.length) {
|
|
|
if (picUrl.indexOf('imageView') === -1) {
|
|
|
newSrc = picUrl + '?imageView2/' + '1' + '/w/' + '320' + '/h/' + '320';
|
|
|
} else {
|
|
|
newSrc = picUrl.replace('{mode}', '1')
|
|
|
.replace('{width}', '320')
|
|
|
.replace('{height}', '320');
|
|
|
}
|
|
|
}
|
|
|
let shareInfo = {
|
|
|
title: subject.postsTitle||'',
|
|
|
content,
|
|
|
'picUrl':newSrc,
|
|
|
linkUrl: json.shareUrl,
|
|
|
}
|
|
|
console.log(shareInfo);
|
|
|
dispatch(doShare(shareInfo));
|
|
|
}).catch(error => {
|
|
|
console.log(error);
|
|
|
Alert.alert('提示','获取分享信息失败');
|
|
|
})
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function onRight() {
|
|
|
return {
|
|
|
type:'SUBJECT_DO_NOTHING'
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function doShare(shareInfo) {
|
|
|
|
|
|
console.log(shareInfo);
|
|
|
NativeModules.YH_CommunityHelper.showShare(shareInfo);
|
|
|
|
|
|
return {
|
|
|
type:'SUBJECT_DO_NOTHING'
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function doDelete(postsId) {
|
|
|
|
|
|
Alert.alert('提示','是否确认删除?',
|
|
|
[{text:'否'},
|
|
|
{text:'是', onPress: ()=>{
|
|
|
Actions.pop();
|
|
|
new PostingService().deletePost(postsId).then(json => {
|
|
|
Alert.alert('提示','删除成功');
|
|
|
console.log('......del success ....... ' + json);
|
|
|
}).catch(error => {
|
|
|
Alert.alert('提示','删除失败');
|
|
|
console.log('....error.......... ' +error);
|
|
|
})
|
|
|
}}]);
|
|
|
console.log('deleted.............');
|
|
|
return {
|
|
|
type:'SUBJECT_DO_NOTHING'
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function doReport(params) {
|
|
|
new PostingService().reportPost(params).then(json => {
|
|
|
Alert.alert('提示','举报成功');
|
|
|
}).catch(error => {
|
|
|
Alert.alert('提示','举报失败');
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
type:'SUBJECT_DO_NOTHING'
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function requestPostContent(postsId) {
|
|
|
return dispatch => {
|
|
|
dispatch(doRequestContent());
|
...
|
...
|
@@ -47,6 +217,11 @@ export function requestPostContent(postsId) { |
|
|
NativeModules.YH_CommunityHelper.uid()
|
|
|
.then(uid => {
|
|
|
json.LZ = (uid == json.authorInfo.uid);
|
|
|
let rightImg = require('../../images/posting/share.png');
|
|
|
if (json.LZ&&!json.revieweState) {
|
|
|
rightImg = require('../../images/posting/more.png');
|
|
|
}
|
|
|
Actions.refresh({key: 'SubjectPost', rightButtonImage:rightImg});
|
|
|
dispatch(contentRequestSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
...
|
...
|
@@ -121,6 +296,10 @@ export function commentsRequestSuccess(json) { |
|
|
};
|
|
|
newBlocks.push(newItem);
|
|
|
})
|
|
|
if (replyTo) {
|
|
|
let nickName = replyTo.nickName||'';
|
|
|
replyTo.nickName = nickName;
|
|
|
}
|
|
|
let newObj={
|
|
|
commentId: id||'',
|
|
|
cidTo: postInfo.authorUid||'',
|
...
|
...
|
@@ -129,6 +308,7 @@ export function commentsRequestSuccess(json) { |
|
|
nickName: reply.nickName||'',
|
|
|
LZ:false,
|
|
|
blocks: newBlocks||[],
|
|
|
replyTo,
|
|
|
}
|
|
|
newList.push(newObj);
|
|
|
})
|
...
|
...
|
|