Skip to content

Commit

Permalink
fixup! Allowing message action items to be already set.
Browse files Browse the repository at this point in the history
  • Loading branch information
splindsay-92 committed Oct 24, 2024
1 parent 543b360 commit a8dd4cf
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/common/lib/types/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ const MessageActionArray: API.MessageAction[] = [
'message_meta_occupancy',
];

const MessageActionMap = new Map<API.MessageAction, number>(MessageActionArray.map((action, index) => [action, index]));

const ReverseMessageActionMap = new Map<number, API.MessageAction>(
MessageActionArray.map((action, index) => [index, action]),
);

function toMessageActionString(actionNumber: number): API.MessageAction | undefined {
if (actionNumber in MessageActionArray) {
return MessageActionArray[actionNumber];
}
return ReverseMessageActionMap.get(actionNumber);
}

function toMessageActionNumber(messageAction?: API.MessageAction): number | undefined {
for (const [index, value] of MessageActionArray.entries()) {
if (value === messageAction) {
return index;
}
}
return messageAction ? MessageActionMap.get(messageAction) : undefined;
}

export type CipherOptions = {
Expand Down

0 comments on commit a8dd4cf

Please sign in to comment.