@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
91 lines (90 loc) • 2.35 kB
JavaScript
import t from "../common/base-provider.js";
import r from "../managers/braze-instance.js";
import Feed from "./feed.js";
import {
newCardFromFeedJson as at,
newCardFromSerializedValue as Z,
} from "../Card/util/card-factory.js";
import { rehydrateDateAfterJsonization as V } from "../util/date-utils.js";
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
import u from "../managers/subscription-manager.js";
export default class re extends t {
constructor(t, s) {
super(),
(this.C = t),
(this.Fi = s),
(this.cards = []),
(this.xi = null),
(this.C = t),
(this.Fi = s),
(this.Ts = new u()),
r.N(this.Ts),
this.Ds();
}
Ds() {
let t = [];
this.C && (t = this.C.ft(s.gt.qi) || []);
const i = [];
for (let s = 0; s < t.length; s++) {
const e = Z(t[s]);
null != e && i.push(e);
}
(this.cards = i), this.C && (this.xi = V(this.C.ft(s.gt.zi)));
}
ki(t) {
const i = [];
let e = null,
r = {};
this.C && (r = this.C.ft(s.gt.Zt) || {});
const h = {};
for (let s = 0; s < t.length; s++) {
e = t[s];
const o = at(e);
if (null != o) {
const t = o.id;
t && r[t] && ((o.viewed = !0), (h[t] = !0)), i.push(o);
}
}
(this.cards = i),
this.Ys(),
(this.xi = new Date()),
this.C && (this.C.Bt(s.gt.Zt, h), this.C.Bt(s.gt.zi, this.xi));
}
Ys() {
var t;
const i = [];
for (let t = 0; t < this.cards.length; t++) i.push(this.cards[t].bt());
null === (t = this.C) || void 0 === t || t.Bt(s.gt.qi, i);
}
U(t) {
null != t &&
t.feed &&
(this.Ds(),
this.ki(t.feed),
this.Ts.X(new Feed(this.cards.slice(), this.xi)));
}
Bi() {
this.Ds();
const t = [],
s = new Date();
for (let i = 0; i < this.cards.length; i++) {
const e = this.cards[i].expiresAt;
let r = !0;
null != e && (r = e >= s), r && t.push(this.cards[i]);
}
return new Feed(t, this.xi);
}
vi() {
this.Fi && this.Fi.requestFeedRefresh();
}
qt(t) {
return this.Ts.Ft(t);
}
clearData(t) {
null == t && (t = !1),
(this.cards = []),
(this.xi = null),
t && this.C && (this.C.Ut(s.gt.qi), this.C.Ut(s.gt.zi)),
this.Ts.X(new Feed(this.cards.slice(), this.xi));
}
}