Maestro1

Untitled

May 31st, 2024
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.26 KB | None | 0 0
  1.  
  2.  
  3.     void deleteMessage() {
  4.         if (!currentUser || (!currentUser->isAdmin && !currentUser->isModerator)) {
  5.            cout << "Удаление сообщений требует прав модератора или администратора." << endl;
  6.             return;
  7.         }
  8.  
  9.         int sectionId, topicId, messageId;
  10.         cout << "Введите ID раздела: ";
  11.        cin >> sectionId;
  12.         cout << "Введите ID темы: ";
  13.        cin >> topicId;
  14.         cout << "Введите ID сообщения: ";
  15.        cin >> messageId;
  16.  
  17.         auto sectionIt = find_if(sections.begin(), sections.end(), [sectionId](Section& s) { return s.id == sectionId; });
  18.         if (sectionIt == sections.end()) {
  19.             cout << "Раздел не найден." << endl;
  20.            return;
  21.        }
  22.  
  23.        auto topicIt = find_if(sectionIt->topics.begin(), sectionIt->topics.end(), [topicId](Topic& t) { return t.id == topicId; });
  24.         if (topicIt == sectionIt->topics.end()) {
  25.             cout << "Тема не найдена." << endl;
  26.            return;
  27.        }
  28.  
  29.        deleteMessageRecursive(topicIt->messages, messageId);
  30.         cout << "Сообщение удалено." << endl;
  31.    }
  32.  
  33.    void moveTopicToSection() {
  34.        if (!currentUser || (!currentUser->isAdmin && !currentUser->isModerator)) {
  35.            cout << "Перенос тем требует прав модератора или администратора." << endl;
  36.             return;
  37.         }
  38.  
  39.         int fromSectionId, toSectionId, topicId;
  40.         cout << "Введите ID раздела, из которого переносится тема: ";
  41.        cin >> fromSectionId;
  42.         cout << "Введите ID раздела, в который переносится тема: ";
  43.        cin >> toSectionId;
  44.         cout << "Введите ID темы: ";
  45.        cin >> topicId;
  46.  
  47.         auto fromSectionIt = find_if(sections.begin(), sections.end(), [fromSectionId](Section& s) { return s.id == fromSectionId; });
  48.         if (fromSectionIt == sections.end()) {
  49.             cout << "Исходный раздел не найден." << endl;
  50.            return;
  51.        }
  52.  
  53.        auto toSectionIt = find_if(sections.begin(), sections.end(), [toSectionId](Section& s) { return s.id == toSectionId; });
  54.        if (toSectionIt == sections.end()) {
  55.            cout << "Целевой раздел не найден." << endl;
  56.            return;
  57.        }
  58.  
  59.        auto topicIt = find_if(fromSectionIt->topics.begin(), fromSectionIt->topics.end(), [topicId](Topic& t) { return t.id == topicId; });
  60.         if (topicIt == fromSectionIt->topics.end()) {
  61.             cout << "Тема не найдена." << endl;
  62.            return;
  63.        }
  64.  
  65.        toSectionIt->topics.push_back(*topicIt);
  66.         fromSectionIt->topics.erase(topicIt);
  67.         cout << "Тема перенесена." << endl;
  68.    }
  69.  
  70. private:
  71.    Message* findMessage(vector<Message>& messages, int messageId) {
  72.        for (Message& message : messages) {
  73.            if (message.id == messageId) {
  74.                return &message;
  75.             }
  76.             Message* found = findMessage(message.replies, messageId);
  77.             if (found) {
  78.                 return found;
  79.             }
  80.         }
  81.         return nullptr;
  82.     }
  83.  
  84.     void deleteMessageRecursive(vector<Message>& messages, int messageId) {
  85.        for (auto it = messages.begin(); it != messages.end(); ++it) {
  86.             if (it->id == messageId) {
  87.                 messages.erase(it);
  88.                 return;
  89.             }
  90.             deleteMessageRecursive(it->replies, messageId);
  91.         }
  92.     }
  93.  
  94.     void displayMessage(const Message& message, int indent) {
  95.        for (int i = 0; i < indent; ++i) {
  96.            cout << "  ";
  97.        }
  98.        cout << "ID: " << message.id << ", Автор: " << message.author << ", Дата: " << asctime(localtime(&message.creationDate));
  99.        for (int i = 0; i < indent; ++i) {
  100.            cout << "  ";
  101.        }
  102.        cout << "Текст: " << message.text << endl;
  103.        for (const Message& reply : message.replies) {
  104.            displayMessage(reply, indent + 1);
  105.        }
  106.    }
  107. };
  108.  
  109. int main() {
  110.    Forum forum;
  111.    int choice;
  112.  
Advertisement
Add Comment
Please, Sign In to add comment