123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- // _____ _
- // |_ _| |_ _ _ ___ ___ _ __ __ _
- // | | | ' \| '_/ -_) -_) ' \/ _` |_
- // |_| |_||_|_| \___\___|_|_|_\__,_(_)
- //
- // Threema iOS Client
- // Copyright (c) 2012-2020 Threema GmbH
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU Affero General Public License, version 3,
- // as published by the Free Software Foundation.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU Affero General Public License for more details.
- //
- // You should have received a copy of the GNU Affero General Public License
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
- #import "BaseMessage.h"
- #import "Conversation.h"
- @implementation BaseMessage
- @dynamic date;
- @dynamic id;
- @dynamic delivered;
- @dynamic isOwn;
- @dynamic read;
- @dynamic sent;
- @dynamic userack;
- @dynamic userackDate;
- @dynamic deliveryDate;
- @dynamic readDate;
- @dynamic remoteSentDate;
- @dynamic sendFailed;
- @dynamic conversation;
- @dynamic sender;
- @dynamic webRequestId;
- @dynamic flags;
- - (NSString*)logText {
- return nil;
- }
- - (NSString*)previewText {
- return @"";
- }
- - (NSString*)quotePreviewText {
- return self.previewText;
- }
- - (BOOL)wasDeleted {
- return self.managedObjectContext == nil;
- }
- // for backwards compatibility of message created before ThreemaDataV19
- - (NSDate *)remoteSentDate {
- NSDate *date = [self primitiveValueForKey:@"remoteSentDate"];
- if (date == nil) {
- date = [self primitiveValueForKey:@"date"];
- }
-
- return date;
- }
- - (MessageState)messageState {
- if (self.isOwn.boolValue) {
- if (self.userackDate) {
- if (self.userack.boolValue) {
- return MESSAGE_STATE_USER_ACK;
- } else {
- return MESSAGE_STATE_USER_DECLINED;
- }
- } else if (self.sendFailed.boolValue) {
- return MESSAGE_STATE_FAILED;
- } else if (self.read.boolValue) {
- return MESSAGE_STATE_READ;
- } else if (self.delivered.boolValue) {
- return MESSAGE_STATE_DELIVERED;
- } else if (self.sent.boolValue) {
- return MESSAGE_STATE_SENT;
- } else {
- return MESSAGE_STATE_SENDING;
- }
- } else {
- if (self.userackDate) {
- if (self.userack.boolValue) {
- return MESSAGE_STATE_USER_ACK;
- } else {
- return MESSAGE_STATE_USER_DECLINED;
- }
- } else {
- return MESSAGE_STATE_SENT;
- }
- }
- }
- - (NSDate *)dateForCurrentState {
- NSDate *date = nil;
-
- if (!self.isOwn.boolValue) {
- date = self.remoteSentDate;
- if (self.userackDate != nil) {
- date = self.userackDate;
- }
- } else {
- /* sent self - timestamp depends on status */
- if (self.conversation.groupId != nil) {
- /* Group messages don't really have a read date, but the UI may have set one for the new message line */
- date = self.date;
- } else {
- if (self.userackDate != nil) {
- date = self.userackDate;
- } else if (self.read.boolValue) {
- date = self.readDate;
- } else if (self.delivered.boolValue) {
- date = self.deliveryDate;
- } else if (self.sent.boolValue) {
- date = self.date;
- }
- }
- }
-
- return date;
- }
- - (BOOL)noDeliveryReceiptFlagSet {
- if (self.flags != nil) {
- if ([self.flags integerValue] & BaseMessageFlagsNoDeliveryReceipt) {
- return true;
- }
- }
- return false;
- }
- @end
|