BaseMessage+Accessibility.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2016-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "BaseMessage+Accessibility.h"
  21. #import "Conversation.h"
  22. #import "Contact.h"
  23. #import "BundleUtil.h"
  24. #import "ThreemaFramework/ThreemaFramework-swift.h"
  25. @implementation BaseMessage (AccessibilityUtil)
  26. - (NSString *)accessibilityMessageSender {
  27. NSString *senderText;
  28. if (self.isOwn.boolValue) {
  29. senderText = [BundleUtil localizedStringForKey:@"me"];
  30. } else if ([self.conversation isGroup]) {
  31. if (self.sender != nil) {
  32. senderText = self.sender.displayName;
  33. }
  34. } else {
  35. senderText = self.conversation.displayName;
  36. }
  37. return senderText;
  38. }
  39. - (NSString *)accessibilityMessageShortStatus {
  40. NSString *status = @"";
  41. if ([self.conversation isGroup]) {
  42. return status;
  43. }
  44. switch (self.messageState) {
  45. case MESSAGE_STATE_USER_ACK:
  46. status = [BundleUtil localizedStringForKey:@"status_acknowledged"];
  47. break;
  48. case MESSAGE_STATE_USER_DECLINED:
  49. status = [BundleUtil localizedStringForKey:@"status_declined"];
  50. break;
  51. case MESSAGE_STATE_FAILED:
  52. status = [BundleUtil localizedStringForKey:@"status_failed"];
  53. break;
  54. case MESSAGE_STATE_READ:
  55. status = [BundleUtil localizedStringForKey:@"status_read"];
  56. break;
  57. case MESSAGE_STATE_SENT:
  58. status = [BundleUtil localizedStringForKey:@"status_sent"];
  59. break;
  60. case MESSAGE_STATE_SENDING:
  61. status = [BundleUtil localizedStringForKey:@"status_sending"];
  62. break;
  63. case MESSAGE_STATE_DELIVERED:
  64. status = [BundleUtil localizedStringForKey:@"status_delivered"];
  65. break;
  66. default:
  67. break;
  68. }
  69. return status;
  70. }
  71. - (NSString *)accessibilityMessageStatus {
  72. NSString *status = @"";
  73. if ([self.conversation isGroup]) {
  74. return status;
  75. }
  76. switch (self.messageState) {
  77. case MESSAGE_STATE_SENDING:
  78. status = [BundleUtil localizedStringForKey:@"status_sending"];
  79. break;
  80. case MESSAGE_STATE_SENT:
  81. status = [BundleUtil localizedStringForKey:@"status_sent"];
  82. break;
  83. case MESSAGE_STATE_DELIVERED:
  84. status = [BundleUtil localizedStringForKey:@"status_delivered"];
  85. break;
  86. case MESSAGE_STATE_READ:
  87. status = [BundleUtil localizedStringForKey:@"status_read"];
  88. break;
  89. case MESSAGE_STATE_USER_ACK:
  90. status = [BundleUtil localizedStringForKey:@"status_acknowledged"];
  91. break;
  92. case MESSAGE_STATE_USER_DECLINED:
  93. status = [BundleUtil localizedStringForKey:@"status_declined"];
  94. break;
  95. case MESSAGE_STATE_FAILED:
  96. status = [BundleUtil localizedStringForKey:@"status_failed"];
  97. break;
  98. default:
  99. break;
  100. }
  101. return status;
  102. }
  103. - (NSString *)accessibilityMessageDate {
  104. NSDate *date = [self dateForCurrentState];
  105. if (date != nil) {
  106. return [DateFormatter accessibilityRelativeDayTime:date];
  107. }
  108. return nil;
  109. }
  110. @end