chatmessage.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef CHATMESSAGE_H
  2. #define CHATMESSAGE_H
  3. #include <QDateTime>
  4. #include <QObject>
  5. #include <QString>
  6. namespace ChatConstants {
  7. static constexpr int AVATAR_SIZE = 40;
  8. static constexpr int BUBBLE_PADDING = 12;
  9. static constexpr int BUBBLE_SPACING = 8;
  10. static constexpr int BUBBLE_RADIUS = 8;
  11. static constexpr int TIMESTAMP_HEIGHT = 20;
  12. // static constexpr int MAX_WIDTH = 600;
  13. } // namespace ChatConstants
  14. // 添加消息类型枚举
  15. enum class MessageType {
  16. Left, // 接收到的消息
  17. Right, // 发送的消息
  18. System, // 系统消息
  19. Private // 私聊消息
  20. };
  21. class ChatMessage
  22. {
  23. public:
  24. QString id;
  25. QString text;
  26. QString senderId;
  27. QString senderName;
  28. QString roomId;
  29. QString avatar;
  30. MessageType type = MessageType::Left;
  31. QDateTime timestamp = QDateTime::currentDateTime();
  32. bool isRead = false;
  33. ChatMessage(const QString &text = QString(),
  34. MessageType type = MessageType::Left,
  35. const QDateTime &timestamp = QDateTime::currentDateTime())
  36. : text(text)
  37. , type(type)
  38. , timestamp(timestamp)
  39. {}
  40. bool isLeft() const { return type == MessageType::Left; }
  41. bool isRight() const { return type == MessageType::Right; }
  42. bool isSystem() const { return type == MessageType::System; }
  43. };
  44. Q_DECLARE_METATYPE(ChatMessage)
  45. #endif // CHATMESSAGE_H