apps/notifications/src/panel/rest-client/index.js
function updateLastSeenTime( proposedTime, fromStorage ) {
	let fromNote = false;
	let mostRecentNoteTime = 0;

	// Make sure we aren't getting milliseconds
	// The check time is Aug 8, 2005 in ms
	if ( proposedTime > 1123473600000 ) {
		proposedTime = proposedTime / 1000;
	}

	debug( 'updateLastSeenTime 0', {
		proposedTime: proposedTime,
		fromStorage: fromStorage,
		lastSeenTime: this.lastSeenTime,
	} );

	// Event was triggered by another tab's localStorage.setItem; ignore localStorage and remote.
	if ( fromStorage ) {
		if ( proposedTime <= this.lastSeenTime ) {
			return false;
		}
		this.lastSeenTime = proposedTime;
		return true;
	}

	const notes = getAllNotes( store.getState() );
	if ( notes.length ) {
		mostRecentNoteTime = Date.parse( notes[ 0 ].timestamp ) / 1000;
	}

	debug( 'updateLastSeenTime 1', {
		proposedTime: proposedTime,
		showing: this.showing,
		visible: this.visible,
		lastSeenTime: this.lastSeenTime,
		mostRecentNoteTime: mostRecentNoteTime,
	} );

	// Advance proposedTime to the latest visible note time.
	if ( this.isShowing && this.isVisible && mostRecentNoteTime > proposedTime ) {
		proposedTime = mostRecentNoteTime;
		fromNote = true;
	}

	debug( 'updateLastSeenTime 2', {
		proposedTime: proposedTime,
		fromNote: fromNote,
		oldNews: proposedTime <= this.lastSeenTime,
	} );

	// Ignore old news.
	if ( proposedTime <= this.lastSeenTime ) {
		return false;
	}

	this.lastSeenTime = proposedTime;

	try {
		localStorage.setItem( 'notesLastMarkedSeen', this.lastSeenTime );
	} catch ( e ) {}

	// Update the database only if an unseen note has become visible.
	if ( fromNote ) {
		debug( 'updateLastSeenTime 3', this.lastSeenTime );
		sendLastSeenTime( this.lastSeenTime );
	}

	return true;
}
function updateLastSeenTime( proposedTime, fromStorage ) {
	let fromNote = false;
	let mostRecentNoteTime = 0;

	// Make sure we aren't getting milliseconds
	// The check time is Aug 8, 2005 in ms
	if ( proposedTime > 1123473600000 ) {
		proposedTime = proposedTime / 1000;
	}

	debug( 'updateLastSeenTime 0', {
		proposedTime: proposedTime,
		fromStorage: fromStorage,
		lastSeenTime: this.lastSeenTime,
	} );

	// Event was triggered by another tab's localStorage.setItem; ignore localStorage and remote.
	if ( fromStorage ) {
		if ( proposedTime <= this.lastSeenTime ) {
			return false;
		}
		this.lastSeenTime = proposedTime;
		return true;
	}

	const notes = getAllNotes( store.getState() );
	if ( notes.length ) {
		mostRecentNoteTime = Date.parse( notes[ 0 ].timestamp ) / 1000;
	}

	debug( 'updateLastSeenTime 1', {
		proposedTime: proposedTime,
		showing: this.showing,
		visible: this.visible,
		lastSeenTime: this.lastSeenTime,
		mostRecentNoteTime: mostRecentNoteTime,
	} );

	// Advance proposedTime to the latest visible note time.
	if ( this.isShowing && this.isVisible && mostRecentNoteTime > proposedTime ) {
		proposedTime = mostRecentNoteTime;
		fromNote = true;
	}

	debug( 'updateLastSeenTime 2', {
		proposedTime: proposedTime,
		fromNote: fromNote,
		oldNews: proposedTime <= this.lastSeenTime,
	} );

	// Ignore old news.
	if ( proposedTime <= this.lastSeenTime ) {
		return false;
	}

	this.lastSeenTime = proposedTime;

	try {
		localStorage.setItem( 'notesLastMarkedSeen', this.lastSeenTime );
	} catch ( e ) {}

	// Update the database only if an unseen note has become visible.
	if ( fromNote ) {
		debug( 'updateLastSeenTime 3', this.lastSeenTime );
		sendLastSeenTime( this.lastSeenTime );
	}

	return true;
}
Update lastSeenTime in object instance, localStorage, and remote database.
Advance this.lastSeenTime to proposedTime or the latest visible note time.
If the timestamp comes from a note, update the remote database.

@param {Number} proposedTime A proposed update to our lastSeenTime timestamp
@param {Boolean} fromStorage Whether this call is from handleStorageEvent
@returns {Boolean} whether or not we will update our lastSeenTime value