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) {
const boundsX = get(bounds, 'x') || 0;
const boundsY = get(bounds, 'y') || 0;
const boundsWidth = get(bounds, 'width') || DEFAULT_WIDTH;
const boundsHeight = get(bounds, 'height') || DEFAULT_HEIGHT;
const boundsX = bounds?.x || 0;
const boundsY = bounds?.y || 0;
const boundsWidth = bounds?.width || DEFAULT_WIDTH;
const boundsHeight = bounds?.height || DEFAULT_HEIGHT;
// requiring BOUNDS_BUFFER pixels on the left or right side
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.
// In the future it could listen to redux changes and do its updates there.
const inboxCollection = new (window.Backbone.Collection.extend({
hasQueueEmptied: false,
initialize() {
this.listenTo(conversations, 'add change:active_at', this.addActive);
this.listenTo(conversations, 'reset', () => this.reset([]));
const debouncedUpdateUnreadCount = debounce(
this.updateUnreadCount.bind(this),
1000
1000,
{ leading: true, maxWait: 1000, trailing: true }
);
this.on(
@ -65,6 +68,10 @@ export function start(): void {
model.startMuteTimer();
});
},
onEmpty() {
this.hasQueueEmptied = true;
this.updateUnreadCount();
},
addActive(model: ConversationModel) {
if (model.get('active_at')) {
this.add(model);
@ -73,6 +80,10 @@ export function start(): void {
}
},
updateUnreadCount() {
if (!this.hasQueueEmptied) {
return;
}
const canCountMutedConversations =
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');
window.readyForUpdates();
window.getInboxCollection().onEmpty();
// Start listeners here, after we get through our queue.
RotateSignedPreKeyListener.init(window.Whisper.events, newVersion);
@ -2305,11 +2306,12 @@ export async function startApp(): Promise<void> {
window.reduxActions.app.initialLoadComplete();
const processedCount = messageReceiver?.getAndResetProcessedCount() || 0;
window.logAppLoadedEvent?.({
processedCount: messageReceiver && messageReceiver.getProcessedCount(),
processedCount,
});
if (messageReceiver) {
log.info('App loaded - messages:', messageReceiver.getProcessedCount());
log.info('App loaded - messages:', processedCount);
}
window.Signal.Util.setBatchingStrategy(false);

View file

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

4
ts/window.d.ts vendored
View file

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