@ -9,8 +9,8 @@ import PromiseKit
// • D o c u m e n t t h e e x p e c t e d c a s e s f o r e v e r y t h i n g .
// • E x p r e s s t h o s e c a s e s i n t e s t s .
@objc ( LKSession Protocol)
public final class Session Protocol : NSObject {
@objc ( LKSession Meta Protocol)
public final class Session Meta Protocol : NSObject {
internal static var storage : OWSPrimaryStorage { OWSPrimaryStorage . shared ( ) }
@ -58,15 +58,6 @@ public final class SessionProtocol : NSObject {
}
// MARK: N o t e t o S e l f
// B E H A V I O R N O T E : O W S M e s s a g e S e n d e r . s e n d M e s s a g e T o S e r v i c e : s e n d e r C e r t i f i c a t e : s u c c e s s : f a i l u r e : a b o r t s e a r l y a n d j u s t s e n d s
// a s y n c m e s s a g e i n s t e a d i f t h e m e s s a g e i t ' s s u p p o s e d t o s e n d i s c o n s i d e r e d a n o t e t o s e l f ( I N C L U D I N G l i n k e d d e v i c e s ) .
// B E H A V I O R N O T E : O W S M e s s a g e S e n d e r . s e n d M e s s a g e : a b o r t s e a r l y a n d d o e s n o t h i n g i f t h e m e s s a g e i s t a r g e t a t
// t h e c u r r e n t u s e r ( E X C L U D I N G l i n k e d d e v i c e s ) .
// B E H A V I O R N O T E : O W S M e s s a g e S e n d e r . h a n d l e M e s s a g e S e n t L o c a l l y : s u c c e s s : f a i l u r e : d o e s n ' t s e n d a s y n c t r a n s c r i p t i f t h e m e s s a g e
// t h a t w a s s e n t i s c o n s i d e r e d a n o t e t o s e l f ( I N C L U D I N G l i n k e d d e v i c e s ) b u t i t d o e s t h e n m a r k t h e m e s s a g e a s r e a d .
// TODO: C h e c k t h a t t h e b e h a v i o r s d e s c r i b e d a b o v e m a k e s e n s e
@objc ( isMessageNoteToSelf : )
public static func isMessageNoteToSelf ( _ thread : TSThread ) -> Bool {
guard let thread = thread as ? TSContactThread else { return false }
@ -77,23 +68,12 @@ public final class SessionProtocol : NSObject {
return isNoteToSelf
}
@objc ( isMessageNoteToSelf : inThread : )
public static func isMessageNoteToSelf ( _ message : TSOutgoingMessage , in thread : TSThread ) -> Bool {
guard let thread = thread as ? TSContactThread , ! ( message is OWSOutgoingSyncMessage ) && ! ( message is DeviceLinkMessage ) else { return false }
var isNoteToSelf = false
storage . dbReadConnection . read { transaction in
isNoteToSelf = LokiDatabaseUtilities . isUserLinkedDevice ( thread . contactIdentifier ( ) , transaction : transaction )
}
return isNoteToSelf
}
// MARK: T r a n s c r i p t s
@objc ( shouldSendTranscriptForMessage : in : )
public static func shouldSendTranscript ( for message : TSOutgoingMessage , in thread : TSThread ) -> Bool {
let isNoteToSelf = isMessageNoteToSelf ( message , in : thread )
let isOpenGroupMessage = ( thread as ? TSGroupThread ) ? . isPublicChat = = true
let wouldSignalRequireTranscript = ( AreRecipientUpdatesEnabled ( ) || ! message . hasSyncedTranscript )
return wouldSignalRequireTranscript && ! is NoteToSelf && ! is OpenGroupMessage && ! ( message is DeviceLinkMessage )
return wouldSignalRequireTranscript && ! isOpenGroupMessage
}
// MARK: T y p i n g I n d i c a t o r s
@ -101,43 +81,16 @@ public final class SessionProtocol : NSObject {
// / s e n d t h e m i f c e r t a i n c o n d i t i o n s a r e m e t .
@objc ( shouldSendTypingIndicatorForThread : )
public static func shouldSendTypingIndicator ( for thread : TSThread ) -> Bool {
return ! thread . isGroupThread ( ) && ! isMessageNoteToSelf ( thread )
return thread . friendRequestStatus = = . friends && ! thread . isGroupThread ( )
}
// MARK: R e c e i p t s
// U s e d f r o m O W S R e a d R e c e i p t M a n a g e r
@objc ( shouldSendReadReceiptForThread : )
public static func shouldSendReadReceipt ( for thread : TSThread ) -> Bool {
return ! isMessageNoteToSelf ( thread ) && ! thread . isGroupThread ( )
}
// TODO: N o t s u r e h o w t h e s e t w o r e l a t e
// E D I T : I t h i n k t h e o n e b e l o w i s u s e d t o b l o c k d e l i v e r y r e c e i p t s . T h a t m e a n s t h a t
// r i g h t n o w w e d o s e n d d e l i v e r y r e c e i p t s i n n o t e t o s e l f , b u t n o t r e a d r e c e i p t s . O t h e r t h a n t h a t t h e i r b e h a v i o r s h o u l d
// b e i d e n t i c a l . S h o u l d w e j u s t n o t s e n d a n y k i n d o f r e c e i p t i n n o t e t o s e l f ?
// U s e d f r o m O W S O u t g o i n g R e c e i p t M a n a g e r
@objc ( shouldSendReceiptForThread : )
public static func shouldSendReceipt ( for thread : TSThread ) -> Bool {
return thread . friendRequestStatus = = . friends && ! thread . isGroupThread ( )
}
// MARK: - R e c e i v i n g
// W h e n a m e s s a g e c o m e s i n , O W S M e s s a g e M a n a g e r d o e s t h i n g s i n t h i s o r d e r :
// 1 . C h e c k s i f t h e m e s s a g e i s a f r i e n d r e q u e s t f r o m b e f o r e r e s t o r a t i o n a n d i g n o r e s i t i f s o
// 2 . H a n d l e s f r i e n d r e q u e s t a c c e p t a n c e i f n e e d e d
// 3 . C h e c k s i f t h e m e s s a g e i s a d u p l i c a t e s y n c m e s s a g e a n d i g n o r e s i t i f s o
// 4 . H a n d l e s p r e k e y s i f n e e d e d ( t h i s a l s o m i g h t t r i g g e r a s e s s i o n r e s e t )
// 5 . U p d a t e s P 2 P i n f o i f t h e m e s s a g e i s a P 2 P a d d r e s s m e s s a g e
// 6 . H a n d l e d e v i c e l i n k i n g r e q u e s t s o r a u t h o r i z a t i o n s i f n e e d e d ( i t n o w d o e s n ' t c o n t i n u e a l o n g t h e n o r m a l m e s s a g e h a n d l i n g p a t h )
// - I f t h e m e s s a g e i s a d a t a m e s s a g e a n d h a s t h e s e s s i o n r e q u e s t f l a g s e t , p r o c e s s i n g s t o p s h e r e
// - I f t h e m e s s a g e i s a d a t a m e s s a g e a n d h a s t h e s e s s i o n r e s t o r e f l a g s e t , p r o c e s s i n g s t o p s h e r e
// 7 . I f t h e m e s s a g e g o t t o t h i s p o i n t , a n d i t h a s a n u p d a t e d p r o f i l e k e y a t t a c h e d , i t ' l l n o w h a n d l e t h e p r o f i l e k e y
// - I f t h e m e s s a g e i s a c l o s e d g r o u p m e s s a g e , i t ' l l n o w c h e c k i f i t n e e d s t o b e i g n o r e d
// . . .
// MARK: - D e c r y p t i o n
@objc ( shouldSkipMessageDecryptResult : )
public static func shouldSkipMessageDecryptResult ( _ result : OWSMessageDecryptResult ) -> Bool {
// C a l l e d f r o m O W S M e s s a g e R e c e i v e r t o p r e v e n t m e s s a g e s f r o m e v e n b e i n g a d d e d t o t h e p r o c e s s i n g q u e u e