在 macOS 上使用 :syntax 打开简单的 .tsx (TypeScript) 文件时会导致 vim 崩溃
const MessageActions = findByPropsLazy("fetchMessages", "sendMessage");
function getTotalReactions(message: Message): number { if (!message?.reactions) { return 0; } return message.reactions.reduce((sum, reaction) => sum + (reaction.count ?? 0), 0); }
function getOldestMessage(channelId: string): Message | undefined { const messagesObj = MessageStore.getMessages(channelId); const currentMessages = messagesObj?._array ?? []; return currentMessages.reduce((oldest, msg) => { if (!oldest || BigInt(msg.id) < BigInt(oldest.id)) { return msg; } return oldest; }, undefined as Message | undefined); }
const LoadAndSortButton: ChatBarButtonFactory = ({ isMainChat }) => { if (!isMainChat) return null;
const [isLoading, setIsLoading] = useState(false);
const currentChannelId = SelectedChannelStore.getChannelId();
const oldestMessageTimestampText = useStateFromStores(
[MessageStore, SelectedChannelStore],
() => {
const chanId = SelectedChannelStore.getChannelId();
if (!chanId) return "";
const oldestMsg = getOldestMessage(chanId);
if (!oldestMsg) return "";
return DateUtils.calendarFormat(oldestMsg.timestamp);
}
);
const handleLoadAndSortClick = async () => {
const channelId = SelectedChannelStore.getChannelId();
if (!channelId || isLoading) {
return;
}
if (!MessageActions?.fetchMessages) {
return;
}
setIsLoading(true);
const FETCH_LIMIT = 100;
let fetchError = null;
try {
const oldestMsg = getOldestMessage(channelId);
await MessageActions.fetchMessages({
channelId: channelId,
limit: FETCH_LIMIT,
before: oldestMsg?.id,
});
await sleep(100);
const messagesObj = MessageStore.getMessages(channelId);
const messagesArray = messagesObj?._array;
if (messagesArray && messagesArray.length > 0) {
messagesArray.sort((a, b) => getTotalReactions(a) -
…
内容来源: vim/vim