Skip to content

Commit

Permalink
feat: Add executor to MarkChatItemAsDeletedAction
Browse files Browse the repository at this point in the history
  • Loading branch information
uetchy committed May 26, 2022
1 parent 80123c7 commit c64ebb6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

- Move video comments API to Masterchat class
- `mc.getComments()`
- Add `executor` to `MarkChatItemAsDeletedAction`

### Fixes

Expand Down
12 changes: 9 additions & 3 deletions src/chat/actions/markChatItemAsDeletedAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,33 @@ export function parseMarkChatItemAsDeletedAction(
payload: YTMarkChatItemAsDeletedAction
) {
const statusText = payload.deletedStateMessage.runs[0].text;
// {"deletedStateMessage":{"runs":[{"text":"Message deleted by "},{"text":"uetchy","bold":true},{"text":"."}]},"targetItemId":"Ch4KGkNONjBtTHZWX1BjQ0ZSTUNyUVlkclZBRnlREgA%3D","showOriginalContentMessage":{"runs":[{"text":"View deleted message","italics":true}]}
// [{"text":"Message deleted by "},{"text":"uetchy","bold":true},{"text":"."}]
switch (statusText) {
case "[message retracted]":
case "[message deleted]":
case "Message deleted by ":
break;
default:
debugLog(
"[action required] Unrecognized deletion status:",
statusText,
JSON.stringify(payload)
);
throw new Error(
`Unrecognized deletion status: ${payload.deletedStateMessage}`
);
}

const executor =
statusText === "Message deleted by "
? payload.deletedStateMessage.runs[1].text
: undefined;

const retracted = statusText === "[message retracted]";

const parsed: MarkChatItemAsDeletedAction = {
type: "markChatItemAsDeletedAction",
retracted,
targetId: payload.targetItemId,
executor,
timestamp: new Date(),
};
return parsed;
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export interface MarkChatItemAsDeletedAction {
type: "markChatItemAsDeletedAction";
retracted: boolean;
targetId: string;
executor?: string;
timestamp: Date;
}

Expand Down

0 comments on commit c64ebb6

Please sign in to comment.