Reset MessageReceiver processed count after reporting it

This commit is contained in:
Scott Nonnenberg 2022-05-25 11:15:09 -07:00 committed by GitHub
parent bf6d9c6cda
commit 68f705e6ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 10 deletions

View file

@ -486,10 +486,10 @@ type BoundsType = {
}; };
function isVisible(window: BoundsType, bounds: BoundsType) { function isVisible(window: BoundsType, bounds: BoundsType) {
const boundsX = get(bounds, 'x') || 0; const boundsX = bounds?.x || 0;
const boundsY = get(bounds, 'y') || 0; const boundsY = bounds?.y || 0;
const boundsWidth = get(bounds, 'width') || DEFAULT_WIDTH; const boundsWidth = bounds?.width || DEFAULT_WIDTH;
const boundsHeight = get(bounds, 'height') || DEFAULT_HEIGHT; const boundsHeight = bounds?.height || DEFAULT_HEIGHT;
// requiring BOUNDS_BUFFER pixels on the left or right side // requiring BOUNDS_BUFFER pixels on the left or right side
const rightSideClearOfLeftBound = const rightSideClearOfLeftBound =

View file

@ -44,13 +44,16 @@ export function start(): void {
// This class is entirely designed to keep the app title, badge and tray icon updated. // This class is entirely designed to keep the app title, badge and tray icon updated.
// In the future it could listen to redux changes and do its updates there. // In the future it could listen to redux changes and do its updates there.
const inboxCollection = new (window.Backbone.Collection.extend({ const inboxCollection = new (window.Backbone.Collection.extend({
hasQueueEmptied: false,
initialize() { initialize() {
this.listenTo(conversations, 'add change:active_at', this.addActive); this.listenTo(conversations, 'add change:active_at', this.addActive);
this.listenTo(conversations, 'reset', () => this.reset([])); this.listenTo(conversations, 'reset', () => this.reset([]));
const debouncedUpdateUnreadCount = debounce( const debouncedUpdateUnreadCount = debounce(
this.updateUnreadCount.bind(this), this.updateUnreadCount.bind(this),
1000 1000,
{ leading: true, maxWait: 1000, trailing: true }
); );
this.on( this.on(
@ -65,6 +68,10 @@ export function start(): void {
model.startMuteTimer(); model.startMuteTimer();
}); });
}, },
onEmpty() {
this.hasQueueEmptied = true;
this.updateUnreadCount();
},
addActive(model: ConversationModel) { addActive(model: ConversationModel) {
if (model.get('active_at')) { if (model.get('active_at')) {
this.add(model); this.add(model);
@ -73,6 +80,10 @@ export function start(): void {
} }
}, },
updateUnreadCount() { updateUnreadCount() {
if (!this.hasQueueEmptied) {
return;
}
const canCountMutedConversations = const canCountMutedConversations =
window.storage.get('badge-count-muted-conversations') || false; window.storage.get('badge-count-muted-conversations') || false;

View file

@ -2287,6 +2287,7 @@ export async function startApp(): Promise<void> {
]); ]);
log.info('onEmpty: All outstanding database requests complete'); log.info('onEmpty: All outstanding database requests complete');
window.readyForUpdates(); window.readyForUpdates();
window.getInboxCollection().onEmpty();
// Start listeners here, after we get through our queue. // Start listeners here, after we get through our queue.
RotateSignedPreKeyListener.init(window.Whisper.events, newVersion); RotateSignedPreKeyListener.init(window.Whisper.events, newVersion);
@ -2305,11 +2306,12 @@ export async function startApp(): Promise<void> {
window.reduxActions.app.initialLoadComplete(); window.reduxActions.app.initialLoadComplete();
const processedCount = messageReceiver?.getAndResetProcessedCount() || 0;
window.logAppLoadedEvent?.({ window.logAppLoadedEvent?.({
processedCount: messageReceiver && messageReceiver.getProcessedCount(), processedCount,
}); });
if (messageReceiver) { if (messageReceiver) {
log.info('App loaded - messages:', messageReceiver.getProcessedCount()); log.info('App loaded - messages:', processedCount);
} }
window.Signal.Util.setBatchingStrategy(false); window.Signal.Util.setBatchingStrategy(false);

View file

@ -251,8 +251,10 @@ export default class MessageReceiver
}); });
} }
public getProcessedCount(): number { public getAndResetProcessedCount(): number {
return this.processedCount; const count = this.processedCount;
this.processedCount = 0;
return count;
} }
public handleRequest(request: IncomingWebSocketRequest): void { public handleRequest(request: IncomingWebSocketRequest): void {

4
ts/window.d.ts vendored
View file

@ -195,7 +195,9 @@ declare global {
getEnvironment: typeof getEnvironment; getEnvironment: typeof getEnvironment;
getExpiration: () => string; getExpiration: () => string;
getHostName: () => string; getHostName: () => string;
getInboxCollection: () => ConversationModelCollectionType; getInboxCollection: () => ConversationModelCollectionType & {
onEmpty: () => void;
};
getInteractionMode: () => 'mouse' | 'keyboard'; getInteractionMode: () => 'mouse' | 'keyboard';
getLocale: () => ElectronLocaleType; getLocale: () => ElectronLocaleType;
getMediaCameraPermissions: () => Promise<boolean>; getMediaCameraPermissions: () => Promise<boolean>;