...
|
...
|
@@ -2,7 +2,7 @@ |
|
|
|
|
|
import {Actions} from 'react-native-router-flux';
|
|
|
import MessageService from '../../services/MessageService';
|
|
|
// import timeago from 'timeago.js';
|
|
|
import timeago from '../../utils/timeago';
|
|
|
|
|
|
const {
|
|
|
GO_TO_MESSAGE_CENTER,
|
...
|
...
|
@@ -15,30 +15,63 @@ const { |
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
|
|
|
export function likeMessageRequest() {
|
|
|
export function likeMessageRequest(ptr) {
|
|
|
return {
|
|
|
type: LIKE_MESSAGE_REQUEST,
|
|
|
payload: ptr
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function likeMessageSuccess() {
|
|
|
export function likeMessageSuccess(json) {
|
|
|
return {
|
|
|
type: LIKE_MESSAGE_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function likeMessageFailue() {
|
|
|
export function likeMessageFailue(error) {
|
|
|
return {
|
|
|
type: LIKE_MESSAGE_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function likeMessage() {
|
|
|
export function likeMessage(ptr = false) {
|
|
|
return (dispatch, getState) => {
|
|
|
dispatch(likeMessageRequest());
|
|
|
return new MessageService().messageList(uid)
|
|
|
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 => {
|
|
|
dispatch(likeMessageSuccess(json));
|
|
|
let payload = parseLikeMessage(json);
|
|
|
if (!ptr) {
|
|
|
let oldList = message.like.list.toJS();
|
|
|
let list = [...oldList, ...payload.list];
|
|
|
payload.list = list;
|
|
|
}
|
|
|
dispatch(likeMessageSuccess(payload));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(likeMessageFailue(error));
|
...
|
...
|
@@ -46,30 +79,68 @@ export function likeMessage() { |
|
|
};
|
|
|
}
|
|
|
|
|
|
function parseLikeMessage(json) {
|
|
|
let {lastedTime, list} = json;
|
|
|
let messages = [];
|
|
|
list && list.map((item, i) => {
|
|
|
|
|
|
let id = item.id ? item.id : 0;
|
|
|
let title = item.title ? item.title : '';
|
|
|
let type = item.type ? item.type : 0;
|
|
|
let isRead = item.isRead ? item.isRead : 'Y';
|
|
|
let createTime = item.createTime;
|
|
|
let timeagoStr = timeago(createTime);
|
|
|
|
|
|
// 页面跳转
|
|
|
export function goToStatsPage(type) {
|
|
|
switch (type) {
|
|
|
|
|
|
case GO_TO_SYS_MESSAGE:
|
|
|
{
|
|
|
Actions.SystemMessage();
|
|
|
return {
|
|
|
type: GO_TO_SYS_MESSAGE,
|
|
|
let user = {};
|
|
|
let post = {};
|
|
|
let {content} = item;
|
|
|
if (content) {
|
|
|
let {userInfo, postInfo} = content;
|
|
|
if (userInfo) {
|
|
|
let nickName = userInfo.nickName ? userInfo.nickName : '';
|
|
|
let avatar = userInfo.headIcon ? userInfo.headIcon : '';
|
|
|
let uid = userInfo.uid ? userInfo.uid : 0;
|
|
|
let sign = userInfo.signature ? userInfo.signature : '';
|
|
|
let backgroundImage = userInfo.bgPic ? userInfo.bgPic : '';
|
|
|
user = {
|
|
|
nickName,
|
|
|
avatar,
|
|
|
uid,
|
|
|
sign,
|
|
|
backgroundImage,
|
|
|
};
|
|
|
}
|
|
|
if (postInfo) {
|
|
|
let sectionId = postInfo.sectionId ? postInfo.sectionId : '';
|
|
|
let postId = postInfo.postId ? postInfo.postId : 0;
|
|
|
postId = parseInt(postId);
|
|
|
let thumb = postInfo.content ? postInfo.content : '';
|
|
|
post = {
|
|
|
id: postId,
|
|
|
thumb,
|
|
|
sectionId,
|
|
|
};
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case GO_TO_LIKE_MESSAGE:
|
|
|
{
|
|
|
Actions.LikeMessage();
|
|
|
return {
|
|
|
type: GO_TO_LIKE_MESSAGE,
|
|
|
}
|
|
|
|
|
|
let message = {
|
|
|
id,
|
|
|
title,
|
|
|
type,
|
|
|
isRead,
|
|
|
createTime,
|
|
|
timeago: timeagoStr,
|
|
|
user,
|
|
|
post,
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
|
|
|
messages.push(message);
|
|
|
});
|
|
|
|
|
|
let endReached = messages.length == 0;
|
|
|
return {
|
|
|
lastedTime,
|
|
|
list: messages,
|
|
|
endReached,
|
|
|
}
|
|
|
} |
...
|
...
|
|