DEV: Add app event "topic:timings-sent" (#12737)

This commit is contained in:
Gerhard Schlager 2021-04-16 18:34:49 +02:00 committed by GitHub
parent 74e84a1953
commit c60ccfed98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -11,11 +11,18 @@ const AJAX_FAILURE_DELAYS = [5000, 10000, 20000, 40000];
const ALLOWED_AJAX_FAILURES = [405, 429, 500, 501, 502, 503, 504]; const ALLOWED_AJAX_FAILURES = [405, 429, 500, 501, 502, 503, 504];
export default class { export default class {
constructor(topicTrackingState, siteSettings, session, currentUser) { constructor(
topicTrackingState,
siteSettings,
session,
currentUser,
appEvents
) {
this.topicTrackingState = topicTrackingState; this.topicTrackingState = topicTrackingState;
this.siteSettings = siteSettings; this.siteSettings = siteSettings;
this.session = session; this.session = session;
this.currentUser = currentUser; this.currentUser = currentUser;
this.appEvents = appEvents;
this.reset(); this.reset();
this._consolidatedTimings = []; this._consolidatedTimings = [];
} }
@ -139,15 +146,16 @@ export default class {
this._ajaxFailures = this._ajaxFailures || 0; this._ajaxFailures = this._ajaxFailures || 0;
const { timings, topicTime, topicId } = this._consolidatedTimings.pop(); const { timings, topicTime, topicId } = this._consolidatedTimings.pop();
const data = {
timings: timings,
topic_time: topicTime,
topic_id: topicId,
};
this._inProgress = true; this._inProgress = true;
ajax("/topics/timings", { ajax("/topics/timings", {
data: { data,
timings: timings,
topic_time: topicTime,
topic_id: topicId,
},
cache: false, cache: false,
type: "POST", type: "POST",
headers: { headers: {
@ -162,6 +170,7 @@ export default class {
const postNumbers = Object.keys(timings).map((v) => parseInt(v, 10)); const postNumbers = Object.keys(timings).map((v) => parseInt(v, 10));
topicController.readPosts(topicId, postNumbers); topicController.readPosts(topicId, postNumbers);
} }
this.appEvents.trigger("topic:timings-sent", data);
}) })
.catch((e) => { .catch((e) => {
if (ALLOWED_AJAX_FAILURES.indexOf(e.jqXHR.status) > -1) { if (ALLOWED_AJAX_FAILURES.indexOf(e.jqXHR.status) > -1) {

View File

@ -74,7 +74,8 @@ export default {
topicTrackingState, topicTrackingState,
siteSettings, siteSettings,
session, session,
currentUser currentUser,
app.appEvents
); );
app.register("service:screen-track", screenTrack, { instantiate: false }); app.register("service:screen-track", screenTrack, { instantiate: false });