Conversation.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
  3. * All rights reserved. Distributed under the terms of the MIT license.
  4. */
  5. #ifndef CONVERSATION_H
  6. #define CONVERSATION_H
  7. #include <DateTimeFormat.h>
  8. #include <Messenger.h>
  9. #include <Path.h>
  10. #include <StringList.h>
  11. #include <libsupport/KeyMap.h>
  12. #include "Observer.h"
  13. #include "Role.h"
  14. #include "Server.h"
  15. #include "User.h"
  16. class BBitmap;
  17. class ConversationItem;
  18. class ConversationView;
  19. class ProtocolLooper;
  20. class Server;
  21. typedef KeyMap<BString, User*> UserMap;
  22. typedef KeyMap<BString, Role*> RoleMap;
  23. class Conversation : public Notifier, public Observer {
  24. public:
  25. Conversation(BString id, BMessenger msgn);
  26. ~Conversation();
  27. BString GetId() const;
  28. void ImMessage(BMessage* msg);
  29. // Tell the ConversationView to invalidate user list
  30. void ObserveString(int32 what, BString str);
  31. void ObserveInteger(int32 what, int32 value);
  32. void ObservePointer(int32 what, void* ptr);
  33. void SetNotifyName(const char* name);
  34. void SetNotifySubject(const char* subject);
  35. bool SetNotifyIconBitmap(BBitmap* icon);
  36. BMessenger Messenger() const;
  37. void SetMessenger(BMessenger messenger);
  38. ProtocolLooper* GetProtocolLooper() const;
  39. void SetProtocolLooper(ProtocolLooper* looper);
  40. BString GetName() const;
  41. BString GetSubject() const;
  42. BBitmap* ProtocolBitmap() const;
  43. BBitmap* IconBitmap() const;
  44. ConversationView* GetView();
  45. void ShowView(bool typing, bool userAction);
  46. ConversationItem* GetListItem();
  47. UserMap Users();
  48. User* UserById(BString id);
  49. Contact* GetOwnContact();
  50. void AddUser(User* user);
  51. void RemoveUser(User* user);
  52. void SetRole(BString id, Role* role);
  53. Role* GetRole(BString id);
  54. int32 GetFlags() { return fRoomFlags; }
  55. void SetFlags(int32 flags);
  56. int32 DisallowedFlags() { return fDisallowedFlags; }
  57. private:
  58. void _WarnUser(BString message);
  59. void _LogChatMessage(BMessage* msg);
  60. status_t _GetChatLogs(BMessage* msg);
  61. void _CacheRoomFlags();
  62. void _LoadRoomFlags();
  63. void _EnsureCachePath();
  64. User* _EnsureUser(BMessage* msg, bool implicit = true);
  65. Role* _GetRole(BMessage* msg);
  66. void _UpdateIcon(User* user = NULL);
  67. bool _IsDefaultIcon(BBitmap* icon);
  68. void _SortConversationList();
  69. Server* _GetServer();
  70. BMessenger fMessenger;
  71. ProtocolLooper* fLooper;
  72. ConversationView* fChatView;
  73. ConversationItem* fConversationItem;
  74. int32 fNotifyMessageCount;
  75. int32 fNotifyMentionCount;
  76. BString fID;
  77. BString fName;
  78. BString fSubject;
  79. BBitmap* fIcon;
  80. bool fUserIcon;
  81. BPath fCachePath;
  82. BDateTimeFormat fDateFormatter;
  83. int32 fRoomFlags;
  84. int32 fDisallowedFlags;
  85. UserMap fUsers; // For defined, certain members of the room
  86. BStringList fGuests; // IDs of implicitly-defined users
  87. RoleMap fRoles;
  88. };
  89. #endif // CONVERSATION_H