Update CIDER local and session storage keys to unbrick downgrade compat

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2020-10-08 09:51:31 +01:00
parent 0d6edab708
commit 017d2d40fe
2 changed files with 15 additions and 21 deletions

View file

@ -41,7 +41,7 @@ export default class SendHistoryManager {
while (itemJSON = sessionStorage.getItem(`${this.prefix}[${index}]`)) { while (itemJSON = sessionStorage.getItem(`${this.prefix}[${index}]`)) {
try { try {
this.history.push(SendHistoryManager.parseItem(JSON.parse(itemJSON))); this.history.push(JSON.parse(itemJSON));
} catch (e) { } catch (e) {
console.warn("Throwing away unserialisable history", e); console.warn("Throwing away unserialisable history", e);
break; break;
@ -60,16 +60,6 @@ export default class SendHistoryManager {
}; };
} }
static parseItem(item: IHistoryItem | SerializedPart[]): IHistoryItem {
if (Array.isArray(item)) {
// XXX: migrate from old format already in Storage
return {
parts: item,
};
}
return item;
}
save(editorModel: EditorModel, replyEvent?: MatrixEvent) { save(editorModel: EditorModel, replyEvent?: MatrixEvent) {
const item = SendHistoryManager.createItem(editorModel, replyEvent); const item = SendHistoryManager.createItem(editorModel, replyEvent);
this.history.push(item); this.history.push(item);

View file

@ -338,11 +338,11 @@ export default class SendMessageComposer extends React.Component {
const parts = this._restoreStoredEditorState(partCreator) || []; const parts = this._restoreStoredEditorState(partCreator) || [];
this.model = new EditorModel(parts, partCreator); this.model = new EditorModel(parts, partCreator);
this.dispatcherRef = dis.register(this.onAction); this.dispatcherRef = dis.register(this.onAction);
this.sendHistoryManager = new SendHistoryManager(this.props.room.roomId, 'mx_cider_composer_history_'); this.sendHistoryManager = new SendHistoryManager(this.props.room.roomId, 'mx_cider_history_');
} }
get _editorStateKey() { get _editorStateKey() {
return `cider_editor_state_${this.props.room.roomId}`; return `mx_cider_state_${this.props.room.roomId}`;
} }
_clearStoredEditorState() { _clearStoredEditorState() {
@ -352,15 +352,19 @@ export default class SendMessageComposer extends React.Component {
_restoreStoredEditorState(partCreator) { _restoreStoredEditorState(partCreator) {
const json = localStorage.getItem(this._editorStateKey); const json = localStorage.getItem(this._editorStateKey);
if (json) { if (json) {
const {parts: serializedParts, replyEventId} = SendHistoryManager.parseItem(JSON.parse(json)); try {
const parts = serializedParts.map(p => partCreator.deserializePart(p)); const {parts: serializedParts, replyEventId} = JSON.parse(json);
if (replyEventId) { const parts = serializedParts.map(p => partCreator.deserializePart(p));
dis.dispatch({ if (replyEventId) {
action: 'reply_to_event', dis.dispatch({
event: this.props.room.findEventById(replyEventId), action: 'reply_to_event',
}); event: this.props.room.findEventById(replyEventId),
});
}
return parts;
} catch (e) {
console.error(e);
} }
return parts;
} }
} }