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

View File

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