diff options
Diffstat (limited to 'webapp/stores/file_store.jsx')
-rw-r--r-- | webapp/stores/file_store.jsx | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/webapp/stores/file_store.jsx b/webapp/stores/file_store.jsx index 2692e6959..18a35e1fd 100644 --- a/webapp/stores/file_store.jsx +++ b/webapp/stores/file_store.jsx @@ -16,41 +16,58 @@ class FileStore extends EventEmitter { this.handleEventPayload = this.handleEventPayload.bind(this); this.dispatchToken = AppDispatcher.register(this.handleEventPayload); - this.fileInfo = new Map(); + this.setMaxListeners(600); + + this.fileInfosByPost = new Map(); } addChangeListener(callback) { this.on(CHANGE_EVENT, callback); } + removeChangeListener(callback) { this.removeListener(CHANGE_EVENT, callback); } - emitChange(filename) { - this.emit(CHANGE_EVENT, filename); + + emitChange() { + this.emit(CHANGE_EVENT); + } + + hasInfosForPost(postId) { + return this.fileInfosByPost.has(postId); + } + + getInfosForPost(postId) { + return this.fileInfosByPost.get(postId); + } + + saveInfos(postId, infos) { + this.fileInfosByPost.set(postId, infos); } - hasInfo(filename) { - return this.fileInfo.has(filename); + getFileUrl(fileId) { + return `/api/v3/files/${fileId}/get`; } - getInfo(filename) { - return this.fileInfo.get(filename); + getFileThumbnailUrl(fileId) { + return `/api/v3/files/${fileId}/get_thumbnail`; } - setInfo(filename, info) { - this.fileInfo.set(filename, info); + getFilePreviewUrl(fileId) { + return `/api/v3/files/${fileId}/get_preview`; } handleEventPayload(payload) { const action = payload.action; switch (action.type) { - case ActionTypes.RECEIVED_FILE_INFO: - this.setInfo(action.filename, action.info); - this.emitChange(action.filename); + case ActionTypes.RECEIVED_FILE_INFOS: + // This assumes that all received file infos are for a single post + this.saveInfos(action.postId, action.infos); + this.emitChange(action.postId); break; } } } -export default new FileStore(); +export default new FileStore();
\ No newline at end of file |