// // Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "TSYapDatabaseObject.h" NS_ASSUME_NONNULL_BEGIN @class TSInteraction; @class TSInvalidIdentityKeyReceivingErrorMessage; /** * TSThread is the superclass of TSContactThread and TSGroupThread */ @interface TSThread : TSYapDatabaseObject // YES IFF this thread has ever had a message. @property (nonatomic) BOOL hasEverHadMessage; /** * Whether the object is a group thread or not. * * @return YES if is a group thread, NO otherwise. */ - (BOOL)isGroupThread; /** * Returns the name of the thread. * * @return The name of the thread. */ - (NSString *)name; /** * @returns * Signal Id (e164) of the contact if it's a contact thread. */ - (nullable NSString *)contactIdentifier; /** * @returns recipientId for each recipient in the thread */ @property (nonatomic, readonly) NSArray *recipientIdentifiers; #if TARGET_OS_IOS /** * Returns the image representing the thread. Nil if not available. * * @return UIImage of the thread, or nil. */ - (nullable UIImage *)image; #endif #pragma mark Interactions /** * @return The number of interactions in this thread. */ - (NSUInteger)numberOfInteractions; /** * Get all messages in the thread we weren't able to decrypt */ - (NSArray *)receivedMessagesForInvalidKey:(NSData *)key; - (NSUInteger)unreadMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction NS_SWIFT_NAME(unreadMessageCount(transaction:)); - (BOOL)hasSafetyNumbers; - (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; /** * Returns the latest date of a message in the thread or the thread creation date if there are no messages in that *thread. * * @return The date of the last message or thread creation date. */ - (NSDate *)lastMessageDate; /** * Returns the string that will be displayed typically in a conversations view as a preview of the last message *received in this thread. * * @return Thread preview string. */ - (NSString *)lastMessageTextWithTransaction:(YapDatabaseReadTransaction *)transaction NS_SWIFT_NAME(lastMessageText(transaction:)); /** * Updates the thread's caches of the latest interaction. * * @param lastMessage Latest Interaction to take into consideration. * @param transaction Database transaction. */ - (void)updateWithLastMessage:(TSInteraction *)lastMessage transaction:(YapDatabaseReadWriteTransaction *)transaction; #pragma mark Archival /** * Returns the last date at which a string was archived or nil if the thread was never archived or brought back to the *inbox. * * @return Last archival date. */ - (nullable NSDate *)archivalDate; /** * Archives a thread with the current date. * * @param transaction Database transaction. */ - (void)archiveThreadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; /** * Archives a thread with the reference date. This is currently only used for migrating older data that has already * been archived. * * @param transaction Database transaction. * @param date Date at which the thread was archived. */ - (void)archiveThreadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction referenceDate:(NSDate *)date; /** * Unarchives a thread that was archived previously. * * @param transaction Database transaction. */ - (void)unarchiveThreadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)removeAllThreadInteractionsWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; #pragma mark Drafts /** * Returns the last known draft for that thread. Always returns a string. Empty string if nil. * * @param transaction Database transaction. * * @return Last known draft for that thread. */ - (NSString *)currentDraftWithTransaction:(YapDatabaseReadTransaction *)transaction; /** * Sets the draft of a thread. Typically called when leaving a conversation view. * * @param draftString Draft string to be saved. * @param transaction Database transaction. */ - (void)setDraft:(NSString *)draftString transaction:(YapDatabaseReadWriteTransaction *)transaction; @property (atomic, readonly) BOOL isMuted; @property (atomic, readonly, nullable) NSDate *mutedUntilDate; #pragma mark - Update With... Methods - (void)updateWithMutedUntilDate:(NSDate *)mutedUntilDate; @end NS_ASSUME_NONNULL_END