field_characters_count_manager.cpp 917 B

123456789101112131415161718192021222324252627282930313233343536
  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 "chat_helpers/field_characters_count_manager.h"
  8. FieldCharsCountManager::FieldCharsCountManager() = default;
  9. void FieldCharsCountManager::setCount(int count) {
  10. _previous = _current;
  11. _current = count;
  12. if (_previous != _current) {
  13. constexpr auto kMax = 15;
  14. const auto was = (_previous > kMax);
  15. const auto now = (_current > kMax);
  16. if (was != now) {
  17. _isLimitExceeded = now;
  18. _limitExceeds.fire({});
  19. }
  20. }
  21. }
  22. int FieldCharsCountManager::count() const {
  23. return _current;
  24. }
  25. bool FieldCharsCountManager::isLimitExceeded() const {
  26. return _isLimitExceeded;
  27. }
  28. rpl::producer<> FieldCharsCountManager::limitExceeds() const {
  29. return _limitExceeds.events();
  30. }