Refresh stories in redux when data changes
This commit is contained in:
parent
b82234b119
commit
e14c3241c5
5 changed files with 71 additions and 13 deletions
|
@ -4,6 +4,7 @@
|
||||||
import PQueue from 'p-queue';
|
import PQueue from 'p-queue';
|
||||||
import { isNumber, omit } from 'lodash';
|
import { isNumber, omit } from 'lodash';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import { EventEmitter } from 'events';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Direction,
|
Direction,
|
||||||
|
@ -195,12 +196,6 @@ export function freezeSignedPreKey(
|
||||||
return keyPair;
|
return keyPair;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We add a this parameter to avoid an 'implicit any' error on the next line
|
|
||||||
const EventsMixin = function EventsMixin(this: unknown) {
|
|
||||||
Object.assign(this, window.Backbone.Events);
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
} as any as typeof window.Backbone.EventsMixin;
|
|
||||||
|
|
||||||
type SessionCacheEntry = CacheEntryType<SessionType, SessionRecord>;
|
type SessionCacheEntry = CacheEntryType<SessionType, SessionRecord>;
|
||||||
type SenderKeyCacheEntry = CacheEntryType<SenderKeyType, SenderKeyRecord>;
|
type SenderKeyCacheEntry = CacheEntryType<SenderKeyType, SenderKeyRecord>;
|
||||||
|
|
||||||
|
@ -209,7 +204,7 @@ type ZoneQueueEntryType = Readonly<{
|
||||||
callback(): void;
|
callback(): void;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export class SignalProtocolStore extends EventsMixin {
|
export class SignalProtocolStore extends EventEmitter {
|
||||||
// Enums used across the app
|
// Enums used across the app
|
||||||
|
|
||||||
VerifiedStatus = VerifiedStatus;
|
VerifiedStatus = VerifiedStatus;
|
||||||
|
@ -388,7 +383,7 @@ export class SignalProtocolStore extends EventsMixin {
|
||||||
const id: PreKeyIdType = `${ourUuid.toString()}:${keyId}`;
|
const id: PreKeyIdType = `${ourUuid.toString()}:${keyId}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.trigger('removePreKey', ourUuid);
|
this.emit('removePreKey', ourUuid);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(
|
log.error(
|
||||||
'removePreKey error triggering removePreKey:',
|
'removePreKey error triggering removePreKey:',
|
||||||
|
@ -1669,7 +1664,7 @@ export class SignalProtocolStore extends EventsMixin {
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.trigger('keychange', encodedAddress.uuid);
|
this.emit('keychange', encodedAddress.uuid);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(
|
log.error(
|
||||||
'saveIdentity: error triggering keychange:',
|
'saveIdentity: error triggering keychange:',
|
||||||
|
@ -1839,7 +1834,7 @@ export class SignalProtocolStore extends EventsMixin {
|
||||||
|
|
||||||
if (identityRecord) {
|
if (identityRecord) {
|
||||||
try {
|
try {
|
||||||
this.trigger('keychange', uuid);
|
this.emit('keychange', uuid);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(
|
log.error(
|
||||||
'processVerifiedMessage error triggering keychange:',
|
'processVerifiedMessage error triggering keychange:',
|
||||||
|
@ -2071,6 +2066,8 @@ export class SignalProtocolStore extends EventsMixin {
|
||||||
|
|
||||||
window.ConversationController.reset();
|
window.ConversationController.reset();
|
||||||
await window.ConversationController.load();
|
await window.ConversationController.load();
|
||||||
|
|
||||||
|
this.emit('removeAllData');
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeAllConfiguration(mode: RemoveAllConfiguration): Promise<void> {
|
async removeAllConfiguration(mode: RemoveAllConfiguration): Promise<void> {
|
||||||
|
@ -2156,6 +2153,43 @@ export class SignalProtocolStore extends EventsMixin {
|
||||||
|
|
||||||
return Array.from(union.values());
|
return Array.from(union.values());
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// EventEmitter types
|
||||||
|
//
|
||||||
|
|
||||||
|
public override on(
|
||||||
|
name: 'removePreKey',
|
||||||
|
handler: (ourUuid: UUID) => unknown
|
||||||
|
): this;
|
||||||
|
|
||||||
|
public override on(
|
||||||
|
name: 'keychange',
|
||||||
|
handler: (theirUuid: UUID) => unknown
|
||||||
|
): this;
|
||||||
|
|
||||||
|
public override on(name: 'removeAllData', handler: () => unknown): this;
|
||||||
|
|
||||||
|
public override on(
|
||||||
|
eventName: string | symbol,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
listener: (...args: Array<any>) => void
|
||||||
|
): this {
|
||||||
|
return super.on(eventName, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override emit(name: 'removePreKey', ourUuid: UUID): boolean;
|
||||||
|
|
||||||
|
public override emit(name: 'keychange', theirUuid: UUID): boolean;
|
||||||
|
|
||||||
|
public override emit(name: 'removeAllData'): boolean;
|
||||||
|
|
||||||
|
public override emit(
|
||||||
|
eventName: string | symbol,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
...args: Array<any>
|
||||||
|
): boolean {
|
||||||
|
return super.emit(eventName, ...args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.SignalProtocolStore = SignalProtocolStore;
|
window.SignalProtocolStore = SignalProtocolStore;
|
||||||
|
|
|
@ -540,6 +540,10 @@ export async function startApp(): Promise<void> {
|
||||||
window.getAccountManager().refreshPreKeys(uuidKind);
|
window.getAccountManager().refreshPreKeys(uuidKind);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.textsecure.storage.protocol.on('removeAllData', () => {
|
||||||
|
window.reduxActions.stories.removeAllStories();
|
||||||
|
});
|
||||||
|
|
||||||
window.getSocketStatus = () => {
|
window.getSocketStatus = () => {
|
||||||
if (server === undefined) {
|
if (server === undefined) {
|
||||||
return SocketStatus.CLOSED;
|
return SocketStatus.CLOSED;
|
||||||
|
@ -1179,6 +1183,8 @@ export async function startApp(): Promise<void> {
|
||||||
|
|
||||||
changedConvoBatcher.add(conversation);
|
changedConvoBatcher.add(conversation);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Called by SignalProtocolStore#removeAllData()
|
||||||
convoCollection.on('reset', removeAllConversations);
|
convoCollection.on('reset', removeAllConversations);
|
||||||
|
|
||||||
window.Whisper.events.on('userChanged', (reconnect = false) => {
|
window.Whisper.events.on('userChanged', (reconnect = false) => {
|
||||||
|
|
|
@ -4795,6 +4795,7 @@ async function removeAll(): Promise<void> {
|
||||||
DELETE FROM storyDistributions;
|
DELETE FROM storyDistributions;
|
||||||
DELETE FROM storyReads;
|
DELETE FROM storyReads;
|
||||||
DELETE FROM unprocessed;
|
DELETE FROM unprocessed;
|
||||||
|
DELETE FROM uninstalled_sticker_packs;
|
||||||
`);
|
`);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,7 @@ const SEND_STORY_MODAL_OPEN_STATE_CHANGED =
|
||||||
const STORY_CHANGED = 'stories/STORY_CHANGED';
|
const STORY_CHANGED = 'stories/STORY_CHANGED';
|
||||||
const TOGGLE_VIEW = 'stories/TOGGLE_VIEW';
|
const TOGGLE_VIEW = 'stories/TOGGLE_VIEW';
|
||||||
const VIEW_STORY = 'stories/VIEW_STORY';
|
const VIEW_STORY = 'stories/VIEW_STORY';
|
||||||
|
const REMOVE_ALL_STORIES = 'stories/REMOVE_ALL_STORIES';
|
||||||
|
|
||||||
type DOEStoryActionType = {
|
type DOEStoryActionType = {
|
||||||
type: typeof DOE_STORY;
|
type: typeof DOE_STORY;
|
||||||
|
@ -185,6 +186,10 @@ type ViewStoryActionType = {
|
||||||
payload: SelectedStoryDataType | undefined;
|
payload: SelectedStoryDataType | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type RemoveAllStoriesActionType = {
|
||||||
|
type: typeof REMOVE_ALL_STORIES;
|
||||||
|
};
|
||||||
|
|
||||||
export type StoriesActionType =
|
export type StoriesActionType =
|
||||||
| DOEStoryActionType
|
| DOEStoryActionType
|
||||||
| ListMembersVerified
|
| ListMembersVerified
|
||||||
|
@ -199,7 +204,8 @@ export type StoriesActionType =
|
||||||
| SendStoryModalOpenStateChanged
|
| SendStoryModalOpenStateChanged
|
||||||
| StoryChangedActionType
|
| StoryChangedActionType
|
||||||
| ToggleViewActionType
|
| ToggleViewActionType
|
||||||
| ViewStoryActionType;
|
| ViewStoryActionType
|
||||||
|
| RemoveAllStoriesActionType;
|
||||||
|
|
||||||
// Action Creators
|
// Action Creators
|
||||||
|
|
||||||
|
@ -746,6 +752,12 @@ const viewUserStories: ViewUserStoriesActionCreatorType = ({
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function removeAllStories(): RemoveAllStoriesActionType {
|
||||||
|
return {
|
||||||
|
type: REMOVE_ALL_STORIES,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
type ViewStoryOptionsType =
|
type ViewStoryOptionsType =
|
||||||
| {
|
| {
|
||||||
closeViewer: true;
|
closeViewer: true;
|
||||||
|
@ -1129,6 +1141,7 @@ export const actions = {
|
||||||
markStoryRead,
|
markStoryRead,
|
||||||
queueStoryDownload,
|
queueStoryDownload,
|
||||||
reactToStory,
|
reactToStory,
|
||||||
|
removeAllStories,
|
||||||
replyToStory,
|
replyToStory,
|
||||||
sendStoryMessage,
|
sendStoryMessage,
|
||||||
sendStoryModalOpenStateChanged,
|
sendStoryModalOpenStateChanged,
|
||||||
|
@ -1424,6 +1437,10 @@ export function reducer(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (action.type === REMOVE_ALL_STORIES) {
|
||||||
|
return getEmptyState();
|
||||||
|
}
|
||||||
|
|
||||||
if (action.type === QUEUE_STORY_DOWNLOAD) {
|
if (action.type === QUEUE_STORY_DOWNLOAD) {
|
||||||
const storyIndex = state.stories.findIndex(
|
const storyIndex = state.stories.findIndex(
|
||||||
story => story.messageId === action.payload
|
story => story.messageId === action.payload
|
||||||
|
|
|
@ -686,12 +686,12 @@ describe('SignalProtocolStore', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
keychangeTriggered = 0;
|
keychangeTriggered = 0;
|
||||||
store.bind('keychange', () => {
|
store.on('keychange', () => {
|
||||||
keychangeTriggered += 1;
|
keychangeTriggered += 1;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
store.unbind('keychange');
|
store.removeAllListeners('keychange');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when the new verified status is DEFAULT', () => {
|
describe('when the new verified status is DEFAULT', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue