mono/reference/tiktok/files/60248.341443e1_deobfuscated.js
2026-01-29 18:35:51 +01:00

1581 lines
70 KiB
JavaScript

/**
* TikTok Comment System - Deobfuscated JavaScript Bundle
* Original file: 60248.341443e1.js
*
* This bundle contains modules for:
* - Comment state management and caching
* - Comment reply threading system
* - Comment like/unlike functionality
* - Comment preloading and ML integration
* - User data processing for comments
* - Search and analytics integration
*/
"use strict";
// Initialize loadable chunks array
(self.__LOADABLE_LOADED_CHUNKS__ = self.__LOADABLE_LOADED_CHUNKS__ || []).push([["60248"], {
/**
* Module 61937: Comment Item Management
* Individual comment item state management
*/
61937: function(exports, module, require) {
require.d(exports, {
I9: function() { return commentItemAtom; },
Tq: function() { return useCommentItemState; },
tR: function() { return useCommentItemActions; }
});
var objectUtils = require(35383);
var assignUtils = require(5377);
var mergeUtils = require(45996);
var omitUtils = require(16327);
var keyUtils = require(11201);
var atomUtils = require(73455);
var serviceUtils = require(4676);
var jotaiUtils = require(10625);
/**
* Comment item atom - stores individual comment data
*/
var commentItemAtom = atomUtils._(jotaiUtils.p("commentItemAtom@tiktok/webapp-atoms", {}), {
rehydrationKey: "webapp.comment.items"
});
/**
* Comment item service - manages comment operations
*/
var commentItemService = serviceUtils.i(commentItemAtom, function(getState, setState) {
return {
/**
* Set individual comment item data
*/
setItem: function(commentData) {
setState(commentItemAtom, function(currentState) {
return mergeUtils._(assignUtils._(assignUtils._({}, currentState),
objectUtils._(objectUtils._({}, commentData.cid, commentData)));
});
},
/**
* Update comment like/digg state
*/
setItemDiggState: function(diggData) {
var currentState = getState(commentItemAtom);
if (currentState[diggData.cid]) {
setState(commentItemAtom, function(state) {
var existingComment = state[diggData.cid];
return mergeUtils._(assignUtils._(assignUtils._({}, state),
objectUtils._(objectUtils._({}, diggData.cid,
mergeUtils._(assignUtils._(assignUtils._({}, existingComment), {
user_digged: diggData.digged,
is_author_digged: diggData.is_author_digged !== undefined ?
diggData.is_author_digged : existingComment.is_author_digged
})))));
});
}
},
/**
* Update comment like count
*/
setItemDiggCount: function(countData) {
var currentState = getState(commentItemAtom);
if (currentState[countData.cid]) {
setState(commentItemAtom, function(state) {
return mergeUtils._(assignUtils._(assignUtils._({}, state),
objectUtils._(objectUtils._({}, countData.cid,
mergeUtils._(assignUtils._(assignUtils._({}, state[countData.cid]), {
digg_count: countData.count
})))));
});
}
},
/**
* Remove comment item from state
*/
removeItem: function(commentId) {
setState(commentItemAtom, function(state) {
var newState = assignUtils._(assignUtils._({}, state));
delete newState[commentId];
return omitUtils._(newState, [commentId].map(keyUtils._));
});
},
/**
* Set multiple comment items at once
*/
multiSetCommentItem: function(commentArray) {
setState(commentItemAtom, function(state) {
var newState = assignUtils._(assignUtils._({}, state));
commentArray.forEach(function(comment) {
newState[comment.cid] = assignUtils._(assignUtils._({}, newState[comment.cid], comment));
});
return newState;
});
},
/**
* Remove multiple comment items
*/
multiRemoveCommentItem: function(commentIds) {
setState(commentItemAtom, function(state) {
var newState = assignUtils._(assignUtils._({}, state));
commentIds.forEach(function(commentId) {
delete newState[commentId];
});
return newState;
});
},
/**
* Increase or decrease reply comment count
*/
reduceOrIncreaseCommentCount: function(countData) {
var commentId = countData.cid;
var isReduce = countData.isReduce;
var currentState = getState(commentItemAtom);
if (currentState[commentId]) {
var currentComment = currentState[commentId];
var currentCount = Number(currentComment.reply_comment_total || 0);
setState(commentItemAtom, function(state) {
return mergeUtils._(assignUtils._(assignUtils._({}, state),
objectUtils._(objectUtils._({}, commentId,
mergeUtils._(assignUtils._(assignUtils._({}, state[commentId]), {
reply_comment_total: isReduce ? currentCount - 1 : currentCount + 1
})))));
});
}
}
};
});
var useCommentItemState = commentItemService.useServiceState;
var useCommentItemActions = commentItemService.useServiceDispatchers;
},
/**
* Module 31847: Main Comment System
* Core comment management, fetching, and interaction handling
*/
31847: function(exports, module, require) {
require.d(exports, {
lN: function() { return defaultCommentState; },
BY: function() { return useCommentService; },
_B: function() { return useCommentState; },
kH: function() { return useCommentDispatchers; },
OL: function() { return getCommentStaticApi; }
});
var asyncUtils = require(79066);
var objectUtils = require(35383);
var assignUtils = require(5377);
var mergeUtils = require(45996);
var arrayUtils = require(6586);
var spreadUtils = require(54333);
var generatorUtils = require(72516);
var deepMergeUtils = require(54122);
var uniqueByUtils = require(61945);
var batchUpdatesUtils = require(18499);
var atomUtils = require(73455);
var serviceUtils = require(4676);
var jotaiUtils = require(10625);
var topicUtils = require(64781);
var commentStatusUtils = require(8686);
var contextUtils = require(35144);
var teaAnalytics = require(77226);
var toastUtils = require(35702);
var statusUtils = require(13495);
var statusCodes = require(57007);
var containerUtils = require(55453);
var translationUtils = require(77214);
var personalizationUtils = require(83751);
var userUtils = require(35379);
var i18nUtils = require(7871);
var itemUtils = require(72702);
var commentItemUtils = require(61937);
var userDataUtils = require(91781);
var urlUtils = require(26869);
var ssrUtils = require(75434);
var fetchUtils = require(91402);
var httpClient = require(42646);
var baseUrlTypes = require(56904);
/**
* Comment API service with CSR/SSR support
*/
var commentApiService = fetchUtils.M({
// Client-side rendering
csr: function(params) {
return asyncUtils._(function() {
return generatorUtils.__generator(this, function(step) {
return [2, httpClient.h.get("/api/comment/list/", {
query: mergeUtils._(assignUtils._(assignUtils._({}, params), {
count: 20,
aid: 1988,
app_language: "ja-JP",
device_platform: "web_pc",
current_region: "JP",
fromWeb: 1,
enter_from: "tiktok_web"
}),
baseUrlType: baseUrlTypes.Z4.FixedWww
})];
});
})();
},
// Server-side rendering
ssr: function(params) {
return asyncUtils._(function() {
var ssrClient, apiUrl, response;
return generatorUtils.__generator(this, function(step) {
switch (step.label) {
case 0:
ssrClient = ssrUtils.yK();
apiUrl = urlUtils.stringifyUrl({
url: "consul://tiktok.comment.api/api/comment/list/",
query: mergeUtils._(assignUtils._(assignUtils._({}, params), {
aid: 1988,
count: 20,
device_platform: "web_pc",
fromWeb: 1
})
});
step.label = 1;
case 1:
step.trys.push([1, 3, , 4]);
return [4, ssrClient.fetch(apiUrl, {
method: "GET",
timeout: 5000,
headers: mergeUtils._(assignUtils._(assignUtils._({}, ssrClient.headers), {
referer: ssrClient.href
})
})];
case 2:
response = step.sent();
return [2, response.json()];
case 3:
var error = step.sent();
ssrClient.logger.error("ssr fetch catch err: " + error);
return [2, {
status_code: statusCodes.s.UnknownError,
reply_style: 1,
has_more: 1,
cursor: "0"
}];
case 4:
return [2];
}
});
})();
}
});
/**
* Default comment state structure
*/
var defaultCommentState = {
awemeId: undefined,
cursor: "0",
comments: [],
hasMore: true,
loading: false,
isFirstLoad: false,
fetchType: "load_by_current",
currentAspect: "all"
};
/**
* Main comment atom for video-level comment state
*/
var commentAtom = atomUtils._(jotaiUtils.p("commentAtom@tiktok/webapp-atoms", {}), {
rehydrationKey: "webapp.comment"
});
/**
* Comment service - handles all comment operations
*/
var commentService = serviceUtils.i(commentAtom, function(getState, setState) {
return {
/**
* Switch comment aspect/filter (all, topic-specific, etc.)
*/
switchAspect: function(aspectParams) {
return asyncUtils._(function() {
var itemId, aspect, currentState, currentAspect;
return generatorUtils.__generator(this, function(step) {
switch (step.label) {
case 0:
itemId = aspectParams.itemId;
aspect = aspectParams.aspect;
currentState = getState(commentAtom)[itemId];
// Skip if already loading or same aspect
if ((currentState && currentState.loading) ||
(currentState && currentState.currentAspect === aspect)) {
return [2];
}
// Update state with new aspect
setState(commentAtom, function(state) {
return mergeUtils._(assignUtils._(assignUtils._({}, state),
assignUtils._(assignUtils._({}, itemId,
deepMergeUtils.A(mergeUtils._(assignUtils._(assignUtils._({}, defaultCommentState), {
currentAspect: aspect
})))));
});
// Fetch comments for new aspect
return [4, this.fetchComment({
aweme_id: itemId,
cursor: 0,
fetch_type: "load_by_current",
commentAspect: aspect
})];
case 1:
step.sent();
return [2];
}
});
}).apply(this, arguments);
},
/**
* Set comment item data for a specific video
*/
setCommentItem: function(params) {
var itemId = params.itemId !== undefined ? params.itemId : "";
var itemData = params.item;
if (itemData) {
setState(commentAtom, function(state) {
var existingData = state[itemId] || defaultCommentState;
return mergeUtils._(assignUtils._(assignUtils._({}, state),
assignUtils._(assignUtils._({}, itemId,
assignUtils._(assignUtils._({}, existingData, itemData)))));
});
}
},
/**
* Set reply loading state for a comment
*/
setReplyLoading: function(loadingParams) {
var commentData = getCommentAndIndex(getState, loadingParams);
var comment = commentData[0];
var commentIndex = commentData[1];
if (comment) {
// Update reply cache with loading state
var existingReplyCache = comment.replyCache || {
comments: comment.reply_comment || [],
cursor: (comment.reply_comment && comment.reply_comment.length) || "0",
hasMore: true
};
comment.replyCache = mergeUtils._(assignUtils._(assignUtils._({}, existingReplyCache), {
loading: loadingParams.loading
}));
updateCommentInList(setState, loadingParams.itemId, commentIndex, assignUtils._(assignUtils._({}, comment)));
}
},
/**
* Set reply comments for a parent comment
*/
setReplyComment: function(replyParams) {
var commentData = getCommentAndIndex(getState, replyParams);
var comment = commentData[0];
var commentIndex = commentData[1];
if (comment) {
updateCommentInList(setState, replyParams.itemId, commentIndex,
mergeUtils._(assignUtils._(assignUtils._({}, comment), {
reply_comment: replyParams.comments
}));
}
},
/**
* Set reply comment cache data
*/
setReplyCommentCache: function(cacheParams) {
var commentData = getCommentAndIndex(getState, cacheParams);
var comment = commentData[0];
var commentIndex = commentData[1];
if (comment) {
comment.replyCache = {
comments: cacheParams.comments,
cursor: cacheParams.cursor,
hasMore: cacheParams.hasMore,
loading: comment.replyCache && comment.replyCache.loading || false
};
updateCommentInList(setState, cacheParams.itemId, commentIndex, assignUtils._(assignUtils._({}, comment)));
}
},
/**
* Delete comment from list (handles both main comments and replies)
*/
deleteCommentFromList: function(deleteParams) {
var commentIndex = deleteParams.index;
var replyIndex = deleteParams.subIndex;
var itemId = deleteParams.itemId;
if (replyIndex === undefined) {
// Delete main comment
updateCommentInList(setState, itemId, commentIndex);
} else {
// Delete reply comment
var currentState = getState(commentAtom)[itemId];
if (!currentState) return;
var parentComment = assignUtils._(assignUtils._({}, currentState.comments[commentIndex]));
// Remove from reply_comment array
if (parentComment.reply_comment) {
parentComment.reply_comment.splice(replyIndex, 1);
}
// Remove from replyCache
if (parentComment.replyCache) {
parentComment.replyCache.comments.splice(replyIndex, 1);
}
updateCommentInList(setState, itemId, commentIndex, parentComment);
}
},
/**
* Add new comment to the beginning of the list
*/
addCommentToFirst: function(newComment) {
setState(commentAtom, function(state) {
var existingVideoComments = state[newComment.aweme_id];
var currentComments = existingVideoComments && existingVideoComments.comments || [];
return mergeUtils._(assignUtils._(assignUtils._({}, state),
assignUtils._(assignUtils._({}, newComment.aweme_id,
mergeUtils._(assignUtils._(assignUtils._({}, defaultCommentState, existingVideoComments), {
comments: [{
cid: newComment.cid,
reply_comment: [],
replyCache: null
}].concat(spreadUtils._(currentComments))
}))));
});
},
/**
* Add new reply to the beginning of a comment's reply list
*/
addReplyToFirst: function(replyParams) {
var newReply = replyParams.comment;
var parentCommentPosition = replyParams.position;
var currentState = getState(commentAtom);
var videoComments = currentState[newReply.aweme_id];
if (videoComments) {
var parentComment = videoComments.comments[parentCommentPosition];
if (parentComment) {
var updatedComment = assignUtils._(assignUtils._({}, parentComment));
// Add to reply_comment array
updatedComment.reply_comment = [{
cid: newReply.cid,
reply_comment: null,
replyCache: null
}].concat(spreadUtils._(parentComment.reply_comment || []));
// Add to replyCache
var existingCache = updatedComment.replyCache || {
cursor: "0",
hasMore: true,
loading: false
};
updatedComment.replyCache = mergeUtils._(assignUtils._(assignUtils._({}, existingCache), {
comments: [{
cid: newReply.cid,
reply_comment: null,
replyCache: null
}].concat(spreadUtils._(existingCache.comments || []))
});
updateCommentInList(setState, newReply.aweme_id, parentCommentPosition, updatedComment);
}
}
},
/**
* Handle successful comment post
*/
handlePostSuccess: function(newComment) {
var self = this;
var processedData = processCommentData([newComment]);
var users = processedData.users;
var commentItems = processedData.commentItems;
batchUpdatesUtils.unstable_batchedUpdates(function() {
self.addCommentToFirst(newComment);
userUtils.Gp().multiSetUser(users);
commentItemUtils.tR().multiSetCommentItem(commentItems);
itemUtils.ud().reduceOrIncreaseCommentCount({
id: newComment.aweme_id,
isReduce: false
});
});
},
/**
* Handle successful reply post
*/
handleReplySuccess: function(replyParams) {
var self = this;
var newReply = replyParams.comment;
var position = replyParams.position;
var processedData = processCommentData([newReply], { ignoreReply: true });
var users = processedData.users;
var commentItems = processedData.commentItems;
var commentActions = commentItemUtils.tR();
batchUpdatesUtils.unstable_batchedUpdates(function() {
self.addReplyToFirst({
comment: newReply,
position: position
});
userUtils.Gp().multiSetUser(users);
commentActions.multiSetCommentItem(commentItems);
commentActions.reduceOrIncreaseCommentCount({
cid: newReply.reply_id
});
itemUtils.ud().reduceOrIncreaseCommentCount({
id: newReply.aweme_id,
isReduce: false
});
});
},
/**
* Fetch comments for a video
* Core comment loading functionality
*/
fetchComment: function(fetchParams, translationParams) {
return asyncUtils._(function() {
var self, currentState, awemeId, insertIds, fetchType,
commentState, subTopicId, subCategory, isNonPersonalized,
cursor, apiResponse, processedData, users, comments,
commentItems, existingComments, mergedComments;
return generatorUtils.__generator(this, function(step) {
switch (step.label) {
case 0:
self = this;
currentState = getState(commentAtom);
awemeId = fetchParams.aweme_id;
insertIds = fetchParams.insert_ids;
fetchType = fetchParams.fetch_type !== undefined ?
fetchParams.fetch_type : "load_by_current";
commentState = currentState[fetchParams.aweme_id] || {
awemeId: undefined,
cursor: "0",
comments: [],
hasMore: true,
loading: true,
currentAspect: "all"
};
// Parse comment aspect for topic filtering
var aspectData = parseCommentAspect(fetchParams.commentAspect || commentState.currentAspect);
subTopicId = aspectData.subTopicId;
subCategory = aspectData.subCategory;
isNonPersonalized = personalizationUtils.PJ(getState(personalizationUtils.WH));
// Skip if no more comments to load
if (!commentState.hasMore) {
return [2];
}
cursor = commentState.cursor;
// Set loading state
this.setCommentItem({
item: { awemeId: awemeId, loading: true },
itemId: awemeId
});
step.label = 1;
case 1:
step.trys.push([1, 10, , 11]);
// Choose API endpoint based on topic filtering
if (subTopicId || subCategory) {
return [4, topicUtils.iB({
itemID: awemeId,
subTopicId: subTopicId,
subCategory: subCategory,
cursor: cursor
})];
} else {
return [3, 3];
}
case 2:
apiResponse = step.sent();
return [3, 5];
case 3:
return [4, commentApiService({
insert_ids: cursor === "0" ? insertIds : undefined,
aweme_id: awemeId,
cursor: cursor,
is_non_personalized: isNonPersonalized
})];
case 4:
apiResponse = step.sent();
step.label = 5;
case 5:
statusUtils.G(apiResponse.status_code, [statusCodes.s.Ok]);
// Process successful response
if (apiResponse.status_code === statusCodes.s.Ok &&
apiResponse.comments && apiResponse.comments.length) {
processedData = processCommentData(apiResponse.comments, {
logId: apiResponse.log_pb && apiResponse.log_pb.impr_id
});
users = processedData.users;
comments = processedData.comments;
commentItems = processedData.commentItems;
// Handle translation if needed
if (translationParams) {
var translateTo = translationParams.translateTo;
var count = translationParams.count;
var commentsToTranslate = commentItems
.filter(function(comment) {
return comment.comment_language !== "un" &&
comment.comment_language !== translateTo;
})
.slice(0, count);
if (commentsToTranslate.length) {
return [4, translationUtils.mx().fetchCommentTranslation(
commentsToTranslate, translateTo, true)];
}
}
return [3, 7];
case 6:
step.sent();
step.label = 7;
case 7:
// Merge with existing comments
existingComments = commentState.comments;
mergedComments = uniqueByUtils.A(existingComments.concat(comments), "cid");
// Batch update all related state
batchUpdatesUtils.unstable_batchedUpdates(function() {
userUtils.Gp().multiSetUser(users);
commentItemUtils.tR().multiSetCommentItem(commentItems);
self.setCommentItem({
item: {
comments: mergedComments,
hasMore: !!apiResponse.has_more,
cursor: apiResponse.cursor,
loading: false,
isFirstLoad: Number(cursor) === 0,
fetchType: fetchType
},
itemId: awemeId
});
// Update total comment count if provided
if (apiResponse.total) {
itemUtils.ud().setCommentCount({
id: awemeId,
commentCount: Number(apiResponse.total)
});
}
});
return [3, 9];
}
case 8:
// Handle empty response or error
if (apiResponse.status_code !== statusCodes.s.Ok ||
!apiResponse.comments || !apiResponse.comments.length ||
!apiResponse.has_more) {
this.setCommentItem({
item: {
hasMore: !!apiResponse.has_more,
loading: false
},
itemId: awemeId
});
}
step.label = 9;
case 9:
return [3, 11];
case 10:
step.sent();
this.setCommentItem({
item: { loading: false },
itemId: awemeId
});
return [3, 11];
case 11:
return [2];
}
});
}).call(this);
},
/**
* Fetch reply comments for a parent comment
*/
fetchCommentReply: function(replyParams) {
return asyncUtils._(function() {
var self, commentData, comment, parentComment, apiResponse,
processedData, users, replyComments, commentItems,
existingReplies, mergedReplies;
return generatorUtils.__generator(this, function(step) {
switch (step.label) {
case 0:
self = this;
commentData = getCommentAndIndex(getState, replyParams);
comment = commentData[0];
parentComment = commentData[1];
if (!parentComment) {
console.warn("No item here in fetch comment reply");
return [2];
}
// Set reply loading state
this.setReplyLoading(mergeUtils._(assignUtils._(assignUtils._({}, comment), {
loading: true
}));
step.label = 1;
case 1:
step.trys.push([1, 3, , 4]);
// Fetch reply comments
return [4, fetchReplyComments({
comment_id: comment.cid,
item_id: comment.itemId,
cursor: parentComment.replyCache && parentComment.replyCache.cursor || "0"
})];
case 2:
apiResponse = step.sent();
statusUtils.G(apiResponse.status_code, [statusCodes.s.Ok]);
if (apiResponse.status_code === statusCodes.s.Ok) {
processedData = processCommentData(apiResponse.comments, {
logId: apiResponse.log_pb && apiResponse.log_pb.impr_id
});
users = processedData.users;
replyComments = processedData.comments;
commentItems = processedData.commentItems;
existingReplies = parentComment.reply_comment || [];
mergedReplies = uniqueByUtils.A(existingReplies.concat(replyComments), "cid");
// Batch update reply data
batchUpdatesUtils.unstable_batchedUpdates(function() {
userUtils.Gp().multiSetUser(users);
commentItemUtils.tR().multiSetCommentItem(commentItems);
self.setReplyComment(assignUtils._(assignUtils._({
comments: spreadUtils._(mergedReplies)
}, comment)));
self.setReplyCommentCache(assignUtils._(assignUtils._({
comments: spreadUtils._(mergedReplies),
hasMore: !!apiResponse.has_more,
cursor: apiResponse.cursor
}, comment)));
self.setReplyLoading(mergeUtils._(assignUtils._(assignUtils._({}, comment), {
loading: false
}));
});
}
return [3, 4];
case 3:
step.sent();
this.setReplyLoading(mergeUtils._(assignUtils._(assignUtils._({}, comment), {
loading: false
}));
return [3, 4];
case 4:
return [2];
}
});
}).call(this);
},
/**
* Handle comment like/unlike action
*/
handleCommentLike: function(likeParams) {
return asyncUtils._(function() {
var commentItemState, userState, commentItem, currentUserId,
authorId, userData, diggType, apiResponse, translator,
newDiggState, newDiggCount, isAuthorDigged, commentActions;
return generatorUtils.__generator(this, function(step) {
switch (step.label) {
case 0:
commentItemState = getState(commentItemUtils.I9);
userState = getState(userUtils.p9);
commentItem = commentItemState[likeParams.cid];
currentUserId = contextUtils.x().user && contextUtils.x().user.uid;
authorId = getState(itemUtils.Pu)[likeParams.itemId] &&
getState(itemUtils.Pu)[likeParams.itemId].authorId;
userData = userState.users[commentItem && commentItem.user || ""];
if (!commentItem) {
console.warn("No comment item here in handle comment like");
return [2];
}
diggType = commentItem.user_digged ? 2 : 1; // 1 = like, 2 = unlike
step.label = 1;
case 1:
step.trys.push([1, 3, , 4]);
// Send like/unlike request
return [4, sendCommentDiggRequest({
aweme_id: likeParams.itemId,
cid: likeParams.cid,
digg_type: diggType
})];
case 2:
apiResponse = step.sent();
translator = i18nUtils.T();
// Handle different response scenarios
if (apiResponse && apiResponse.status_code === statusCodes.s.Ok) {
// Success - send analytics
teaAnalytics.f.sendEvent(diggType === 1 ? "like_comment" : "cancel_like_comment", {
comment_id: likeParams.cid,
group_id: likeParams.itemId,
comment_user_id: userData && userData.id || "",
author_id: likeParams.teaAuthorId,
enter_method: likeParams.enterMethod
});
} else if (apiResponse && apiResponse.status_code === statusCodes.s.CommentLikePermissionDisable) {
// Permission disabled
toastUtils.F.destroy();
toastUtils.F.open({
content: translator(diggType === 2 ? "comment_turnoff_unlike" : "comment_turnoff_like"),
duration: 3,
getContainer: containerUtils.M,
getContainerPosition: "fixed"
});
} else if (apiResponse && apiResponse.status_code) {
// Server error
toastUtils.F.destroy();
toastUtils.F.open({
content: translator("Sorry, something wrong with the server, please try again."),
duration: 3,
widthType: "half",
getContainer: containerUtils.M,
getContainerPosition: "fixed"
});
} else {
// Network error
toastUtils.F.destroy();
toastUtils.F.open({
content: translator("comment_nointernet_toast"),
duration: 3,
widthType: "half",
getContainer: containerUtils.M,
getContainerPosition: "fixed"
});
}
// Update local state if successful
if (apiResponse.status_code === statusCodes.s.Ok) {
if (diggType === 1) {
// Like
newDiggState = 1;
newDiggCount = commentItem.digg_count + 1;
if (currentUserId === authorId) {
isAuthorDigged = true;
}
} else {
// Unlike
newDiggState = 0;
newDiggCount = Math.max(commentItem.digg_count - 1, 0);
if (currentUserId === authorId) {
isAuthorDigged = false;
}
}
commentActions = commentItemUtils.tR();
batchUpdatesUtils.unstable_batchedUpdates(function() {
commentActions.setItemDiggState({
cid: likeParams.cid,
digged: newDiggState,
is_author_digged: isAuthorDigged
});
commentActions.setItemDiggCount({
cid: likeParams.cid,
count: newDiggCount
});
});
} else if (apiResponse.status_code === statusCodes.s.CommentLikePermissionDisable) {
// Update item comment status
itemUtils.ud().updateItem({
id: likeParams.itemId,
itemCommentStatus: commentStatusUtils.v.OFF
});
}
return [3, 4];
case 3:
step.sent();
return [3, 4];
case 4:
return [2];
}
});
}).call(this);
},
/**
* Handle comment preloading for upcoming videos
* ML-driven comment preloading system
*/
handleCommentsPreload: function(preloadData) {
var self = this;
var awemeId = preloadData.aweme_id;
var fetchType = preloadData.fetch_type;
var hasMore = preloadData.has_more;
var cursor = preloadData.cursor;
var total = preloadData.total;
var processedData = processCommentData(preloadData.comments);
var users = processedData.users;
var comments = processedData.comments;
var commentItems = processedData.commentItems;
batchUpdatesUtils.unstable_batchedUpdates(function() {
// Update user data
userUtils.Gp().multiSetUser(users);
// Update comment items
commentItemUtils.tR().multiSetCommentItem(commentItems);
// Update comment state
self.setCommentItem({
item: {
comments: comments,
hasMore: !!hasMore,
cursor: cursor,
loading: false,
isFirstLoad: true,
fetchType: fetchType
},
itemId: awemeId
});
// Update total comment count
if (total) {
itemUtils.ud().setCommentCount({
id: awemeId,
commentCount: Number(total)
});
}
});
}
};
});
/**
* Parse comment aspect for filtering
*/
function parseCommentAspect(aspect) {
if (typeof aspect === "string" && aspect.startsWith("topic_")) {
return { subTopicId: aspect.split("_")[1] };
} else if (typeof aspect === "number") {
return { subCategory: aspect };
}
return {};
}
/**
* Get comment and its index from state
*/
function getCommentAndIndex(getState, params) {
var itemId = params.itemId;
var commentId = params.cid;
var videoComments = getState(commentAtom)[itemId];
if (!videoComments) {
return [undefined, -1];
}
var comments = videoComments.comments;
var commentIndex = comments.findIndex(function(comment) {
return comment.cid === commentId;
});
return commentIndex !== -1 ? [comments[commentIndex], commentIndex] : [undefined, -1];
}
/**
* Update comment in the comment list
*/
function updateCommentInList(setState, itemId, commentIndex, updatedComment) {
if (commentIndex === -1) return;
setState(commentAtom, function(state) {
var videoComments = state[itemId];
var existingComments = videoComments && videoComments.comments || [];
var newComments;
if (updatedComment) {
// Update existing comment
newComments = spreadUtils._(existingComments.slice(0, commentIndex))
.concat([deepMergeUtils.A(assignUtils._(assignUtils._({}, existingComments[commentIndex], updatedComment)))])
.concat(spreadUtils._(existingComments.slice(commentIndex + 1)));
} else {
// Remove comment
newComments = spreadUtils._(existingComments.slice(0, commentIndex))
.concat(spreadUtils._(existingComments.slice(commentIndex + 1)));
}
return mergeUtils._(assignUtils._(assignUtils._({}, state),
assignUtils._(assignUtils._({}, itemId,
mergeUtils._(assignUtils._(assignUtils._({}, defaultCommentState, state[itemId]), {
comments: newComments
})))));
});
}
/**
* Process raw comment data into structured format
*/
function processCommentData(rawComments, options) {
rawComments = rawComments !== undefined ? rawComments : [];
options = options !== undefined ? options : {};
return rawComments.reduce(function(accumulator, comment) {
var user = comment.user;
var replyComments = comment.reply_comment;
// Process main comment user
accumulator.users.push(userDataUtils.bg(user));
// Process reply comment users
(replyComments || []).forEach(function(reply) {
var replyUser = reply.user;
accumulator.users.push(userDataUtils.bg(replyUser));
});
// Process comment structure
accumulator.comments.push(processCommentStructure(comment, options));
// Process comment items for individual management
userDataUtils.PT(comment, options).forEach(function(commentItem) {
accumulator.commentItems.push(commentItem);
});
return accumulator;
}, {
users: [],
comments: [],
commentItems: []
});
}
/**
* Process individual comment structure
*/
function processCommentStructure(comment, options) {
options = options !== undefined ? options : {};
return {
cid: comment.cid,
logId: options.logId,
reply_comment: comment.reply_comment ?
comment.reply_comment.map(function(reply) {
return processCommentStructure(reply, options);
}) : undefined,
replyCache: null
};
}
/**
* Fetch reply comments API call
*/
function fetchReplyComments(params) {
return asyncUtils._(function() {
return generatorUtils.__generator(this, function(step) {
return [2, httpClient.h.get("/api/comment/list/reply/", {
query: mergeUtils._(assignUtils._(assignUtils._({}, params), {
count: 3,
aid: 1988,
app_language: "ja-JP",
device_platform: "web_pc",
current_region: "JP",
fromWeb: 1,
enter_from: "tiktok_web"
}),
baseUrlType: baseUrlTypes.Z4.FixedWww
})];
});
})();
}
/**
* Send comment digg (like/unlike) request
*/
function sendCommentDiggRequest(params) {
return asyncUtils._(function() {
return generatorUtils.__generator(this, function(step) {
return [2, httpClient.h.post("/api/comment/digg/", {
query: mergeUtils._(assignUtils._(assignUtils._({}, params), {
aid: 1988,
channel_id: statusCodes.F.Hot
}),
headers: assignUtils._(assignUtils._({}, baseUrlTypes.nk, httpClient.h.csrfToken)),
baseUrlType: baseUrlTypes.Z4.FixedWww
})];
});
})();
}
// Export service hooks
var useCommentService = commentService.useAtomService;
var useCommentState = commentService.useServiceState;
var useCommentDispatchers = commentService.useServiceDispatchers;
var getCommentStaticApi = commentService.getStaticApi;
},
/**
* Module 90059: Search Analytics
* Comprehensive search and interaction analytics
*/
90059: function(exports, module, require) {
require.d(exports, {
$G: function() { return searchAnalytics; },
Cy: function() { return SearchSource; },
HT: function() { return SearchAction; },
Kq: function() { return SearchEnterMethod; },
M2: function() { return SearchFeedbackType; },
TI: function() { return SearchFeedbackReason; },
VQ: function() { return LiveClickAction; },
ez: function() { return SearchResultSource; },
fk: function() { return SearchFeedbackAction; },
fo: function() { return PersonalizationToggle; },
k0: function() { return SuggestionType; },
ks: function() { return TokenType; },
n: function() { return PersonalizationChange; },
nX: function() { return SearchType; },
rU: function() { return WordsSource; }
});
var objectUtils = require(5377);
var mergeUtils = require(45996);
var teaAnalytics = require(77226);
/**
* Search enter methods for analytics
*/
var SearchEnterMethod = {
ClickEnter: "click_enter",
ClickIcon: "click_icon",
ClickViewAll: "click_view_all",
ClickSearch: "homepage_click_search",
ClickMoreGeneralList: "click_more_general_list",
ClickSearchResult: "click_search_result",
SearchHistory: "search_history",
RecomSearch: "recom_search",
ManagePersonalise: "manage_personalise"
};
/**
* Search result sources
*/
var SearchResultSource = {
Hot: "hot",
Sav: "top",
Music: "music",
SearchBar: "search_bar_outer",
ExploreAll: "explore_all"
};
/**
* Suggestion types
*/
var SuggestionType = {
EnrichSug: "enrich_sug",
NormalSug: "normal_sug"
};
/**
* Search types
*/
var SearchType = {
User: "user",
Video: "video",
General: "general",
Live: "live",
Photo: "photo"
};
/**
* Search feedback types
*/
var SearchFeedbackType = {
RecomSearchFeedback: "recom_search_feedback"
};
/**
* Search sources
*/
var SearchSource = {
RecomSearch: "recom_search",
SearchHistory: "search_history",
VideoTitleChallenge: "video_title_challenge",
NormalSearch: "normal_search",
SearchOuter: "search_outer",
SwitchTab: "switch_tab",
ClickMoreGeneralList: "click_more_general_list",
SearchSug: "search_sug",
DefaultSearchKeyword: "default_search_keyword",
CommentRelatedSearch: "comment_related_search",
CommentHighlightedWords: "comment_highlighted_words",
RelatedSearch: "related_search"
};
/**
* Words sources for trending/suggestion analytics
*/
var WordsSource = {
Sug: "sug",
RecomSearch: "recom_search",
SearchBar: "related_search_anchor_v2",
CommentRelatedSearch: "comment_related_search",
CommentHighlightedWords: "comment_highlighted_words",
RelatedSearch: "related_search",
ExploreAll: "explore_all"
};
/**
* Token types for search results
*/
var TokenType = {
Tag: "tag",
Person: "person",
LiveCard: "live_card",
HotUser: "hot_user"
};
/**
* Live click actions
*/
var LiveClickAction = {
ClickIntoLive: "click_into_live",
ClickInfo: "click_info",
ClickClose: "click_close",
ClickBlankSpace: "click_blank_space",
ClickDone: "click_done"
};
/**
* Search feedback actions
*/
var SearchFeedbackAction = {
Report: "report",
NotRelevant: "not_relevant",
Close: "close"
};
/**
* Search actions
*/
var SearchAction = {
Enter: "enter",
Cancel: "cancel"
};
/**
* Search feedback reasons
*/
var SearchFeedbackReason = {
NotInterested: "Not interested",
UnrelatedContent: "Unrelated content",
InappropriateContent: "Inappropriate content",
Others: "others",
Cancel: "cancel"
};
/**
* Personalization change types
*/
var PersonalizationChange = {
OnToOff: 1,
OffToOn: 2,
RemainOff: 3,
RemainOn: 4
};
/**
* Personalization toggle states
*/
var PersonalizationToggle = {
On: "on",
Off: "off"
};
/**
* Comprehensive search analytics service
*/
var searchAnalytics = {
/**
* Handle suggestion click
*/
handleSugClick: function(params) {
teaAnalytics.f.sendEvent("trending_words_click", params);
},
/**
* Handle suggestion impression
*/
handleSugImpression: function(params) {
teaAnalytics.f.sendEvent("trending_words_show", params);
},
/**
* Handle suggestion group impression
*/
handleSugGroupImpression: function(params) {
teaAnalytics.f.sendEvent("trending_show", params);
},
/**
* Handle search entry
*/
handleSearchEntry: function(params) {
teaAnalytics.f.sendEvent("enter_search", params);
},
/**
* Handle search result impression
*/
handleSearchImpression: function(params) {
teaAnalytics.f.sendEvent("search_result_show", objectUtils._({
token_type: "person"
}, params));
},
/**
* Handle video search result impression
*/
handleSearchVideoImpression: function(params) {
teaAnalytics.f.sendEvent("search_result_show_video", objectUtils._(objectUtils._({}, params)));
},
/**
* Handle search execution
*/
handleSearch: function(params) {
teaAnalytics.f.sendEvent("search", mergeUtils._(objectUtils._(objectUtils._({}, params), {
is_success: 1
}));
},
/**
* Handle search result click
*/
handleSearchResultClick: function(params) {
teaAnalytics.f.sendEvent("search_result_click", objectUtils._(objectUtils._({}, params)));
},
/**
* Handle search session finish
*/
handleSearchSessionFinish: function(params) {
teaAnalytics.f.sendEvent("search_session_finish", params);
},
/**
* Handle empty search results
*/
handleSearchResultEmpty: function(params) {
teaAnalytics.f.sendEvent("empty_search", objectUtils._(objectUtils._({}, params)));
},
/**
* Handle search click
*/
handleClickSearch: function(params) {
var target = params.target;
teaAnalytics.f.sendEvent("click_search", {
target: target !== undefined ? target : "homepage_click_search"
});
},
/**
* Handle search page entry
*/
handleEnterSearchPage: function(params) {
var enterMethod = params.enter_method;
teaAnalytics.f.sendEvent("enter_search_page", {
enter_method: enterMethod !== undefined ? enterMethod : "homepage_click_search"
});
},
/**
* Handle search blank page entry
*/
handleEnterSearchBlankPage: function(params) {
teaAnalytics.f.sendEvent("enter_search_blankpage", params);
},
/**
* Handle search history interaction
*/
handleSearchHistory: function(params) {
teaAnalytics.f.sendEvent("search_history", params);
},
/**
* Handle trending words show
*/
handleTrendingWordsShow: function(params) {
teaAnalytics.f.sendEvent("trending_words_show", params);
},
/**
* Handle trending words click
*/
handleTrendingWordsClick: function(params) {
teaAnalytics.f.sendEvent("trending_words_click", params);
},
/**
* Handle trending show
*/
handleTrendingShow: function(params) {
teaAnalytics.f.sendEvent("trending_show", params);
},
/**
* Handle comment related search board show
*/
handleCommentRelatedSearchBoardShow: function(params) {
teaAnalytics.f.sendEvent("comment_related_search_board_show", params);
},
/**
* Handle comment related search board click
*/
handleCommentRelatedSearchBoardClick: function(params) {
teaAnalytics.f.sendEvent("comment_related_search_board_click", params);
},
/**
* Handle suggestion report confirm
*/
handleSugReportConfirm: function(params) {
teaAnalytics.f.sendEvent("sug_report_confirm", params);
},
/**
* Handle suggestion report launch
*/
handleSugReportLaunch: function(params) {
teaAnalytics.f.sendEvent("sug_report_launch", params);
},
/**
* Handle challenge title click
*/
handleChallengeTitleClick: function(params) {
teaAnalytics.f.sendEvent("challenge_title_click", params);
},
/**
* Handle search feedback click
*/
handleClickSearchFeedback: function(params) {
teaAnalytics.f.sendEvent("click_search_feedback", params);
},
/**
* Handle search text submit
*/
handleSearchTextSubmit: function(params) {
teaAnalytics.f.sendEvent("search_text_submit", params);
},
/**
* Handle search feedback status
*/
handleSearchFeedbackStatus: function(params) {
teaAnalytics.f.sendEvent("search_feedback_status", params);
},
/**
* Handle manage search popup show
*/
handleManageSearchPopupShow: function(params) {
teaAnalytics.f.sendEvent("manage_search_popup_show", params);
},
/**
* Handle manage search popup click
*/
handleManageSearchPopupClick: function(params) {
teaAnalytics.f.sendEvent("manage_search_popup_click", params);
},
/**
* Handle search non-personalization entrance show
*/
handleSearchNonPersonalizationEntranceShow: function(params) {
teaAnalytics.f.sendEvent("search_non_personalization_entrance_show", params);
}
};
}
}]);