attach_send_files_way.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "ui/chat/attach/attach_send_files_way.h"
  8. namespace Ui {
  9. void SendFilesWay::setSendImagesAsPhotos(bool value) {
  10. if (value) {
  11. _flags |= Flag::SendImagesAsPhotos;
  12. } else {
  13. if (hasCompressedStickers()) {
  14. setGroupFiles(false);
  15. }
  16. _flags &= ~Flag::SendImagesAsPhotos;
  17. }
  18. }
  19. void SendFilesWay::setGroupFiles(bool value) {
  20. if (value) {
  21. _flags |= Flag::GroupFiles;
  22. if (hasCompressedStickers()) {
  23. setSendImagesAsPhotos(true);
  24. }
  25. } else {
  26. _flags &= ~Flag::GroupFiles;
  27. }
  28. }
  29. void SendFilesWay::setHasCompressedStickers(bool value) {
  30. if (value) {
  31. _flags |= Flag::HasCompressedStickers;
  32. } else {
  33. _flags &= ~Flag::HasCompressedStickers;
  34. }
  35. }
  36. //enum class SendFilesWay { // Old way. Serialize should be compatible.
  37. // Album,
  38. // Photos,
  39. // Files,
  40. //};
  41. int32 SendFilesWay::serialize() const {
  42. auto result = (sendImagesAsPhotos() && groupFiles())
  43. ? int32(0)
  44. : sendImagesAsPhotos()
  45. ? int32(1)
  46. : groupFiles()
  47. ? int32(3)
  48. : int32(2);
  49. return result;
  50. }
  51. std::optional<SendFilesWay> SendFilesWay::FromSerialized(int32 value) {
  52. if (value < 0 || value > 3) {
  53. return std::nullopt;
  54. }
  55. auto result = SendFilesWay();
  56. result.setGroupFiles((value == 0) || (value == 3));
  57. result.setSendImagesAsPhotos((value == 0) || (value == 1));
  58. return result;
  59. }
  60. } // namespace Ui