mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 02:40:53 -06:00
DEV: Make screen-track
a regular service (#14983)
This commit is contained in:
parent
05423e9dfd
commit
9be69b603c
@ -74,7 +74,6 @@
|
||||
//= require ./discourse/app/lib/link-mentions
|
||||
//= require ./discourse/app/components/site-header
|
||||
//= require ./discourse/app/components/d-editor
|
||||
//= require ./discourse/app/lib/screen-track
|
||||
//= require ./discourse/app/routes/discourse
|
||||
//= require ./discourse/app/routes/build-topic-route
|
||||
//= require ./discourse/app/routes/restricted-user
|
||||
|
@ -5,7 +5,6 @@ import PrivateMessageTopicTrackingState from "discourse/models/private-message-t
|
||||
import DiscourseLocation from "discourse/lib/discourse-location";
|
||||
import KeyValueStore from "discourse/lib/key-value-store";
|
||||
import MessageBus from "message-bus-client";
|
||||
import ScreenTrack from "discourse/lib/screen-track";
|
||||
import SearchService from "discourse/services/search";
|
||||
import Session from "discourse/models/session";
|
||||
import Site from "discourse/models/site";
|
||||
@ -69,16 +68,6 @@ export default {
|
||||
const session = Session.current();
|
||||
app.register("session:main", session, { instantiate: false });
|
||||
|
||||
// TODO: Automatically register this service
|
||||
const screenTrack = new ScreenTrack(
|
||||
topicTrackingState,
|
||||
siteSettings,
|
||||
session,
|
||||
currentUser,
|
||||
container.lookup("service:app-events")
|
||||
);
|
||||
app.register("service:screen-track", screenTrack, { instantiate: false });
|
||||
|
||||
app.register("location:discourse-location", DiscourseLocation);
|
||||
|
||||
const keyValueStore = new KeyValueStore("discourse_");
|
||||
@ -87,7 +76,6 @@ export default {
|
||||
|
||||
ALL_TARGETS.forEach((t) => {
|
||||
app.inject(t, "appEvents", "service:app-events");
|
||||
app.inject(t, "topicTrackingState", "topic-tracking-state:main");
|
||||
app.inject(t, "pmTopicTrackingState", "pm-topic-tracking-state:main");
|
||||
app.inject(t, "store", "service:store");
|
||||
app.inject(t, "site", "site:main");
|
||||
@ -99,10 +87,11 @@ export default {
|
||||
app.inject(t, "session", "session:main");
|
||||
app.inject(t, "messageBus", "message-bus:main");
|
||||
app.inject(t, "siteSettings", "site-settings:main");
|
||||
app.inject(t, "topicTrackingState", "topic-tracking-state:main");
|
||||
});
|
||||
|
||||
if (currentUser) {
|
||||
["component", "route", "controller", "service"].forEach((t) => {
|
||||
["controller", "component", "route", "service"].forEach((t) => {
|
||||
app.inject(t, "currentUser", "current-user:main");
|
||||
});
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import Service, { inject as service } from "@ember/service";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { bind } from "discourse-common/utils/decorators";
|
||||
import { isTesting } from "discourse-common/config/environment";
|
||||
@ -10,21 +11,24 @@ const ANON_MAX_TOPIC_IDS = 5;
|
||||
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,
|
||||
appEvents
|
||||
) {
|
||||
this.topicTrackingState = topicTrackingState;
|
||||
this.siteSettings = siteSettings;
|
||||
this.session = session;
|
||||
this.currentUser = currentUser;
|
||||
this.appEvents = appEvents;
|
||||
export default class ScreenTrack extends Service {
|
||||
@service appEvents;
|
||||
|
||||
_consolidatedTimings = [];
|
||||
_lastTick = null;
|
||||
_lastScrolled = null;
|
||||
_lastFlush = 0;
|
||||
_timings = {};
|
||||
_totalTimings = {};
|
||||
_topicTime = 0;
|
||||
_onscreen = [];
|
||||
_readOnscreen = [];
|
||||
_readPosts = {};
|
||||
_inProgress = false;
|
||||
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.reset();
|
||||
this._consolidatedTimings = [];
|
||||
}
|
||||
|
||||
start(topicId, topicController) {
|
@ -17,11 +17,10 @@ function topicWithStream(streamDetails) {
|
||||
|
||||
discourseModule("Unit | Controller | topic", function (hooks) {
|
||||
hooks.beforeEach(function () {
|
||||
this.registry.register("service:screen-track", {}, { instantiate: false });
|
||||
this.registry.injection("controller", "appEvents", "service:app-events");
|
||||
});
|
||||
|
||||
hooks.afterEach(function () {
|
||||
this.registry.unregister("service:screen-track");
|
||||
this.registry.unregister("current-user:main");
|
||||
let topic = this.container.lookup("controller:topic");
|
||||
topic.setProperties({
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { module, test } from "qunit";
|
||||
import ScreenTrack from "discourse/lib/screen-track";
|
||||
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { test } from "qunit";
|
||||
|
||||
module("Unit | Utility | screen-track", function () {
|
||||
discourseModule("Unit | Service | screen-track", function () {
|
||||
test("consolidateTimings", function (assert) {
|
||||
const tracker = new ScreenTrack();
|
||||
const tracker = this.container.lookup("service:screen-track");
|
||||
|
||||
tracker.consolidateTimings({ 1: 10, 2: 5 }, 10, 1);
|
||||
tracker.consolidateTimings({ 1: 5, 3: 1 }, 3, 1);
|
Loading…
Reference in New Issue
Block a user