Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 017d2d4

Browse files
committed
Update CIDER local and session storage keys to unbrick downgrade compat
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 0d6edab commit 017d2d4

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

src/SendHistoryManager.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class SendHistoryManager {
4141

4242
while (itemJSON = sessionStorage.getItem(`${this.prefix}[${index}]`)) {
4343
try {
44-
this.history.push(SendHistoryManager.parseItem(JSON.parse(itemJSON)));
44+
this.history.push(JSON.parse(itemJSON));
4545
} catch (e) {
4646
console.warn("Throwing away unserialisable history", e);
4747
break;
@@ -60,16 +60,6 @@ export default class SendHistoryManager {
6060
};
6161
}
6262

63-
static parseItem(item: IHistoryItem | SerializedPart[]): IHistoryItem {
64-
if (Array.isArray(item)) {
65-
// XXX: migrate from old format already in Storage
66-
return {
67-
parts: item,
68-
};
69-
}
70-
return item;
71-
}
72-
7363
save(editorModel: EditorModel, replyEvent?: MatrixEvent) {
7464
const item = SendHistoryManager.createItem(editorModel, replyEvent);
7565
this.history.push(item);

src/components/views/rooms/SendMessageComposer.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,11 @@ export default class SendMessageComposer extends React.Component {
338338
const parts = this._restoreStoredEditorState(partCreator) || [];
339339
this.model = new EditorModel(parts, partCreator);
340340
this.dispatcherRef = dis.register(this.onAction);
341-
this.sendHistoryManager = new SendHistoryManager(this.props.room.roomId, 'mx_cider_composer_history_');
341+
this.sendHistoryManager = new SendHistoryManager(this.props.room.roomId, 'mx_cider_history_');
342342
}
343343

344344
get _editorStateKey() {
345-
return `cider_editor_state_${this.props.room.roomId}`;
345+
return `mx_cider_state_${this.props.room.roomId}`;
346346
}
347347

348348
_clearStoredEditorState() {
@@ -352,15 +352,19 @@ export default class SendMessageComposer extends React.Component {
352352
_restoreStoredEditorState(partCreator) {
353353
const json = localStorage.getItem(this._editorStateKey);
354354
if (json) {
355-
const {parts: serializedParts, replyEventId} = SendHistoryManager.parseItem(JSON.parse(json));
356-
const parts = serializedParts.map(p => partCreator.deserializePart(p));
357-
if (replyEventId) {
358-
dis.dispatch({
359-
action: 'reply_to_event',
360-
event: this.props.room.findEventById(replyEventId),
361-
});
355+
try {
356+
const {parts: serializedParts, replyEventId} = JSON.parse(json);
357+
const parts = serializedParts.map(p => partCreator.deserializePart(p));
358+
if (replyEventId) {
359+
dis.dispatch({
360+
action: 'reply_to_event',
361+
event: this.props.room.findEventById(replyEventId),
362+
});
363+
}
364+
return parts;
365+
} catch (e) {
366+
console.error(e);
362367
}
363-
return parts;
364368
}
365369
}
366370

0 commit comments

Comments
 (0)