Skip to content

Instantly share code, notes, and snippets.

@zone559
Created August 24, 2025 06:24
Show Gist options
  • Select an option

  • Save zone559/b840c4f81cd2fad4e080319902933de6 to your computer and use it in GitHub Desktop.

Select an option

Save zone559/b840c4f81cd2fad4e080319902933de6 to your computer and use it in GitHub Desktop.
"use strict";
(self.__LOADABLE_LOADED_CHUNKS__ = self.__LOADABLE_LOADED_CHUNKS__ || []).push([[3739], {
13739: (t, e, s) => {
s.d(e, {
Q1: () => v,
TX: () => d,
ko: () => l,
tJ: () => c,
zu: () => u
});
var i = s(49360)
, r = s(60540)
, n = s(78285)
, o = s(56525)
, a = function(t, e, s, i) {
return new (s || (s = Promise))(function(r, n) {
function o(t) {
try {
u(i.next(t))
} catch (t) {
n(t)
}
}
function a(t) {
try {
u(i.throw(t))
} catch (t) {
n(t)
}
}
function u(t) {
var e;
t.done ? r(t.value) : (e = t.value,
e instanceof s ? e : new s(function(t) {
t(e)
}
)).then(o, a)
}
u((i = i.apply(t, e || [])).next())
}
)
};
function u(t) {
return a(this, void 0, void 0, function*() {
return n.h.get("/api/story/user_list/", {
query: Object.assign(Object.assign({}, t), {
aid: i.xE,
count: 10
}),
baseUrlType: r.Z4.FixedWww
})
})
}
function c(t) {
return a(this, void 0, void 0, function*() {
return n.h.get("/api/story/item_list/", {
query: Object.assign(Object.assign({}, t), {
aid: i.xE,
count: o.tn
}),
baseUrlType: r.Z4.FixedWww
})
})
}
function d(t) {
return a(this, void 0, void 0, function*() {
return n.h.get("/api/story/batch/item_list/", {
query: Object.assign(Object.assign({}, t), {
aid: i.xE
}),
baseUrlType: r.Z4.FixedWww
})
})
}
function l(t) {
return a(this, void 0, void 0, function*() {
return n.h.get("/api/story/viewer_list/", {
query: Object.assign(Object.assign({}, t), {
aid: i.xE,
count: 10
}),
baseUrlType: r.Z4.FixedWww
})
})
}
function v(t) {
return a(this, void 0, void 0, function*() {
return n.h.post("/tiktok/story/view/report/v1", {
query: Object.assign({}, t),
headers: {
[r.nk]: n.h.csrfToken
},
baseUrlType: r.Z4.FixedWww
})
})
}
}
,
56525: (t, e, s) => {
s.d(e, {
Le: () => j,
cG: () => O,
cp: () => I,
of: () => h,
tn: () => y,
zq: () => S
});
var i = s(3144)
, r = s(99242)
, n = s(54251)
, o = s(7378)
, a = s(3128)
, u = s(71183)
, c = s(18836)
, d = s(9005)
, l = s(55488)
, v = s(13739)
, g = s(99254);
const y = 4
, b = (0,
n.p)("tiktokStoriesStateAtom@tiktok/webapp-atoms", {
userIndex: -1,
storyIndex: -1,
isOpen: !1,
activeSkylightItemIndex: -1
})
, p = (0,
n.p)("tiktokStoriesAtom@tiktok/webapp-atoms", t => {
const e = t(b)
, s = t(g.yj);
return Object.assign(Object.assign({}, e), s)
}
, (t, e, s) => {
console.warn("Tried to set tiktokStoriesAtom with:", s)
}
)
, {useAtomService: O, useServiceState: I, useServiceDispatchers: S, getStaticApi: h} = (0,
i.i)(p, (t, e) => ({
setHasSideNavAvatar(t) {
e(b, e => Object.assign(Object.assign({}, e), {
hasSideNavAvatar: t
}))
},
getHasSideNavAvatar: () => t(b).hasSideNavAvatar,
setActiveSkylightItemIndex(t) {
e(b, e => Object.assign(Object.assign({}, e), {
activeSkylightItemIndex: t
}))
},
updateActive() {
var s, i, r;
const {singleStoryId: n, singleUser: o, users: a, userItemListMap: u} = t(g.yj)
, {userIndex: c, storyIndex: d} = t(b)
, l = null != o ? o : a[c]
, v = null != n ? n : null == (r = u[l]) || null == (i = r.itemList) || null == (s = i[d]) ? void 0 : s.id;
e(b, t => Object.assign(Object.assign({}, t), {
activeUser: l,
activeStoryId: v
}))
},
syncStateToPlayerAtom() {
const {activeStoryId: e="", storyIndex: s} = t(b)
, i = e
, r = {
currentVideo: {
index: s,
id: i,
mode: u.ey.TiktokStories
},
playProgress: 0,
pageType: o.g.Unknown
};
(0,
c.LM)().updateVideo(r),
(0,
l.Q3)().setVideoInfo({
itemId: i,
currentTime: 0
})
},
updateUserIndex(s) {
var i, r, n, o;
const {users: a, userItemListMap: u} = t(g.yj)
, {activeUser: c} = t(b)
, d = null !== (n = null == (o = u[null !== (r = null !== (i = a[s]) && void 0 !== i ? i : c) && void 0 !== r ? r : ""]) ? void 0 : o.CurrentPosition) && void 0 !== n ? n : 0;
e(b, t => Object.assign(Object.assign({}, t), {
userIndex: s,
storyIndex: d >= 0 ? d : 0,
isOpen: !0
})),
this.updateActive(),
this.syncStateToPlayerAtom()
},
updateStoriesIndex(s) {
var i, r, n, o, a;
return r = this,
n = void 0,
a = function*() {
const {activeUser: r="", userIndex: n, storyIndex: o, isLoadingStories: a} = t(b)
, u = Math.sign(s - o)
, {singleUser: c, users: d, userItemListMap: l} = t(g.yj)
, v = l[r];
if (s >= v.TotalCount || s < 0) {
var p;
const t = d[n + u];
if (c || !t)
return;
const s = null !== (i = null == (p = l[t]) ? void 0 : p.CurrentPosition) && void 0 !== i ? i : 0;
return e(b, t => Object.assign(Object.assign({}, t), {
userIndex: n + u,
storyIndex: s
})),
this.updateActive(),
void this.syncStateToPlayerAtom()
}
s in v.itemList || a || (e(b, t => Object.assign(Object.assign({}, t), {
isLoadingStories: !0
})),
yield(0,
g.Vq)().getStoriesForUser(r, s, s < o).finally( () => {
e(b, t => Object.assign(Object.assign({}, t), {
isLoadingStories: !1
}))
}
));
const O = Array.from({
length: y
}).map( (t, e) => o + u * (e + 1)).find(t => !(t in v.itemList));
O && !a && (e(b, t => Object.assign(Object.assign({}, t), {
isLoadingStories: !0
})),
(0,
g.Vq)().getStoriesForUser(r, O, s < o).finally( () => {
e(b, t => Object.assign(Object.assign({}, t), {
isLoadingStories: !1
}))
}
)),
e(b, t => Object.assign(Object.assign({}, t), {
storyIndex: s
})),
this.updateActive(),
this.syncStateToPlayerAtom()
}
,
new ((o = void 0) || (o = Promise))(function(t, e) {
function s(t) {
try {
u(a.next(t))
} catch (t) {
e(t)
}
}
function i(t) {
try {
u(a.throw(t))
} catch (t) {
e(t)
}
}
function u(e) {
var r;
e.done ? t(e.value) : (r = e.value,
r instanceof o ? r : new o(function(t) {
t(r)
}
)).then(s, i)
}
u((a = a.apply(r, n || [])).next())
}
)
},
openStoriesPlayer(s={
userIndex: 0
}) {
const {singleStoryId: i, userItemListMap: r} = t(g.yj)
, n = "storyId"in s ? s.storyId : void 0
, o = () => {
var e, s, i;
const r = t(b)
, n = null == (i = t(d.Pu)[null !== (e = r.activeStoryId) && void 0 !== e ? e : ""]) || null == (s = i.story) ? void 0 : s.Viewed;
a.f.sendEvent("enter_story", {
author_id: r.activeUser,
group_id: r.activeStoryId,
is_story_watched: null == n ? void 0 : n.toString()
})
}
;
if (n || i) {
if (n) {
var u;
const s = null == (u = t(d.Pu)[n]) ? void 0 : u.author;
e(g.yj, t => Object.assign(Object.assign({}, t), {
singleUser: s,
singleStoryId: n
})),
this.updateActive()
}
return e(b, t => Object.assign(Object.assign({}, t), {
isOpen: !0
})),
void o()
}
const c = "singleUser"in s ? s.singleUser : void 0;
if (c) {
const t = r[c];
if (!t)
return;
return e(g.yj, t => Object.assign(Object.assign({}, t), {
singleUser: c
})),
e(b, e => {
var s;
return Object.assign(Object.assign({}, e), {
isOpen: !0,
storyIndex: null !== (s = t.CurrentPosition) && void 0 !== s ? s : 0
})
}
),
this.updateActive(),
void o()
}
const l = "userIndex"in s ? s.userIndex : void 0;
void 0 !== l && (this.updateActive(),
this.updateUserIndex(l),
o())
},
closeStoriesPlayer(s="navigate") {
const i = t(b);
i.isOpen && a.f.sendEvent("exit_story", {
author_id: i.activeUser,
group_id: i.activeStoryId,
enter_method: s
}),
e(b, t => Object.assign(Object.assign({}, t), {
activeUser: void 0,
activeStoryId: void 0,
userIndex: -1,
storyIndex: -1,
isOpen: !1
})),
this.syncStateToPlayerAtom()
},
resetSingleUser() {
e(g.yj, t => {
var {singleUser: e} = t;
return function(t, e) {
var s = {};
for (var i in t)
Object.prototype.hasOwnProperty.call(t, i) && e.indexOf(i) < 0 && (s[i] = t[i]);
if (null != t && "function" == typeof Object.getOwnPropertySymbols) {
var r = 0;
for (i = Object.getOwnPropertySymbols(t); r < i.length; r++)
e.indexOf(i[r]) < 0 && Object.prototype.propertyIsEnumerable.call(t, i[r]) && (s[i[r]] = t[i[r]])
}
return s
}(t, ["singleUser"])
}
)
},
updateStoryViewStatus(s, i, r) {
(0,
v.Q1)({
story_id: s
}).catch(t => {}
);
const {singleUser: n} = t(g.yj);
if (i < 0 || !n && r < 0)
return;
const {users: o, userItemListMap: a} = t(g.yj)
, u = null != n ? n : o[r]
, c = a[u];
if (i >= c.CurrentPosition) {
const t = c;
t.CurrentPosition = i,
i >= c.TotalCount - 1 && (t.CurrentPosition = 0,
t.AllViewed = !0),
e(g.yj, e => Object.assign(Object.assign({}, e), {
userItemListMap: Object.assign(Object.assign({}, e.userItemListMap), {
[u]: t
})
}))
}
}
}))
, j = () => {
const {userIndex: t, storyIndex: e, activeUser: s, activeStoryId: i, singleUser: n, singleStoryId: o} = I(t => ({
userIndex: t.userIndex,
storyIndex: t.storyIndex,
activeUser: t.activeUser,
activeStoryId: t.activeStoryId,
singleUser: t.singleUser,
singleStoryId: t.singleStoryId
}), r.bN)
, a = (0,
d.F3)(t => t[null != i ? i : ""], r.bN);
if ((n || t >= 0) && (o || e >= 0) && s && i)
return a
}
}
,
99254: (t, e, s) => {
s.d(e, {
QG: () => b,
Vq: () => p,
yj: () => y
});
var i = s(18499)
, r = s(3144)
, n = s(54251)
, o = s(81733)
, a = s(57524)
, u = s(819)
, c = s(10547)
, d = s(24967)
, l = s(9005)
, v = s(13739)
, g = function(t, e, s, i) {
return new (s || (s = Promise))(function(r, n) {
function o(t) {
try {
u(i.next(t))
} catch (t) {
n(t)
}
}
function a(t) {
try {
u(i.throw(t))
} catch (t) {
n(t)
}
}
function u(t) {
var e;
t.done ? r(t.value) : (e = t.value,
e instanceof s ? e : new s(function(t) {
t(e)
}
)).then(o, a)
}
u((i = i.apply(t, e || [])).next())
}
)
};
const y = (0,
n.p)("tiktokStoriesItemListAtom@tiktok/webapp-atoms", {
users: [],
totalCountUsers: 0,
userItemListMap: {},
storyViewerMap: {}
})
, {useServiceDispatchers: b, getStaticApi: p} = (0,
r.i)(y, (t, e) => ({
getUsersWithStories(s, r=!1) {
var n;
return g(this, void 0, void 0, function*() {
const {users: l} = t(y)
, g = (0,
c.PJ)(t(c.WH));
try {
var b;
const {user: t} = (0,
a.x)()
, c = yield(0,
v.zu)({
storyFeedScene: s,
isNonPersonalized: g,
cursor: (r ? 0 : l.length).toString()
});
if (c.statusCode !== u.s.Ok)
throw new Error("Not Ok");
const p = null !== (n = null == (b = c.storyUsers) ? void 0 : b.reduce( (e, {user: s}) => s.uniqueId === (null == t ? void 0 : t.uniqueId) ? [s, ...e] : [...e, s], [])) && void 0 !== n ? n : []
, O = p.filter(t => t.UserStoryStatus !== o.ZW.STORY_STATUS_DEFAULT).map(t => t.uniqueId)
, I = r ? O : Array.from(new Set([...l, ...O]));
(0,
i.unstable_batchedUpdates)( () => {
var t, s;
(0,
d.Gp)().multiSetUser(p),
(0,
d.Gp)().multiSetUserStats(null !== (t = null == (s = c.storyUsers) ? void 0 : s.map( ({user: t, stats: e, statsV2: s}) => ({
uniqueId: t.uniqueId,
stats: e,
statsV2: s
}))) && void 0 !== t ? t : []),
e(y, t => {
var e;
return Object.assign(Object.assign({}, t), {
users: I,
totalCountUsers: Number.parseInt(null !== (e = c.totalCount) && void 0 !== e ? e : "0"),
hasMoreUsers: c.hasMore
})
}
)
}
)
} catch (t) {
console.warn("STORIES", {
e: t
})
}
})
},
getStoriesForUser(s, r=0, n=!1) {
var o, a;
return g(this, void 0, void 0, function*() {
var c, g, b;
const {userItemListMap: p} = t(y);
if (r < 0 || (null == (c = p[s]) ? void 0 : c.TotalCount) && r >= p[s].TotalCount)
return;
const O = null !== (o = n ? null == (g = p[s]) ? void 0 : g.MinCursor : null == (b = p[s]) ? void 0 : b.MaxCursor) && void 0 !== o ? o : 0;
try {
var I;
const r = null == (I = t(d.p9).users[s]) ? void 0 : I.id;
if (!r)
throw new Error("No valid user for Stories item list!");
const o = yield(0,
v.tJ)({
authorId: r,
cursor: O.toString(),
loadBackward: n
});
if (o.statusCode !== u.s.Ok)
throw new Error("Not Ok");
const c = p
, g = c[s];
c[s] = Object.assign(Object.assign({}, g), {
TotalCount: Number.parseInt(o.TotalCount),
CurrentPosition: Number.parseInt(o.CurrentPosition) % Number.parseInt(o.TotalCount),
AllViewed: o.AllViewed,
MinCursor: Number.parseInt(o.MinCursor),
MaxCursor: Number.parseInt(o.MaxCursor),
HasMoreBefore: o.HasMoreBefore,
HasMoreAfter: o.HasMoreAfter,
itemList: Object.assign(Object.assign({}, null == g ? void 0 : g.itemList), (null !== (a = o.itemList) && void 0 !== a ? a : []).reduce( (t, e, s) => Object.assign(Object.assign({}, t), {
[Number.parseInt(o.CurrentPosition) + s]: Object.assign(Object.assign({}, e.story), {
id: e.id
})
}), {}))
}),
(0,
i.unstable_batchedUpdates)( () => {
var t;
(0,
l.ud)().multiSetItem(null !== (t = o.itemList) && void 0 !== t ? t : []),
e(y, t => Object.assign(Object.assign({}, t), {
userItemListMap: c
}))
}
)
} catch (t) {
console.warn("STORIES", {
e: t
})
}
})
},
getBatchStoriesForUsers() {
var s;
return g(this, void 0, void 0, function*() {
const {users: r} = t(y)
, n = {};
try {
const a = t(d.p9).users
, c = r.flatMap(t => {
var e;
const s = null == (e = a[t]) ? void 0 : e.id;
return s ? (n[s] = t,
s) : []
}
);
if (!c.length)
throw new Error("No valid users for Stories batch item list!");
const g = yield(0,
v.TX)({
authorIds: c.join(","),
storyCallScene: o.gY.STORY_CALL_SCENE_FEED
});
if (g.statusCode !== u.s.Ok)
throw new Error("Not Ok");
const b = []
, p = (null !== (s = g.batchStoryItemLists) && void 0 !== s ? s : []).reduce( (t, e) => {
var s, i, r;
const o = null !== (s = e.itemList) && void 0 !== s ? s : []
, a = +e.AuthorId ? e.AuthorId : null !== (i = null == (r = o[0].author) ? void 0 : r.uniqueId) && void 0 !== i ? i : ""
, u = n[a];
if (!u)
return t;
const c = o.reduce( (t, s, i) => Object.assign(Object.assign({}, t), {
[Number.parseInt(e.CurrentPosition) + i]: Object.assign(Object.assign({}, s.story), {
id: s.id
})
}), {});
return b.push(...o),
Object.assign(Object.assign({}, t), {
[u]: Object.assign(Object.assign({}, e), {
TotalCount: Number.parseInt(e.TotalCount),
CurrentPosition: Number.parseInt(e.CurrentPosition) % Number.parseInt(e.TotalCount),
MinCursor: Number.parseInt(e.MinCursor),
MaxCursor: Number.parseInt(e.MaxCursor),
itemList: c
})
})
}
, {});
(0,
i.unstable_batchedUpdates)( () => {
(0,
l.ud)().multiSetItem(b),
e(y, t => Object.assign(Object.assign({}, t), {
userItemListMap: p
}))
}
)
} catch (t) {
console.warn("STORIES", {
e: t
})
}
})
},
getViewersForStory(s) {
var r, n, o, a, c;
return g(this, void 0, void 0, function*() {
const {storyViewerMap: l} = t(y)
, g = (s in l ? l[s].viewerListCursor : 0).toString();
try {
const t = yield(0,
v.ko)({
storyId: s,
cursor: g
});
if (t.statusCode !== u.s.Ok)
throw new Error("Not Ok");
const b = (null !== (r = t.storyViewerList) && void 0 !== r ? r : []).map( ({user: t}) => t)
, p = l
, O = p[s]
, I = (null !== (n = null == O ? void 0 : O.viewers) && void 0 !== n ? n : []).concat(null !== (o = t.storyViewerList) && void 0 !== o ? o : []).reduce( (t, e) => (t[e.user.user.id] = e,
t), {});
p[s] = Object.assign(Object.assign({}, O), {
viewerListCursor: t.cursor ? Number.parseInt(t.cursor) : (null !== (a = null == O ? void 0 : O.viewerListCursor) && void 0 !== a ? a : 0) + b.length,
viewCount: t.totalViewers ? Number.parseInt(t.totalViewers) : (null !== (c = null == O ? void 0 : O.viewCount) && void 0 !== c ? c : 0) + b.length,
viewers: Object.values(I),
hasMore: t.hasMore
}),
(0,
i.unstable_batchedUpdates)( () => {
(0,
d.Gp)().multiSetUser(b.map(t => t.user)),
(0,
d.Gp)().multiSetUserStats(b.map( ({user: t, stats: e, statsV2: s}) => ({
uniqueId: t.uniqueId,
stats: e,
statsV2: s
}))),
e(y, t => Object.assign(Object.assign({}, t), {
storyViewerMap: p
}))
}
)
} catch (t) {
console.warn("STORIES", {
e: t
})
}
})
}
}))
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment