Update files
This commit is contained in:
parent
f6baf7ed3e
commit
fc3864aa33
|
|
@ -197,9 +197,20 @@ const pollUpdates = async () => {
|
||||||
// Продолжить опрос
|
// Продолжить опрос
|
||||||
setTimeout(poll, 1000);
|
setTimeout(poll, 1000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logError('Ошибка опроса Telegram для основного бота', error);
|
const errorData = error.response?.data || {};
|
||||||
// Переподключиться через 5 секунд
|
const errorCode = errorData.error_code;
|
||||||
setTimeout(poll, 5000);
|
const errorDescription = errorData.description || error.message;
|
||||||
|
|
||||||
|
// Обработка конфликта 409 - другой экземпляр бота уже опрашивает
|
||||||
|
if (errorCode === 409) {
|
||||||
|
// Не логируем 409 - это ожидаемая ситуация при конфликте экземпляров
|
||||||
|
// Подождать дольше перед повторной попыткой
|
||||||
|
setTimeout(poll, 10000);
|
||||||
|
} else {
|
||||||
|
logError('Ошибка опроса Telegram для основного бота', error);
|
||||||
|
// Переподключиться через 5 секунд
|
||||||
|
setTimeout(poll, 5000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -310,12 +310,17 @@ const processUpdate = async (update) => {
|
||||||
const pollUpdates = async () => {
|
const pollUpdates = async () => {
|
||||||
if (!TELEGRAM_API) return;
|
if (!TELEGRAM_API) return;
|
||||||
|
|
||||||
while (isPolling) {
|
const poll = async () => {
|
||||||
|
if (!isPolling) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${TELEGRAM_API}/getUpdates`, {
|
const response = await axios.get(`${TELEGRAM_API}/getUpdates`, {
|
||||||
params: {
|
params: {
|
||||||
timeout: 25,
|
timeout: 25,
|
||||||
offset
|
offset,
|
||||||
|
allowed_updates: ['message']
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -324,13 +329,35 @@ const pollUpdates = async () => {
|
||||||
offset = update.update_id + 1;
|
offset = update.update_id + 1;
|
||||||
await processUpdate(update);
|
await processUpdate(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Продолжить опрос
|
||||||
|
setTimeout(poll, 100);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log('error', 'Ошибка опроса Telegram для модераторского бота', {
|
const errorData = error.response?.data || {};
|
||||||
error: error.response?.data || error.message
|
const errorCode = errorData.error_code;
|
||||||
});
|
const errorDescription = errorData.description || error.message;
|
||||||
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
||||||
|
// Обработка конфликта 409 - другой экземпляр бота уже опрашивает
|
||||||
|
if (errorCode === 409) {
|
||||||
|
// Не логируем 409 - это ожидаемая ситуация при конфликте экземпляров
|
||||||
|
// Подождать дольше перед повторной попыткой
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 10000));
|
||||||
|
} else {
|
||||||
|
log('error', 'Ошибка опроса Telegram для модераторского бота', {
|
||||||
|
error: errorData || error.message
|
||||||
|
});
|
||||||
|
// Обычная задержка при других ошибках
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Продолжить опрос только если isPolling все еще true
|
||||||
|
if (isPolling) {
|
||||||
|
setTimeout(poll, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
poll();
|
||||||
};
|
};
|
||||||
|
|
||||||
const startServerMonitorBot = () => {
|
const startServerMonitorBot = () => {
|
||||||
|
|
@ -340,13 +367,40 @@ const startServerMonitorBot = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPolling) {
|
if (isPolling) {
|
||||||
|
log('warn', 'Модераторский бот уже запущен, пропускаем повторный запуск');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Инициализировать offset перед началом опроса
|
||||||
|
const initializeOffset = async () => {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`${TELEGRAM_API}/getUpdates`, {
|
||||||
|
params: {
|
||||||
|
timeout: 1,
|
||||||
|
allowed_updates: ['message']
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const updates = response.data?.result || [];
|
||||||
|
if (updates.length > 0) {
|
||||||
|
offset = updates[updates.length - 1].update_id + 1;
|
||||||
|
log('info', `Модераторский бот: пропущено ${updates.length} старых обновлений, offset установлен на ${offset}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
log('warn', 'Не удалось инициализировать offset для модераторского бота, начнем с 0', {
|
||||||
|
error: error.response?.data || error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
isPolling = true;
|
isPolling = true;
|
||||||
log('info', 'Модераторский Telegram бот запущен');
|
log('info', 'Модераторский Telegram бот запущен');
|
||||||
pollUpdates().catch((error) => {
|
|
||||||
|
initializeOffset().then(() => {
|
||||||
|
pollUpdates();
|
||||||
|
}).catch((error) => {
|
||||||
log('error', 'Не удалось запустить модераторский бот', { error: error.message });
|
log('error', 'Не удалось запустить модераторский бот', { error: error.message });
|
||||||
|
isPolling = false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { decodeHtmlEntities } from '../utils/htmlEntities'
|
||||||
import './CommentsModal.css'
|
import './CommentsModal.css'
|
||||||
|
|
||||||
export default function CommentsModal({ post, onClose, onUpdate }) {
|
export default function CommentsModal({ post, onClose, onUpdate }) {
|
||||||
|
// ВСЕ хуки должны вызываться всегда, до любых условных возвратов
|
||||||
const [comment, setComment] = useState('')
|
const [comment, setComment] = useState('')
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [comments, setComments] = useState([])
|
const [comments, setComments] = useState([])
|
||||||
|
|
@ -14,59 +15,47 @@ export default function CommentsModal({ post, onClose, onUpdate }) {
|
||||||
const [loadingPost, setLoadingPost] = useState(false)
|
const [loadingPost, setLoadingPost] = useState(false)
|
||||||
|
|
||||||
// Загрузить полные данные поста с комментариями
|
// Загрузить полные данные поста с комментариями
|
||||||
const loadFullPost = useCallback(async (postId) => {
|
useEffect(() => {
|
||||||
if (!postId) {
|
if (!post || !post._id) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// Сначала установим переданные данные
|
||||||
setLoadingPost(true)
|
setFullPost(post)
|
||||||
// Загрузить посты с фильтром по автору поста для оптимизации
|
const initialComments = (post.comments || []).filter(c => {
|
||||||
// Если это не помогает, загружаем больше постов
|
return c && c.author && (typeof c.author === 'object')
|
||||||
const authorId = post?.author?._id || post?.author
|
})
|
||||||
const response = authorId
|
setComments(initialComments)
|
||||||
? await getPosts({ userId: authorId, limit: 100 })
|
|
||||||
: await getPosts({ limit: 200 })
|
|
||||||
|
|
||||||
const foundPost = response.posts?.find(p => p._id === postId)
|
// Затем загрузим полные данные для обновления
|
||||||
if (foundPost) {
|
const loadFullPost = async () => {
|
||||||
// Проверяем, что комментарии populate'ены с авторами
|
try {
|
||||||
const commentsWithAuthors = (foundPost.comments || []).filter(c => {
|
setLoadingPost(true)
|
||||||
return c && c.author && (typeof c.author === 'object')
|
// Загрузить посты с фильтром по автору поста для оптимизации
|
||||||
})
|
const authorId = post?.author?._id || post?.author
|
||||||
setComments(commentsWithAuthors)
|
const response = authorId
|
||||||
setFullPost(foundPost)
|
? await getPosts({ userId: authorId, limit: 100 })
|
||||||
} else {
|
: await getPosts({ limit: 200 })
|
||||||
// Если не нашли, используем переданные данные
|
|
||||||
const commentsWithAuthors = (post.comments || []).filter(c => {
|
const foundPost = response.posts?.find(p => p._id === post._id)
|
||||||
return c && c.author && (typeof c.author === 'object')
|
if (foundPost) {
|
||||||
})
|
// Проверяем, что комментарии populate'ены с авторами
|
||||||
setComments(commentsWithAuthors)
|
const commentsWithAuthors = (foundPost.comments || []).filter(c => {
|
||||||
|
return c && c.author && (typeof c.author === 'object')
|
||||||
|
})
|
||||||
|
setComments(commentsWithAuthors)
|
||||||
|
setFullPost(foundPost)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[CommentsModal] Ошибка загрузки поста:', error)
|
||||||
|
// Оставляем переданные данные
|
||||||
|
} finally {
|
||||||
|
setLoadingPost(false)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error('[CommentsModal] Ошибка загрузки поста:', error)
|
|
||||||
// Fallback на переданные данные
|
|
||||||
const commentsWithAuthors = (post.comments || []).filter(c => {
|
|
||||||
return c && c.author && (typeof c.author === 'object')
|
|
||||||
})
|
|
||||||
setComments(commentsWithAuthors)
|
|
||||||
} finally {
|
|
||||||
setLoadingPost(false)
|
|
||||||
}
|
}
|
||||||
}, [post?.author])
|
|
||||||
|
|
||||||
useEffect(() => {
|
loadFullPost()
|
||||||
if (post && post._id) {
|
}, [post?._id]) // Только ID поста в зависимостях
|
||||||
// Сначала установим переданные данные
|
|
||||||
setFullPost(post)
|
|
||||||
const initialComments = (post.comments || []).filter(c => {
|
|
||||||
return c && c.author && (typeof c.author === 'object')
|
|
||||||
})
|
|
||||||
setComments(initialComments)
|
|
||||||
// Затем загрузим полные данные для обновления
|
|
||||||
loadFullPost(post._id)
|
|
||||||
}
|
|
||||||
}, [post?._id, loadFullPost])
|
|
||||||
|
|
||||||
// Проверка на существование поста ПОСЛЕ хуков
|
// Проверка на существование поста ПОСЛЕ хуков
|
||||||
if (!post) {
|
if (!post) {
|
||||||
|
|
@ -102,9 +91,8 @@ export default function CommentsModal({ post, onClose, onUpdate }) {
|
||||||
hapticFeedback('success')
|
hapticFeedback('success')
|
||||||
|
|
||||||
// Обновить данные поста для синхронизации (но не блокируем UI)
|
// Обновить данные поста для синхронизации (но не блокируем UI)
|
||||||
loadFullPost(post._id).catch(err => {
|
// Перезагружаем через useEffect, который сработает при изменении post._id
|
||||||
console.error('[CommentsModal] Ошибка при обновлении после добавления:', err)
|
// Но так как post._id не меняется, просто обновим локально
|
||||||
})
|
|
||||||
|
|
||||||
if (onUpdate) {
|
if (onUpdate) {
|
||||||
onUpdate()
|
onUpdate()
|
||||||
|
|
@ -112,17 +100,6 @@ export default function CommentsModal({ post, onClose, onUpdate }) {
|
||||||
} else {
|
} else {
|
||||||
console.error('[CommentsModal] Неожиданный формат ответа:', result)
|
console.error('[CommentsModal] Неожиданный формат ответа:', result)
|
||||||
hapticFeedback('error')
|
hapticFeedback('error')
|
||||||
// Попробуем перезагрузить комментарии
|
|
||||||
await loadFullPost(post._id)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('[CommentsModal] Ошибка добавления комментария:', error)
|
|
||||||
hapticFeedback('error')
|
|
||||||
// Попробуем перезагрузить комментарии в случае ошибки
|
|
||||||
try {
|
|
||||||
await loadFullPost(post._id)
|
|
||||||
} catch (reloadError) {
|
|
||||||
console.error('[CommentsModal] Ошибка при перезагрузке:', reloadError)
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
|
|
||||||
|
|
@ -103,17 +103,17 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.user-item-wrapper {
|
.user-item-wrapper {
|
||||||
padding: 4px 12px;
|
padding: 3px 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.user-item {
|
.user-item {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 8px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background 0.2s;
|
transition: background 0.2s;
|
||||||
padding: 6px;
|
padding: 5px;
|
||||||
border-radius: 8px;
|
border-radius: 6px;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,8 +122,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.user-avatar {
|
.user-avatar {
|
||||||
width: 32px;
|
width: 26px;
|
||||||
height: 32px;
|
height: 26px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
|
|
@ -138,7 +138,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.user-name {
|
.user-name {
|
||||||
font-size: 14px;
|
font-size: 12px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
line-height: 1.3;
|
line-height: 1.3;
|
||||||
|
|
@ -148,7 +148,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.user-username {
|
.user-username {
|
||||||
font-size: 12px;
|
font-size: 15px;
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
line-height: 1.3;
|
line-height: 1.3;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|
@ -158,8 +158,8 @@
|
||||||
|
|
||||||
/* Follow Button Icon */
|
/* Follow Button Icon */
|
||||||
.follow-btn-icon {
|
.follow-btn-icon {
|
||||||
width: 32px;
|
width: 26px;
|
||||||
height: 32px;
|
height: 26px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background: var(--bg-primary);
|
background: var(--bg-primary);
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
|
|
|
||||||
|
|
@ -112,9 +112,9 @@ export default function FollowListModal({ users, title, onClose, currentUser })
|
||||||
onClick={(e) => handleFollowToggle(user._id, e)}
|
onClick={(e) => handleFollowToggle(user._id, e)}
|
||||||
>
|
>
|
||||||
{isFollowing ? (
|
{isFollowing ? (
|
||||||
<UserMinus size={18} />
|
<UserMinus size={16} />
|
||||||
) : (
|
) : (
|
||||||
<UserPlus size={18} />
|
<UserPlus size={16} />
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue