-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] fetch all replies #8
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ import api from '../api'; | |
import { deleteFromTimelines } from './timelines'; | ||
import { importFetchedStatus, importFetchedStatuses } from './importer'; | ||
import { ensureComposeIsVisible, setComposeToStatus } from './compose'; | ||
import { submitSearch } from './search'; | ||
import { showAlert } from './alerts'; | ||
|
||
export const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST'; | ||
export const STATUS_FETCH_SUCCESS = 'STATUS_FETCH_SUCCESS'; | ||
|
@@ -16,6 +18,10 @@ export const CONTEXT_FETCH_REQUEST = 'CONTEXT_FETCH_REQUEST'; | |
export const CONTEXT_FETCH_SUCCESS = 'CONTEXT_FETCH_SUCCESS'; | ||
export const CONTEXT_FETCH_FAIL = 'CONTEXT_FETCH_FAIL'; | ||
|
||
export const EXTERNAL_CONTEXT_FETCH_REQUEST = 'EXTERNAL_CONTEXT_FETCH_REQUEST'; | ||
export const EXTERNAL_CONTEXT_FETCH_SUCCESS = 'EXTERNAL_CONTEXT_FETCH_SUCCESS'; | ||
export const EXTERNAL_CONTEXT_FETCH_FAIL = 'EXTERNAL_CONTEXT_FETCH_FAIL'; | ||
|
||
export const STATUS_MUTE_REQUEST = 'STATUS_MUTE_REQUEST'; | ||
export const STATUS_MUTE_SUCCESS = 'STATUS_MUTE_SUCCESS'; | ||
export const STATUS_MUTE_FAIL = 'STATUS_MUTE_FAIL'; | ||
|
@@ -219,6 +225,65 @@ export function fetchContextFail(id, error) { | |
}; | ||
}; | ||
|
||
|
||
|
||
export function fetchExternalContext(status_url, id){ | ||
// Get just the protocol and domain of the instance | ||
// note that we are just assuming that the api is at <domain>/api | ||
// since I don't know a better way of finding it | ||
let { origin, pathname } = new URL(status_url); | ||
let paths = pathname.split('/'); | ||
let external_id = paths[paths.length - 1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just wondering is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no i don't think so, each instance makes its own local IDs for posts that it uses internally which don't necessarily match the Ids used by other instances. |
||
|
||
return (dispatch, getState) => { | ||
dispatch(fetchExternalContextRequest(id)); | ||
|
||
api(getState).get(`${origin}/api/v1/statuses/${external_id}/context`).then(response => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we do a check here whether the protocol property of ${origin} contains https or not? just for security to avoid sending a request to an http server? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ToDo: we'd need to add handlers for non-mastodon softwares |
||
dispatch(showAlert('Getting Replies...', `Getting ${response.data.descendants.length} Replies.`)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Todo: We could maybe make this alert more accessible? It is currently in English. If possible, we could enable translation into other languages in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, I gotta see how the translation system works and then I'll change |
||
response.data.descendants.forEach((status) => { | ||
dispatch(submitSearch(status.url)); | ||
}); | ||
// dispatch(importFetchedStatuses(response.data.ancestors.concat(response.data.descendants))); | ||
dispatch(fetchExternalContextSuccess(id, response.data.ancestors, response.data.descendants)); | ||
|
||
}).catch(error => { | ||
if (error.response && error.response.status === 404) { | ||
// dispatch(deleteFromTimelines(id)); | ||
} | ||
|
||
dispatch(fetchContextFail(id, error)); | ||
}); | ||
}; | ||
} | ||
|
||
|
||
export function fetchExternalContextRequest(id) { | ||
return { | ||
type: EXTERNAL_CONTEXT_FETCH_REQUEST, | ||
id, | ||
}; | ||
}; | ||
|
||
export function fetchExternalContextSuccess(id, ancestors, descendants) { | ||
console.log('fetch success'); | ||
return { | ||
type: EXTERNAL_CONTEXT_FETCH_SUCCESS, | ||
id, | ||
ancestors, | ||
descendants, | ||
statuses: ancestors.concat(descendants), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we concat only those descendants where |
||
}; | ||
}; | ||
|
||
export function fetchExternalContextFail(id, error) { | ||
return { | ||
type: EXTERNAL_CONTEXT_FETCH_FAIL, | ||
id, | ||
error, | ||
skipAlert: true, | ||
}; | ||
}; | ||
|
||
export function muteStatus(id) { | ||
return (dispatch, getState) => { | ||
dispatch(muteStatusRequest(id)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could maybe add examples here in the comments for newbies like me? :) Like: status_url = "https://origin/@user_id/external_id" where user_id is the OP's user id on the origin instance and external_id is the OP's status id? (dunno if I've got this right tho, lol)