Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void deleteMessage() {
- if (!currentUser || (!currentUser->isAdmin && !currentUser->isModerator)) {
- cout << "Удаление сообщений требует прав модератора или администратора." << endl;
- return;
- }
- int sectionId, topicId, messageId;
- cout << "Введите ID раздела: ";
- cin >> sectionId;
- cout << "Введите ID темы: ";
- cin >> topicId;
- cout << "Введите ID сообщения: ";
- cin >> messageId;
- auto sectionIt = find_if(sections.begin(), sections.end(), [sectionId](Section& s) { return s.id == sectionId; });
- if (sectionIt == sections.end()) {
- cout << "Раздел не найден." << endl;
- return;
- }
- auto topicIt = find_if(sectionIt->topics.begin(), sectionIt->topics.end(), [topicId](Topic& t) { return t.id == topicId; });
- if (topicIt == sectionIt->topics.end()) {
- cout << "Тема не найдена." << endl;
- return;
- }
- deleteMessageRecursive(topicIt->messages, messageId);
- cout << "Сообщение удалено." << endl;
- }
- void moveTopicToSection() {
- if (!currentUser || (!currentUser->isAdmin && !currentUser->isModerator)) {
- cout << "Перенос тем требует прав модератора или администратора." << endl;
- return;
- }
- int fromSectionId, toSectionId, topicId;
- cout << "Введите ID раздела, из которого переносится тема: ";
- cin >> fromSectionId;
- cout << "Введите ID раздела, в который переносится тема: ";
- cin >> toSectionId;
- cout << "Введите ID темы: ";
- cin >> topicId;
- auto fromSectionIt = find_if(sections.begin(), sections.end(), [fromSectionId](Section& s) { return s.id == fromSectionId; });
- if (fromSectionIt == sections.end()) {
- cout << "Исходный раздел не найден." << endl;
- return;
- }
- auto toSectionIt = find_if(sections.begin(), sections.end(), [toSectionId](Section& s) { return s.id == toSectionId; });
- if (toSectionIt == sections.end()) {
- cout << "Целевой раздел не найден." << endl;
- return;
- }
- auto topicIt = find_if(fromSectionIt->topics.begin(), fromSectionIt->topics.end(), [topicId](Topic& t) { return t.id == topicId; });
- if (topicIt == fromSectionIt->topics.end()) {
- cout << "Тема не найдена." << endl;
- return;
- }
- toSectionIt->topics.push_back(*topicIt);
- fromSectionIt->topics.erase(topicIt);
- cout << "Тема перенесена." << endl;
- }
- private:
- Message* findMessage(vector<Message>& messages, int messageId) {
- for (Message& message : messages) {
- if (message.id == messageId) {
- return &message;
- }
- Message* found = findMessage(message.replies, messageId);
- if (found) {
- return found;
- }
- }
- return nullptr;
- }
- void deleteMessageRecursive(vector<Message>& messages, int messageId) {
- for (auto it = messages.begin(); it != messages.end(); ++it) {
- if (it->id == messageId) {
- messages.erase(it);
- return;
- }
- deleteMessageRecursive(it->replies, messageId);
- }
- }
- void displayMessage(const Message& message, int indent) {
- for (int i = 0; i < indent; ++i) {
- cout << " ";
- }
- cout << "ID: " << message.id << ", Автор: " << message.author << ", Дата: " << asctime(localtime(&message.creationDate));
- for (int i = 0; i < indent; ++i) {
- cout << " ";
- }
- cout << "Текст: " << message.text << endl;
- for (const Message& reply : message.replies) {
- displayMessage(reply, indent + 1);
- }
- }
- };
- int main() {
- Forum forum;
- int choice;
Advertisement
Add Comment
Please, Sign In to add comment