Updates comment-related redux code to support sdk version 0.53.0 (#259)
Updates comment-related redux code to support sdk version 0.53.0
This commit is contained in:
commit
2f68494b71
17 changed files with 649 additions and 103 deletions
288
dist/bundle.es.js
vendored
288
dist/bundle.es.js
vendored
|
@ -135,6 +135,15 @@ const COMMENT_LIST_FAILED = 'COMMENT_LIST_FAILED';
|
||||||
const COMMENT_CREATE_STARTED = 'COMMENT_CREATE_STARTED';
|
const COMMENT_CREATE_STARTED = 'COMMENT_CREATE_STARTED';
|
||||||
const COMMENT_CREATE_COMPLETED = 'COMMENT_CREATE_COMPLETED';
|
const COMMENT_CREATE_COMPLETED = 'COMMENT_CREATE_COMPLETED';
|
||||||
const COMMENT_CREATE_FAILED = 'COMMENT_CREATE_FAILED';
|
const COMMENT_CREATE_FAILED = 'COMMENT_CREATE_FAILED';
|
||||||
|
const COMMENT_ABANDON_STARTED = 'COMMENT_ABANDON_STARTED';
|
||||||
|
const COMMENT_ABANDON_COMPLETED = 'COMMENT_ABANDON_COMPLETED';
|
||||||
|
const COMMENT_ABANDON_FAILED = 'COMMENT_ABANDON_FAILED';
|
||||||
|
const COMMENT_UPDATE_STARTED = 'COMMENT_UPDATE_STARTED';
|
||||||
|
const COMMENT_UPDATE_COMPLETED = 'COMMENT_UPDATE_COMPLETED';
|
||||||
|
const COMMENT_UPDATE_FAILED = 'COMMENT_UPDATE_FAILED';
|
||||||
|
const COMMENT_HIDE_STARTED = 'COMMENT_HIDE_STARTED';
|
||||||
|
const COMMENT_HIDE_COMPLETED = 'COMMENT_HIDE_COMPLETED';
|
||||||
|
const COMMENT_HIDE_FAILED = 'COMMENT_HIDE_FAILED';
|
||||||
|
|
||||||
// Files
|
// Files
|
||||||
const FILE_LIST_STARTED = 'FILE_LIST_STARTED';
|
const FILE_LIST_STARTED = 'FILE_LIST_STARTED';
|
||||||
|
@ -382,6 +391,15 @@ var action_types = /*#__PURE__*/Object.freeze({
|
||||||
COMMENT_CREATE_STARTED: COMMENT_CREATE_STARTED,
|
COMMENT_CREATE_STARTED: COMMENT_CREATE_STARTED,
|
||||||
COMMENT_CREATE_COMPLETED: COMMENT_CREATE_COMPLETED,
|
COMMENT_CREATE_COMPLETED: COMMENT_CREATE_COMPLETED,
|
||||||
COMMENT_CREATE_FAILED: COMMENT_CREATE_FAILED,
|
COMMENT_CREATE_FAILED: COMMENT_CREATE_FAILED,
|
||||||
|
COMMENT_ABANDON_STARTED: COMMENT_ABANDON_STARTED,
|
||||||
|
COMMENT_ABANDON_COMPLETED: COMMENT_ABANDON_COMPLETED,
|
||||||
|
COMMENT_ABANDON_FAILED: COMMENT_ABANDON_FAILED,
|
||||||
|
COMMENT_UPDATE_STARTED: COMMENT_UPDATE_STARTED,
|
||||||
|
COMMENT_UPDATE_COMPLETED: COMMENT_UPDATE_COMPLETED,
|
||||||
|
COMMENT_UPDATE_FAILED: COMMENT_UPDATE_FAILED,
|
||||||
|
COMMENT_HIDE_STARTED: COMMENT_HIDE_STARTED,
|
||||||
|
COMMENT_HIDE_COMPLETED: COMMENT_HIDE_COMPLETED,
|
||||||
|
COMMENT_HIDE_FAILED: COMMENT_HIDE_FAILED,
|
||||||
FILE_LIST_STARTED: FILE_LIST_STARTED,
|
FILE_LIST_STARTED: FILE_LIST_STARTED,
|
||||||
FILE_LIST_SUCCEEDED: FILE_LIST_SUCCEEDED,
|
FILE_LIST_SUCCEEDED: FILE_LIST_SUCCEEDED,
|
||||||
FETCH_FILE_INFO_STARTED: FETCH_FILE_INFO_STARTED,
|
FETCH_FILE_INFO_STARTED: FETCH_FILE_INFO_STARTED,
|
||||||
|
@ -782,12 +800,12 @@ var daemon_settings = /*#__PURE__*/Object.freeze({
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* How to use this file:
|
* How to use this file:
|
||||||
* Settings exported from here will trigger the setting to be
|
* Settings exported from here will trigger the setting to be
|
||||||
* sent to the preference middleware when set using the
|
* sent to the preference middleware when set using the
|
||||||
* usual setDaemonSettings and clearDaemonSettings methods.
|
* usual setDaemonSettings and clearDaemonSettings methods.
|
||||||
*
|
*
|
||||||
* See redux/settings/actions in the app for where this is used.
|
* See redux/settings/actions in the app for where this is used.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const WALLET_SERVERS = LBRYUM_SERVERS;
|
const WALLET_SERVERS = LBRYUM_SERVERS;
|
||||||
|
@ -934,6 +952,11 @@ const Lbry = {
|
||||||
// Comments
|
// Comments
|
||||||
comment_list: (params = {}) => daemonCallWithResult('comment_list', params),
|
comment_list: (params = {}) => daemonCallWithResult('comment_list', params),
|
||||||
comment_create: (params = {}) => daemonCallWithResult('comment_create', params),
|
comment_create: (params = {}) => daemonCallWithResult('comment_create', params),
|
||||||
|
comment_hide: (params = {}) => daemonCallWithResult('comment_hide', params),
|
||||||
|
comment_abandon: (params = {}) => daemonCallWithResult('comment_abandon', params),
|
||||||
|
// requires SDK ver. 0.53.0
|
||||||
|
comment_update: (params = {}) => daemonCallWithResult('comment_update', params),
|
||||||
|
|
||||||
// Connect to the sdk
|
// Connect to the sdk
|
||||||
connect: () => {
|
connect: () => {
|
||||||
if (Lbry.connectPromise === null) {
|
if (Lbry.connectPromise === null) {
|
||||||
|
@ -1241,6 +1264,18 @@ function buildURI(UrlObj, includeProto = true, protoDefault = 'lbry://') {
|
||||||
deprecatedParts = _objectWithoutProperties(UrlObj, ['streamName', 'streamClaimId', 'channelName', 'channelClaimId', 'primaryClaimSequence', 'primaryBidPosition', 'secondaryClaimSequence', 'secondaryBidPosition']);
|
deprecatedParts = _objectWithoutProperties(UrlObj, ['streamName', 'streamClaimId', 'channelName', 'channelClaimId', 'primaryClaimSequence', 'primaryBidPosition', 'secondaryClaimSequence', 'secondaryBidPosition']);
|
||||||
const { claimId, claimName, contentName } = deprecatedParts;
|
const { claimId, claimName, contentName } = deprecatedParts;
|
||||||
|
|
||||||
|
{
|
||||||
|
if (claimId) {
|
||||||
|
console.error(__("'claimId' should no longer be used. Use 'streamClaimId' or 'channelClaimId' instead"));
|
||||||
|
}
|
||||||
|
if (claimName) {
|
||||||
|
console.error(__("'claimName' should no longer be used. Use 'streamClaimName' or 'channelClaimName' instead"));
|
||||||
|
}
|
||||||
|
if (contentName) {
|
||||||
|
console.error(__("'contentName' should no longer be used. Use 'streamName' instead"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!claimName && !channelName && !streamName) {
|
if (!claimName && !channelName && !streamName) {
|
||||||
console.error(__("'claimName', 'channelName', and 'streamName' are all empty. One must be present to build a url."));
|
console.error(__("'claimName', 'channelName', and 'streamName' are all empty. One must be present to build a url."));
|
||||||
}
|
}
|
||||||
|
@ -1565,7 +1600,10 @@ function extractUserState(rawObj) {
|
||||||
function doPopulateSharedUserState(sharedSettings) {
|
function doPopulateSharedUserState(sharedSettings) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
const { subscriptions, tags, blocked, settings } = extractUserState(sharedSettings);
|
const { subscriptions, tags, blocked, settings } = extractUserState(sharedSettings);
|
||||||
dispatch({ type: USER_STATE_POPULATE, data: { subscriptions, tags, blocked, settings } });
|
dispatch({
|
||||||
|
type: USER_STATE_POPULATE,
|
||||||
|
data: { subscriptions, tags, blocked, settings }
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4146,6 +4184,8 @@ const doUpdateSearchOptions = newOptions => (dispatch, getState) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
function savePosition(claimId, outpoint, position) {
|
function savePosition(claimId, outpoint, position) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -4223,9 +4263,10 @@ function doCommentCreate(comment = '', claim_id = '', channel, parent_id) {
|
||||||
const namedChannelClaim = myChannels && myChannels.find(myChannel => myChannel.name === channel);
|
const namedChannelClaim = myChannels && myChannels.find(myChannel => myChannel.name === channel);
|
||||||
const channel_id = namedChannelClaim ? namedChannelClaim.claim_id : null;
|
const channel_id = namedChannelClaim ? namedChannelClaim.claim_id : null;
|
||||||
return lbryProxy.comment_create({
|
return lbryProxy.comment_create({
|
||||||
comment,
|
comment: comment,
|
||||||
claim_id,
|
claim_id: claim_id,
|
||||||
channel_id
|
channel_id: channel_id,
|
||||||
|
parent_id: parent_id
|
||||||
}).then(result => {
|
}).then(result => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: COMMENT_CREATE_COMPLETED,
|
type: COMMENT_CREATE_COMPLETED,
|
||||||
|
@ -4247,6 +4288,96 @@ function doCommentCreate(comment = '', claim_id = '', channel, parent_id) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function doCommentHide(comment_id) {
|
||||||
|
return dispatch => {
|
||||||
|
dispatch({
|
||||||
|
type: COMMENT_HIDE_STARTED
|
||||||
|
});
|
||||||
|
return lbryProxy.comment_hide({
|
||||||
|
comment_ids: [comment_id]
|
||||||
|
}).then(result => {
|
||||||
|
dispatch({
|
||||||
|
type: COMMENT_HIDE_COMPLETED,
|
||||||
|
data: result
|
||||||
|
});
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch({
|
||||||
|
type: COMMENT_HIDE_FAILED,
|
||||||
|
data: error
|
||||||
|
});
|
||||||
|
dispatch(doToast({
|
||||||
|
message: 'There was an error hiding this comment. Please try again later.',
|
||||||
|
isError: true
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function doCommentAbandon(comment_id) {
|
||||||
|
return dispatch => {
|
||||||
|
dispatch({
|
||||||
|
type: COMMENT_ABANDON_STARTED
|
||||||
|
});
|
||||||
|
return lbryProxy.comment_abandon({
|
||||||
|
comment_id: comment_id
|
||||||
|
}).then(result => {
|
||||||
|
// Comment may not be deleted if the signing channel can't be signed.
|
||||||
|
// This will happen if the channel was recently created or abandoned.
|
||||||
|
if (result.abandoned) {
|
||||||
|
dispatch({
|
||||||
|
type: COMMENT_ABANDON_COMPLETED,
|
||||||
|
data: {
|
||||||
|
comment_id: comment_id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dispatch({
|
||||||
|
type: COMMENT_ABANDON_FAILED
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch({
|
||||||
|
type: COMMENT_ABANDON_FAILED,
|
||||||
|
data: error
|
||||||
|
});
|
||||||
|
dispatch(doToast({
|
||||||
|
message: 'There was an error hiding this comment. Please try again later.',
|
||||||
|
isError: true
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function doCommentUpdate(comment_id, comment) {
|
||||||
|
// if they provided an empty string, they must have wanted to abandon
|
||||||
|
if (comment === '') {
|
||||||
|
return doCommentAbandon(comment_id);
|
||||||
|
} else {
|
||||||
|
return dispatch => {
|
||||||
|
dispatch({
|
||||||
|
type: COMMENT_UPDATE_STARTED
|
||||||
|
});
|
||||||
|
return lbryProxy.comment_update({
|
||||||
|
comment_id: comment_id,
|
||||||
|
comment: comment
|
||||||
|
}).then(result => {
|
||||||
|
dispatch({
|
||||||
|
type: COMMENT_UPDATE_COMPLETED,
|
||||||
|
data: {
|
||||||
|
comment: result
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch({ type: COMMENT_UPDATE_FAILED, data: error });
|
||||||
|
dispatch(doToast({
|
||||||
|
message: 'There was an error hiding this comment. Please try again later.',
|
||||||
|
isError: true
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
const doToggleBlockChannel = uri => ({
|
const doToggleBlockChannel = uri => ({
|
||||||
|
@ -4663,9 +4794,11 @@ const handleActions = (actionMap, defaultState) => (state = defaultState, action
|
||||||
var _extends$8 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
var _extends$8 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||||
|
|
||||||
const defaultState$1 = {
|
const defaultState$1 = {
|
||||||
byId: {},
|
commentById: {}, // commentId -> Comment
|
||||||
commentsByUri: {},
|
byId: {}, // ClaimID -> list of comments
|
||||||
isLoading: false
|
commentsByUri: {}, // URI -> claimId
|
||||||
|
isLoading: false,
|
||||||
|
myComments: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
const commentReducer = handleActions({
|
const commentReducer = handleActions({
|
||||||
|
@ -4679,15 +4812,22 @@ const commentReducer = handleActions({
|
||||||
|
|
||||||
[COMMENT_CREATE_COMPLETED]: (state, action) => {
|
[COMMENT_CREATE_COMPLETED]: (state, action) => {
|
||||||
const { comment, claimId } = action.data;
|
const { comment, claimId } = action.data;
|
||||||
|
const commentById = Object.assign({}, state.commentById);
|
||||||
const byId = Object.assign({}, state.byId);
|
const byId = Object.assign({}, state.byId);
|
||||||
const comments = byId[claimId];
|
const comments = byId[claimId];
|
||||||
const newComments = comments.slice();
|
const newCommentIds = comments.slice();
|
||||||
|
|
||||||
newComments.unshift(comment);
|
// add the comment by its ID
|
||||||
byId[claimId] = newComments;
|
commentById[comment.comment_id] = comment;
|
||||||
|
|
||||||
|
// push the comment_id to the top of ID list
|
||||||
|
newCommentIds.unshift(comment.comment_id);
|
||||||
|
byId[claimId] = newCommentIds;
|
||||||
|
|
||||||
return _extends$8({}, state, {
|
return _extends$8({}, state, {
|
||||||
byId
|
commentById,
|
||||||
|
byId,
|
||||||
|
isLoading: false
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -4695,15 +4835,29 @@ const commentReducer = handleActions({
|
||||||
|
|
||||||
[COMMENT_LIST_COMPLETED]: (state, action) => {
|
[COMMENT_LIST_COMPLETED]: (state, action) => {
|
||||||
const { comments, claimId, uri } = action.data;
|
const { comments, claimId, uri } = action.data;
|
||||||
|
|
||||||
|
const commentById = Object.assign({}, state.commentById);
|
||||||
const byId = Object.assign({}, state.byId);
|
const byId = Object.assign({}, state.byId);
|
||||||
const commentsByUri = Object.assign({}, state.commentsByUri);
|
const commentsByUri = Object.assign({}, state.commentsByUri);
|
||||||
|
|
||||||
if (comments) {
|
if (comments) {
|
||||||
byId[claimId] = comments;
|
// we use an Array to preserve order of listing
|
||||||
|
// in reality this doesn't matter and we can just
|
||||||
|
// sort comments by their timestamp
|
||||||
|
const commentIds = Array(comments.length);
|
||||||
|
|
||||||
|
// map the comment_ids to the new comments
|
||||||
|
for (let i = 0; i < comments.length; i++) {
|
||||||
|
commentIds[i] = comments[i].comment_id;
|
||||||
|
commentById[commentIds[i]] = comments[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
byId[claimId] = commentIds;
|
||||||
commentsByUri[uri] = claimId;
|
commentsByUri[uri] = claimId;
|
||||||
}
|
}
|
||||||
return _extends$8({}, state, {
|
return _extends$8({}, state, {
|
||||||
byId,
|
byId,
|
||||||
|
commentById,
|
||||||
commentsByUri,
|
commentsByUri,
|
||||||
isLoading: false
|
isLoading: false
|
||||||
});
|
});
|
||||||
|
@ -4711,6 +4865,67 @@ const commentReducer = handleActions({
|
||||||
|
|
||||||
[COMMENT_LIST_FAILED]: (state, action) => _extends$8({}, state, {
|
[COMMENT_LIST_FAILED]: (state, action) => _extends$8({}, state, {
|
||||||
isLoading: false
|
isLoading: false
|
||||||
|
}),
|
||||||
|
[COMMENT_ABANDON_STARTED]: (state, action) => _extends$8({}, state, {
|
||||||
|
isLoading: true
|
||||||
|
}),
|
||||||
|
[COMMENT_ABANDON_COMPLETED]: (state, action) => {
|
||||||
|
const { comment_id } = action.data;
|
||||||
|
const commentById = Object.assign({}, state.commentById);
|
||||||
|
const byId = Object.assign({}, state.byId);
|
||||||
|
|
||||||
|
// to remove the comment and its references
|
||||||
|
const claimId = commentById[comment_id].claim_id;
|
||||||
|
for (let i = 0; i < byId[claimId].length; i++) {
|
||||||
|
if (byId[claimId][i] === comment_id) {
|
||||||
|
byId[claimId].splice(i, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete commentById[comment_id];
|
||||||
|
|
||||||
|
return _extends$8({}, state, {
|
||||||
|
commentById,
|
||||||
|
byId,
|
||||||
|
isLoading: false
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// do nothing
|
||||||
|
[COMMENT_ABANDON_FAILED]: (state, action) => _extends$8({}, state, {
|
||||||
|
isLoading: false
|
||||||
|
}),
|
||||||
|
// do nothing
|
||||||
|
[COMMENT_UPDATE_STARTED]: (state, action) => _extends$8({}, state, {
|
||||||
|
isLoading: true
|
||||||
|
}),
|
||||||
|
// replace existing comment with comment returned here under its comment_id
|
||||||
|
[COMMENT_UPDATE_COMPLETED]: (state, action) => {
|
||||||
|
const { comment } = action.data;
|
||||||
|
const commentById = Object.assign({}, state.commentById);
|
||||||
|
|
||||||
|
if (comment) {
|
||||||
|
commentById[comment.comment_id] = comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _extends$8({}, state, {
|
||||||
|
commentById,
|
||||||
|
isLoading: false
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// nothing can be done here
|
||||||
|
[COMMENT_UPDATE_FAILED]: (state, action) => _extends$8({}, state, {
|
||||||
|
isLoading: false
|
||||||
|
}),
|
||||||
|
// nothing can really be done here
|
||||||
|
[COMMENT_HIDE_STARTED]: (state, action) => _extends$8({}, state, {
|
||||||
|
isLoading: true
|
||||||
|
}),
|
||||||
|
[COMMENT_HIDE_COMPLETED]: (state, action) => _extends$8({}, state, { // todo: add HiddenComments state & create selectors
|
||||||
|
isLoading: false
|
||||||
|
}),
|
||||||
|
// nothing can be done here
|
||||||
|
[COMMENT_HIDE_FAILED]: (state, action) => _extends$8({}, state, {
|
||||||
|
isLoading: false
|
||||||
})
|
})
|
||||||
}, defaultState$1);
|
}, defaultState$1);
|
||||||
|
|
||||||
|
@ -5581,6 +5796,8 @@ const walletReducer = handleActions({
|
||||||
})
|
})
|
||||||
}, defaultState$a);
|
}, defaultState$a);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
const selectState$6 = state => state.content || {};
|
const selectState$6 = state => state.content || {};
|
||||||
|
|
||||||
const makeSelectContentPositionForUri = uri => reselect.createSelector(selectState$6, makeSelectClaimForUri(uri), (state, claim) => {
|
const makeSelectContentPositionForUri = uri => reselect.createSelector(selectState$6, makeSelectClaimForUri(uri), (state, claim) => {
|
||||||
|
@ -5622,8 +5839,30 @@ const selectError = reselect.createSelector(selectState$7, state => {
|
||||||
|
|
||||||
const selectState$8 = state => state.comments || {};
|
const selectState$8 = state => state.comments || {};
|
||||||
|
|
||||||
const selectCommentsById = reselect.createSelector(selectState$8, state => state.byId || {});
|
const selectCommentsById = reselect.createSelector(selectState$8, state => state.commentById || {});
|
||||||
|
|
||||||
|
const selectCommentsByClaimId = reselect.createSelector(selectState$8, selectCommentsById, (state, byId) => {
|
||||||
|
const byClaimId = state.byId || {};
|
||||||
|
const comments = {};
|
||||||
|
|
||||||
|
// replace every comment_id in the list with the actual comment object
|
||||||
|
Object.keys(byClaimId).forEach(claimId => {
|
||||||
|
const commentIds = byClaimId[claimId];
|
||||||
|
|
||||||
|
comments[claimId] = Array(commentIds === null ? 0 : commentIds.length);
|
||||||
|
for (let i = 0; i < commentIds.length; i++) {
|
||||||
|
comments[claimId][i] = byId[commentIds[i]];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return comments;
|
||||||
|
});
|
||||||
|
|
||||||
|
// previously this used a mapping from claimId -> Array<Comments>
|
||||||
|
/* export const selectCommentsById = createSelector(
|
||||||
|
selectState,
|
||||||
|
state => state.byId || {}
|
||||||
|
); */
|
||||||
const selectCommentsByUri = reselect.createSelector(selectState$8, state => {
|
const selectCommentsByUri = reselect.createSelector(selectState$8, state => {
|
||||||
const byUri = state.commentsByUri || {};
|
const byUri = state.commentsByUri || {};
|
||||||
const comments = {};
|
const comments = {};
|
||||||
|
@ -5635,14 +5874,18 @@ const selectCommentsByUri = reselect.createSelector(selectState$8, state => {
|
||||||
comments[uri] = claimId;
|
comments[uri] = claimId;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return comments;
|
return comments;
|
||||||
});
|
});
|
||||||
|
|
||||||
const makeSelectCommentsForUri = uri => reselect.createSelector(selectCommentsById, selectCommentsByUri, (byId, byUri) => {
|
const makeSelectCommentsForUri = uri => reselect.createSelector(selectCommentsByClaimId, selectCommentsByUri, (byClaimId, byUri) => {
|
||||||
const claimId = byUri[uri];
|
const claimId = byUri[uri];
|
||||||
return byId && byId[claimId];
|
return byClaimId && byClaimId[claimId];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// todo: allow SDK to retrieve user comments through comment_list
|
||||||
|
// todo: implement selectors for selecting comments owned by user
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
const selectState$9 = state => state.tags || {};
|
const selectState$9 = state => state.tags || {};
|
||||||
|
@ -5720,8 +5963,11 @@ exports.doCheckPendingPublishes = doCheckPendingPublishes;
|
||||||
exports.doClaimSearch = doClaimSearch;
|
exports.doClaimSearch = doClaimSearch;
|
||||||
exports.doClearPublish = doClearPublish;
|
exports.doClearPublish = doClearPublish;
|
||||||
exports.doClearSupport = doClearSupport;
|
exports.doClearSupport = doClearSupport;
|
||||||
|
exports.doCommentAbandon = doCommentAbandon;
|
||||||
exports.doCommentCreate = doCommentCreate;
|
exports.doCommentCreate = doCommentCreate;
|
||||||
|
exports.doCommentHide = doCommentHide;
|
||||||
exports.doCommentList = doCommentList;
|
exports.doCommentList = doCommentList;
|
||||||
|
exports.doCommentUpdate = doCommentUpdate;
|
||||||
exports.doCreateChannel = doCreateChannel;
|
exports.doCreateChannel = doCreateChannel;
|
||||||
exports.doDeletePurchasedUri = doDeletePurchasedUri;
|
exports.doDeletePurchasedUri = doDeletePurchasedUri;
|
||||||
exports.doDeleteTag = doDeleteTag;
|
exports.doDeleteTag = doDeleteTag;
|
||||||
|
|
32
dist/flow-typed/Comment.js
vendored
32
dist/flow-typed/Comment.js
vendored
|
@ -1,19 +1,23 @@
|
||||||
declare type Comment = {
|
declare type Comment = {
|
||||||
author?: string,
|
comment: string, // comment body
|
||||||
author_url?: string,
|
comment_id: string, // sha256 digest
|
||||||
claim_index?: number,
|
claim_id: string, // id linking to the claim this comment
|
||||||
comment_id?: number,
|
timestamp: number, // integer representing unix-time
|
||||||
downvotes?: number,
|
is_hidden: boolean, // claim owner may enable/disable this
|
||||||
message: string,
|
channel_id?: string, // claimId of channel signing this comment
|
||||||
omitted?: number,
|
channel_name?: string, // name of channel claim
|
||||||
reply_count?: number,
|
channel_url?: string, // full lbry url to signing channel
|
||||||
time_posted?: number,
|
signature?: string, // signature of comment by originating channel
|
||||||
upvotes?: number,
|
signing_ts?: string, // timestamp used when signing this comment
|
||||||
parent_id?: number,
|
is_channel_signature_valid?: boolean, // whether or not the signature could be validated
|
||||||
|
parent_id?: number, // comment_id of comment this is in reply to
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// todo: relate individual comments to their commentId
|
||||||
declare type CommentsState = {
|
declare type CommentsState = {
|
||||||
byId: {},
|
|
||||||
isLoading: boolean,
|
|
||||||
commentsByUri: { [string]: string },
|
commentsByUri: { [string]: string },
|
||||||
}
|
byId: { [string]: Array<string> },
|
||||||
|
commentById: { [string]: Comment },
|
||||||
|
isLoading: boolean,
|
||||||
|
myComments: ?Set<string>,
|
||||||
|
};
|
||||||
|
|
16
dist/flow-typed/Lbry.js
vendored
16
dist/flow-typed/Lbry.js
vendored
|
@ -125,6 +125,8 @@ declare type ChannelUpdateResponse = GenericTxResponse & {
|
||||||
};
|
};
|
||||||
|
|
||||||
declare type CommentCreateResponse = Comment;
|
declare type CommentCreateResponse = Comment;
|
||||||
|
declare type CommentUpdateResponse = Comment;
|
||||||
|
|
||||||
declare type CommentListResponse = {
|
declare type CommentListResponse = {
|
||||||
items: Array<Comment>,
|
items: Array<Comment>,
|
||||||
page: number,
|
page: number,
|
||||||
|
@ -133,6 +135,16 @@ declare type CommentListResponse = {
|
||||||
total_pages: number,
|
total_pages: number,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
declare type CommentHideResponse = {
|
||||||
|
// keyed by the CommentIds entered
|
||||||
|
[string]: { hidden: boolean },
|
||||||
|
};
|
||||||
|
|
||||||
|
declare type CommentAbandonResponse = {
|
||||||
|
// keyed by the CommentId given
|
||||||
|
abandoned: boolean,
|
||||||
|
};
|
||||||
|
|
||||||
declare type ChannelListResponse = {
|
declare type ChannelListResponse = {
|
||||||
items: Array<ChannelClaim>,
|
items: Array<ChannelClaim>,
|
||||||
page: number,
|
page: number,
|
||||||
|
@ -242,6 +254,10 @@ declare type LbryTypes = {
|
||||||
// Commenting
|
// Commenting
|
||||||
comment_list: (params: {}) => Promise<CommentListResponse>,
|
comment_list: (params: {}) => Promise<CommentListResponse>,
|
||||||
comment_create: (params: {}) => Promise<CommentCreateResponse>,
|
comment_create: (params: {}) => Promise<CommentCreateResponse>,
|
||||||
|
comment_update: (params: {}) => Promise<CommentUpdateResponse>,
|
||||||
|
comment_hide: (params: {}) => Promise<CommentHideResponse>,
|
||||||
|
comment_abandon: (params: {}) => Promise<CommentAbandonResponse>,
|
||||||
|
|
||||||
// Wallet utilities
|
// Wallet utilities
|
||||||
wallet_balance: (params: {}) => Promise<BalanceResponse>,
|
wallet_balance: (params: {}) => Promise<BalanceResponse>,
|
||||||
wallet_decrypt: (prams: {}) => Promise<boolean>,
|
wallet_decrypt: (prams: {}) => Promise<boolean>,
|
||||||
|
|
32
flow-typed/Comment.js
vendored
32
flow-typed/Comment.js
vendored
|
@ -1,19 +1,23 @@
|
||||||
declare type Comment = {
|
declare type Comment = {
|
||||||
author?: string,
|
comment: string, // comment body
|
||||||
author_url?: string,
|
comment_id: string, // sha256 digest
|
||||||
claim_index?: number,
|
claim_id: string, // id linking to the claim this comment
|
||||||
comment_id?: number,
|
timestamp: number, // integer representing unix-time
|
||||||
downvotes?: number,
|
is_hidden: boolean, // claim owner may enable/disable this
|
||||||
message: string,
|
channel_id?: string, // claimId of channel signing this comment
|
||||||
omitted?: number,
|
channel_name?: string, // name of channel claim
|
||||||
reply_count?: number,
|
channel_url?: string, // full lbry url to signing channel
|
||||||
time_posted?: number,
|
signature?: string, // signature of comment by originating channel
|
||||||
upvotes?: number,
|
signing_ts?: string, // timestamp used when signing this comment
|
||||||
parent_id?: number,
|
is_channel_signature_valid?: boolean, // whether or not the signature could be validated
|
||||||
|
parent_id?: number, // comment_id of comment this is in reply to
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// todo: relate individual comments to their commentId
|
||||||
declare type CommentsState = {
|
declare type CommentsState = {
|
||||||
byId: {},
|
|
||||||
isLoading: boolean,
|
|
||||||
commentsByUri: { [string]: string },
|
commentsByUri: { [string]: string },
|
||||||
}
|
byId: { [string]: Array<string> },
|
||||||
|
commentById: { [string]: Comment },
|
||||||
|
isLoading: boolean,
|
||||||
|
myComments: ?Set<string>,
|
||||||
|
};
|
||||||
|
|
16
flow-typed/Lbry.js
vendored
16
flow-typed/Lbry.js
vendored
|
@ -125,6 +125,8 @@ declare type ChannelUpdateResponse = GenericTxResponse & {
|
||||||
};
|
};
|
||||||
|
|
||||||
declare type CommentCreateResponse = Comment;
|
declare type CommentCreateResponse = Comment;
|
||||||
|
declare type CommentUpdateResponse = Comment;
|
||||||
|
|
||||||
declare type CommentListResponse = {
|
declare type CommentListResponse = {
|
||||||
items: Array<Comment>,
|
items: Array<Comment>,
|
||||||
page: number,
|
page: number,
|
||||||
|
@ -133,6 +135,16 @@ declare type CommentListResponse = {
|
||||||
total_pages: number,
|
total_pages: number,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
declare type CommentHideResponse = {
|
||||||
|
// keyed by the CommentIds entered
|
||||||
|
[string]: { hidden: boolean },
|
||||||
|
};
|
||||||
|
|
||||||
|
declare type CommentAbandonResponse = {
|
||||||
|
// keyed by the CommentId given
|
||||||
|
abandoned: boolean,
|
||||||
|
};
|
||||||
|
|
||||||
declare type ChannelListResponse = {
|
declare type ChannelListResponse = {
|
||||||
items: Array<ChannelClaim>,
|
items: Array<ChannelClaim>,
|
||||||
page: number,
|
page: number,
|
||||||
|
@ -242,6 +254,10 @@ declare type LbryTypes = {
|
||||||
// Commenting
|
// Commenting
|
||||||
comment_list: (params: {}) => Promise<CommentListResponse>,
|
comment_list: (params: {}) => Promise<CommentListResponse>,
|
||||||
comment_create: (params: {}) => Promise<CommentCreateResponse>,
|
comment_create: (params: {}) => Promise<CommentCreateResponse>,
|
||||||
|
comment_update: (params: {}) => Promise<CommentUpdateResponse>,
|
||||||
|
comment_hide: (params: {}) => Promise<CommentHideResponse>,
|
||||||
|
comment_abandon: (params: {}) => Promise<CommentAbandonResponse>,
|
||||||
|
|
||||||
// Wallet utilities
|
// Wallet utilities
|
||||||
wallet_balance: (params: {}) => Promise<BalanceResponse>,
|
wallet_balance: (params: {}) => Promise<BalanceResponse>,
|
||||||
wallet_decrypt: (prams: {}) => Promise<boolean>,
|
wallet_decrypt: (prams: {}) => Promise<boolean>,
|
||||||
|
|
|
@ -111,6 +111,15 @@ export const COMMENT_LIST_FAILED = 'COMMENT_LIST_FAILED';
|
||||||
export const COMMENT_CREATE_STARTED = 'COMMENT_CREATE_STARTED';
|
export const COMMENT_CREATE_STARTED = 'COMMENT_CREATE_STARTED';
|
||||||
export const COMMENT_CREATE_COMPLETED = 'COMMENT_CREATE_COMPLETED';
|
export const COMMENT_CREATE_COMPLETED = 'COMMENT_CREATE_COMPLETED';
|
||||||
export const COMMENT_CREATE_FAILED = 'COMMENT_CREATE_FAILED';
|
export const COMMENT_CREATE_FAILED = 'COMMENT_CREATE_FAILED';
|
||||||
|
export const COMMENT_ABANDON_STARTED = 'COMMENT_ABANDON_STARTED';
|
||||||
|
export const COMMENT_ABANDON_COMPLETED = 'COMMENT_ABANDON_COMPLETED';
|
||||||
|
export const COMMENT_ABANDON_FAILED = 'COMMENT_ABANDON_FAILED';
|
||||||
|
export const COMMENT_UPDATE_STARTED = 'COMMENT_UPDATE_STARTED';
|
||||||
|
export const COMMENT_UPDATE_COMPLETED = 'COMMENT_UPDATE_COMPLETED';
|
||||||
|
export const COMMENT_UPDATE_FAILED = 'COMMENT_UPDATE_FAILED';
|
||||||
|
export const COMMENT_HIDE_STARTED = 'COMMENT_HIDE_STARTED';
|
||||||
|
export const COMMENT_HIDE_COMPLETED = 'COMMENT_HIDE_COMPLETED';
|
||||||
|
export const COMMENT_HIDE_FAILED = 'COMMENT_HIDE_FAILED';
|
||||||
|
|
||||||
// Files
|
// Files
|
||||||
export const FILE_LIST_STARTED = 'FILE_LIST_STARTED';
|
export const FILE_LIST_STARTED = 'FILE_LIST_STARTED';
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* How to use this file:
|
* How to use this file:
|
||||||
* Settings exported from here will trigger the setting to be
|
* Settings exported from here will trigger the setting to be
|
||||||
* sent to the preference middleware when set using the
|
* sent to the preference middleware when set using the
|
||||||
* usual setDaemonSettings and clearDaemonSettings methods.
|
* usual setDaemonSettings and clearDaemonSettings methods.
|
||||||
*
|
*
|
||||||
* See redux/settings/actions in the app for where this is used.
|
* See redux/settings/actions in the app for where this is used.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as DAEMON_SETTINGS from './daemon_settings';
|
import * as DAEMON_SETTINGS from './daemon_settings';
|
||||||
|
|
|
@ -122,7 +122,13 @@ export {
|
||||||
|
|
||||||
export { doToggleTagFollow, doAddTag, doDeleteTag } from 'redux/actions/tags';
|
export { doToggleTagFollow, doAddTag, doDeleteTag } from 'redux/actions/tags';
|
||||||
|
|
||||||
export { doCommentList, doCommentCreate } from 'redux/actions/comments';
|
export {
|
||||||
|
doCommentList,
|
||||||
|
doCommentCreate,
|
||||||
|
doCommentAbandon,
|
||||||
|
doCommentHide,
|
||||||
|
doCommentUpdate,
|
||||||
|
} from 'redux/actions/comments';
|
||||||
|
|
||||||
export { doToggleBlockChannel } from 'redux/actions/blocked';
|
export { doToggleBlockChannel } from 'redux/actions/blocked';
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,11 @@ const Lbry: LbryTypes = {
|
||||||
// Comments
|
// Comments
|
||||||
comment_list: (params = {}) => daemonCallWithResult('comment_list', params),
|
comment_list: (params = {}) => daemonCallWithResult('comment_list', params),
|
||||||
comment_create: (params = {}) => daemonCallWithResult('comment_create', params),
|
comment_create: (params = {}) => daemonCallWithResult('comment_create', params),
|
||||||
|
comment_hide: (params = {}) => daemonCallWithResult('comment_hide', params),
|
||||||
|
comment_abandon: (params = {}) => daemonCallWithResult('comment_abandon', params),
|
||||||
|
// requires SDK ver. 0.53.0
|
||||||
|
comment_update: (params = {}) => daemonCallWithResult('comment_update', params),
|
||||||
|
|
||||||
// Connect to the sdk
|
// Connect to the sdk
|
||||||
connect: () => {
|
connect: () => {
|
||||||
if (Lbry.connectPromise === null) {
|
if (Lbry.connectPromise === null) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ export function doCommentCreate(
|
||||||
comment: string = '',
|
comment: string = '',
|
||||||
claim_id: string = '',
|
claim_id: string = '',
|
||||||
channel: ?string,
|
channel: ?string,
|
||||||
parent_id?: number
|
parent_id?: string
|
||||||
) {
|
) {
|
||||||
return (dispatch: Dispatch, getState: GetState) => {
|
return (dispatch: Dispatch, getState: GetState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
@ -55,11 +55,12 @@ export function doCommentCreate(
|
||||||
myChannels && myChannels.find(myChannel => myChannel.name === channel);
|
myChannels && myChannels.find(myChannel => myChannel.name === channel);
|
||||||
const channel_id = namedChannelClaim ? namedChannelClaim.claim_id : null;
|
const channel_id = namedChannelClaim ? namedChannelClaim.claim_id : null;
|
||||||
return Lbry.comment_create({
|
return Lbry.comment_create({
|
||||||
comment,
|
comment: comment,
|
||||||
claim_id,
|
claim_id: claim_id,
|
||||||
channel_id,
|
channel_id: channel_id,
|
||||||
|
parent_id: parent_id,
|
||||||
})
|
})
|
||||||
.then((result: Comment) => {
|
.then((result: CommentCreateResponse) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.COMMENT_CREATE_COMPLETED,
|
type: ACTIONS.COMMENT_CREATE_COMPLETED,
|
||||||
data: {
|
data: {
|
||||||
|
@ -82,3 +83,105 @@ export function doCommentCreate(
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function doCommentHide(comment_id: string) {
|
||||||
|
return (dispatch: Dispatch) => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.COMMENT_HIDE_STARTED,
|
||||||
|
});
|
||||||
|
return Lbry.comment_hide({
|
||||||
|
comment_ids: [comment_id],
|
||||||
|
})
|
||||||
|
.then((result: CommentHideResponse) => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.COMMENT_HIDE_COMPLETED,
|
||||||
|
data: result,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.COMMENT_HIDE_FAILED,
|
||||||
|
data: error,
|
||||||
|
});
|
||||||
|
dispatch(
|
||||||
|
doToast({
|
||||||
|
message: 'There was an error hiding this comment. Please try again later.',
|
||||||
|
isError: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doCommentAbandon(comment_id: string) {
|
||||||
|
return (dispatch: Dispatch) => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.COMMENT_ABANDON_STARTED,
|
||||||
|
});
|
||||||
|
return Lbry.comment_abandon({
|
||||||
|
comment_id: comment_id,
|
||||||
|
})
|
||||||
|
.then((result: CommentAbandonResponse) => {
|
||||||
|
// Comment may not be deleted if the signing channel can't be signed.
|
||||||
|
// This will happen if the channel was recently created or abandoned.
|
||||||
|
if (result.abandoned) {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.COMMENT_ABANDON_COMPLETED,
|
||||||
|
data: {
|
||||||
|
comment_id: comment_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.COMMENT_ABANDON_FAILED,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.COMMENT_ABANDON_FAILED,
|
||||||
|
data: error,
|
||||||
|
});
|
||||||
|
dispatch(
|
||||||
|
doToast({
|
||||||
|
message: 'There was an error hiding this comment. Please try again later.',
|
||||||
|
isError: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doCommentUpdate(comment_id: string, comment: string) {
|
||||||
|
// if they provided an empty string, they must have wanted to abandon
|
||||||
|
if (comment === '') {
|
||||||
|
return doCommentAbandon(comment_id);
|
||||||
|
} else {
|
||||||
|
return (dispatch: Dispatch) => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.COMMENT_UPDATE_STARTED,
|
||||||
|
});
|
||||||
|
return Lbry.comment_update({
|
||||||
|
comment_id: comment_id,
|
||||||
|
comment: comment,
|
||||||
|
})
|
||||||
|
.then((result: CommentUpdateResponse) => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.COMMENT_UPDATE_COMPLETED,
|
||||||
|
data: {
|
||||||
|
comment: result,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
dispatch({ type: ACTIONS.COMMENT_UPDATE_FAILED, data: error });
|
||||||
|
dispatch(
|
||||||
|
doToast({
|
||||||
|
message: 'There was an error hiding this comment. Please try again later.',
|
||||||
|
isError: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
// @flow
|
||||||
import * as ACTIONS from 'constants/action_types';
|
import * as ACTIONS from 'constants/action_types';
|
||||||
|
|
||||||
export function savePosition(claimId: string, outpoint: string, position: number) {
|
export function savePosition(claimId: string, outpoint: string, position: number) {
|
||||||
return dispatch => {
|
return (dispatch: Dispatch) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.SET_CONTENT_POSITION,
|
type: ACTIONS.SET_CONTENT_POSITION,
|
||||||
data: { claimId, outpoint, position },
|
data: { claimId, outpoint, position },
|
||||||
|
|
|
@ -14,7 +14,7 @@ type SharedData = {
|
||||||
|
|
||||||
function extractUserState(rawObj: SharedData) {
|
function extractUserState(rawObj: SharedData) {
|
||||||
if (rawObj && rawObj.version === '0.1' && rawObj.value) {
|
if (rawObj && rawObj.version === '0.1' && rawObj.value) {
|
||||||
const { subscriptions, tags, blocked, settings} = rawObj.value;
|
const { subscriptions, tags, blocked, settings } = rawObj.value;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...(subscriptions ? { subscriptions } : {}),
|
...(subscriptions ? { subscriptions } : {}),
|
||||||
|
@ -30,7 +30,10 @@ function extractUserState(rawObj: SharedData) {
|
||||||
export function doPopulateSharedUserState(sharedSettings: any) {
|
export function doPopulateSharedUserState(sharedSettings: any) {
|
||||||
return (dispatch: Dispatch) => {
|
return (dispatch: Dispatch) => {
|
||||||
const { subscriptions, tags, blocked, settings } = extractUserState(sharedSettings);
|
const { subscriptions, tags, blocked, settings } = extractUserState(sharedSettings);
|
||||||
dispatch({ type: ACTIONS.USER_STATE_POPULATE, data: { subscriptions, tags, blocked, settings } });
|
dispatch({
|
||||||
|
type: ACTIONS.USER_STATE_POPULATE,
|
||||||
|
data: { subscriptions, tags, blocked, settings },
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,7 @@ export const blockedReducer = handleActions(
|
||||||
const { blocked } = action.data;
|
const { blocked } = action.data;
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
blockedChannels:
|
blockedChannels: blocked && blocked.length ? blocked : state.blockedChannels,
|
||||||
blocked && blocked.length ? blocked : state.blockedChannels,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,9 +3,11 @@ import * as ACTIONS from 'constants/action_types';
|
||||||
import { handleActions } from 'util/redux-utils';
|
import { handleActions } from 'util/redux-utils';
|
||||||
|
|
||||||
const defaultState: CommentsState = {
|
const defaultState: CommentsState = {
|
||||||
byId: {},
|
commentById: {}, // commentId -> Comment
|
||||||
commentsByUri: {},
|
byId: {}, // ClaimID -> list of comments
|
||||||
|
commentsByUri: {}, // URI -> claimId
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
myComments: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const commentReducer = handleActions(
|
export const commentReducer = handleActions(
|
||||||
|
@ -21,17 +23,24 @@ export const commentReducer = handleActions(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
[ACTIONS.COMMENT_CREATE_COMPLETED]: (state: CommentsState, action: any): CommentsState => {
|
[ACTIONS.COMMENT_CREATE_COMPLETED]: (state: CommentsState, action: any): CommentsState => {
|
||||||
const { comment, claimId }: any = action.data;
|
const { comment, claimId }: { comment: Comment, claimId: string } = action.data;
|
||||||
|
const commentById = Object.assign({}, state.commentById);
|
||||||
const byId = Object.assign({}, state.byId);
|
const byId = Object.assign({}, state.byId);
|
||||||
const comments = byId[claimId];
|
const comments = byId[claimId];
|
||||||
const newComments = comments.slice();
|
const newCommentIds = comments.slice();
|
||||||
|
|
||||||
newComments.unshift(comment);
|
// add the comment by its ID
|
||||||
byId[claimId] = newComments;
|
commentById[comment.comment_id] = comment;
|
||||||
|
|
||||||
|
// push the comment_id to the top of ID list
|
||||||
|
newCommentIds.unshift(comment.comment_id);
|
||||||
|
byId[claimId] = newCommentIds;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
commentById,
|
||||||
byId,
|
byId,
|
||||||
|
isLoading: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -39,16 +48,30 @@ export const commentReducer = handleActions(
|
||||||
|
|
||||||
[ACTIONS.COMMENT_LIST_COMPLETED]: (state: CommentsState, action: any) => {
|
[ACTIONS.COMMENT_LIST_COMPLETED]: (state: CommentsState, action: any) => {
|
||||||
const { comments, claimId, uri } = action.data;
|
const { comments, claimId, uri } = action.data;
|
||||||
|
|
||||||
|
const commentById = Object.assign({}, state.commentById);
|
||||||
const byId = Object.assign({}, state.byId);
|
const byId = Object.assign({}, state.byId);
|
||||||
const commentsByUri = Object.assign({}, state.commentsByUri);
|
const commentsByUri = Object.assign({}, state.commentsByUri);
|
||||||
|
|
||||||
if (comments) {
|
if (comments) {
|
||||||
byId[claimId] = comments;
|
// we use an Array to preserve order of listing
|
||||||
|
// in reality this doesn't matter and we can just
|
||||||
|
// sort comments by their timestamp
|
||||||
|
const commentIds = Array(comments.length);
|
||||||
|
|
||||||
|
// map the comment_ids to the new comments
|
||||||
|
for (let i = 0; i < comments.length; i++) {
|
||||||
|
commentIds[i] = comments[i].comment_id;
|
||||||
|
commentById[commentIds[i]] = comments[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
byId[claimId] = commentIds;
|
||||||
commentsByUri[uri] = claimId;
|
commentsByUri[uri] = claimId;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
byId,
|
byId,
|
||||||
|
commentById,
|
||||||
commentsByUri,
|
commentsByUri,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
};
|
};
|
||||||
|
@ -58,6 +81,76 @@ export const commentReducer = handleActions(
|
||||||
...state,
|
...state,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
}),
|
}),
|
||||||
|
[ACTIONS.COMMENT_ABANDON_STARTED]: (state: CommentsState, action: any) => ({
|
||||||
|
...state,
|
||||||
|
isLoading: true,
|
||||||
|
}),
|
||||||
|
[ACTIONS.COMMENT_ABANDON_COMPLETED]: (state: CommentsState, action: any) => {
|
||||||
|
const { comment_id } = action.data;
|
||||||
|
const commentById = Object.assign({}, state.commentById);
|
||||||
|
const byId = Object.assign({}, state.byId);
|
||||||
|
|
||||||
|
// to remove the comment and its references
|
||||||
|
const claimId = commentById[comment_id].claim_id;
|
||||||
|
for (let i = 0; i < byId[claimId].length; i++) {
|
||||||
|
if (byId[claimId][i] === comment_id) {
|
||||||
|
byId[claimId].splice(i, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete commentById[comment_id];
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
commentById,
|
||||||
|
byId,
|
||||||
|
isLoading: false,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
// do nothing
|
||||||
|
[ACTIONS.COMMENT_ABANDON_FAILED]: (state: CommentsState, action: any) => ({
|
||||||
|
...state,
|
||||||
|
isLoading: false,
|
||||||
|
}),
|
||||||
|
// do nothing
|
||||||
|
[ACTIONS.COMMENT_UPDATE_STARTED]: (state: CommentsState, action: any) => ({
|
||||||
|
...state,
|
||||||
|
isLoading: true,
|
||||||
|
}),
|
||||||
|
// replace existing comment with comment returned here under its comment_id
|
||||||
|
[ACTIONS.COMMENT_UPDATE_COMPLETED]: (state: CommentsState, action: any) => {
|
||||||
|
const { comment } = action.data;
|
||||||
|
const commentById = Object.assign({}, state.commentById);
|
||||||
|
|
||||||
|
if (comment) {
|
||||||
|
commentById[comment.comment_id] = comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
commentById,
|
||||||
|
isLoading: false,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
// nothing can be done here
|
||||||
|
[ACTIONS.COMMENT_UPDATE_FAILED]: (state: CommentsState, action: any) => ({
|
||||||
|
...state,
|
||||||
|
isLoading: false,
|
||||||
|
}),
|
||||||
|
// nothing can really be done here
|
||||||
|
[ACTIONS.COMMENT_HIDE_STARTED]: (state: CommentsState, action: any) => ({
|
||||||
|
...state,
|
||||||
|
isLoading: true,
|
||||||
|
}),
|
||||||
|
[ACTIONS.COMMENT_HIDE_COMPLETED]: (state: CommentsState, action: any) => ({
|
||||||
|
...state, // todo: add HiddenComments state & create selectors
|
||||||
|
isLoading: false,
|
||||||
|
}),
|
||||||
|
// nothing can be done here
|
||||||
|
[ACTIONS.COMMENT_HIDE_FAILED]: (state: CommentsState, action: any) => ({
|
||||||
|
...state,
|
||||||
|
isLoading: false,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
defaultState
|
defaultState
|
||||||
);
|
);
|
||||||
|
|
|
@ -5,9 +5,35 @@ const selectState = state => state.comments || {};
|
||||||
|
|
||||||
export const selectCommentsById = createSelector(
|
export const selectCommentsById = createSelector(
|
||||||
selectState,
|
selectState,
|
||||||
state => state.byId || {}
|
state => state.commentById || {}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const selectCommentsByClaimId = createSelector(
|
||||||
|
selectState,
|
||||||
|
selectCommentsById,
|
||||||
|
(state, byId) => {
|
||||||
|
const byClaimId = state.byId || {};
|
||||||
|
const comments = {};
|
||||||
|
|
||||||
|
// replace every comment_id in the list with the actual comment object
|
||||||
|
Object.keys(byClaimId).forEach(claimId => {
|
||||||
|
const commentIds = byClaimId[claimId];
|
||||||
|
|
||||||
|
comments[claimId] = Array(commentIds === null ? 0 : commentIds.length);
|
||||||
|
for (let i = 0; i < commentIds.length; i++) {
|
||||||
|
comments[claimId][i] = byId[commentIds[i]];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return comments;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// previously this used a mapping from claimId -> Array<Comments>
|
||||||
|
/* export const selectCommentsById = createSelector(
|
||||||
|
selectState,
|
||||||
|
state => state.byId || {}
|
||||||
|
); */
|
||||||
export const selectCommentsByUri = createSelector(
|
export const selectCommentsByUri = createSelector(
|
||||||
selectState,
|
selectState,
|
||||||
state => {
|
state => {
|
||||||
|
@ -21,16 +47,20 @@ export const selectCommentsByUri = createSelector(
|
||||||
comments[uri] = claimId;
|
comments[uri] = claimId;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const makeSelectCommentsForUri = (uri: string) =>
|
export const makeSelectCommentsForUri = (uri: string) =>
|
||||||
createSelector(
|
createSelector(
|
||||||
selectCommentsById,
|
selectCommentsByClaimId,
|
||||||
selectCommentsByUri,
|
selectCommentsByUri,
|
||||||
(byId, byUri) => {
|
(byClaimId, byUri) => {
|
||||||
const claimId = byUri[uri];
|
const claimId = byUri[uri];
|
||||||
return byId && byId[claimId];
|
return byClaimId && byClaimId[claimId];
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// todo: allow SDK to retrieve user comments through comment_list
|
||||||
|
// todo: implement selectors for selecting comments owned by user
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
|
// @flow
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import { makeSelectClaimForUri } from 'redux/selectors/claims';
|
import { makeSelectClaimForUri } from 'redux/selectors/claims';
|
||||||
|
|
||||||
export const selectState = (state: any) => state.content || {};
|
export const selectState = (state: any) => state.content || {};
|
||||||
|
|
||||||
export const makeSelectContentPositionForUri = (uri: string) =>
|
export const makeSelectContentPositionForUri = (uri: string) =>
|
||||||
createSelector(selectState, makeSelectClaimForUri(uri), (state, claim) => {
|
createSelector(
|
||||||
if (!claim) {
|
selectState,
|
||||||
return null;
|
makeSelectClaimForUri(uri),
|
||||||
|
(state, claim) => {
|
||||||
|
if (!claim) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const outpoint = `${claim.txid}:${claim.nout}`;
|
||||||
|
const id = claim.claim_id;
|
||||||
|
return state.positions[id] ? state.positions[id][outpoint] : null;
|
||||||
}
|
}
|
||||||
const outpoint = `${claim.txid}:${claim.nout}`;
|
);
|
||||||
const id = claim.claim_id;
|
|
||||||
return state.positions[id] ? state.positions[id][outpoint] : null;
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,26 +1,32 @@
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
|
|
||||||
export const selectState = (state) => state.notifications || {};
|
export const selectState = state => state.notifications || {};
|
||||||
|
|
||||||
export const selectToast = createSelector(selectState, (state) => {
|
export const selectToast = createSelector(
|
||||||
if (state.toasts.length) {
|
selectState,
|
||||||
const { id, params } = state.toasts[0];
|
state => {
|
||||||
return {
|
if (state.toasts.length) {
|
||||||
id,
|
const { id, params } = state.toasts[0];
|
||||||
...params,
|
return {
|
||||||
};
|
id,
|
||||||
|
...params,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return null;
|
export const selectError = createSelector(
|
||||||
});
|
selectState,
|
||||||
|
state => {
|
||||||
|
if (state.errors.length) {
|
||||||
|
const { error } = state.errors[0];
|
||||||
|
return {
|
||||||
|
error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const selectError = createSelector(selectState, (state) => {
|
return null;
|
||||||
if (state.errors.length) {
|
|
||||||
const { error } = state.errors[0];
|
|
||||||
return {
|
|
||||||
error,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in a new issue