@ -82,23 +82,30 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
( result = = . success || result = = . legacySuccess ) ,
let data : Data = maybeData
else {
switch result {
switch ( result , metadata . namespace . isConfigNamespace ) {
// I f w e g o t a n e x p l i c i t f a i l u r e , o r w e g o t a s u c c e s s b u t n o c o n t e n t t h e n s h o w
// t h e f a l l b a c k n o t i f i c a t i o n
case .success , . legacySuccess , . failure :
case ( .success , false ) , ( . legacySuccess , false ) , ( . failure , false ) :
return self . handleFailure (
for : notificationContent ,
metadata : metadata ,
threadVariant : nil ,
threadDisplayName : nil ,
resolution : . errorProcessing ( result ) ,
runId : runId
)
case ( . success , _ ) , ( . legacySuccess , _ ) , ( . failure , _ ) :
return self . completeSilenty ( . errorProcessing ( result ) , runId : runId )
// J u s t l o g i f t h e n o t i f i c a t i o n w a s t o o l o n g ( a ~ 2 k m e s s a g e s h o u l d b e a b l e t o f i t s o
// t h e s e w i l l m o s t c o m m o n l y b e c a l l o r c o n f i g m e s s a g e s )
case . successTooLong : return self . completeSilenty ( . ignoreDueToContentSize ( metadata ) , runId : runId )
case . failureNoContent : return self . completeSilenty ( . errorNoContent ( metadata ) , runId : runId )
case . legacyFailure : return self . completeSilenty ( . errorNoContentLegacy , runId : runId )
case . legacyForceSilent :
case ( . successTooLong , _ ) :
return self . completeSilenty ( . ignoreDueToContentSize ( metadata ) , runId : runId )
case ( . failureNoContent , _ ) : return self . completeSilenty ( . errorNoContent ( metadata ) , runId : runId )
case ( . legacyFailure , _ ) : return self . completeSilenty ( . errorNoContentLegacy , runId : runId )
case ( . legacyForceSilent , _ ) :
return self . completeSilenty ( . ignoreDueToNonLegacyGroupLegacyNotification , runId : runId )
}
}
@ -119,6 +126,9 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
// w h e r e t h e c o m p l e t e S i l e n t y ( ) i s c a l l e d b e f o r e t h e l o c a l n o t i f i c a t i o n r e q u e s t
// i s a d d e d t o n o t i f i c a t i o n c e n t e r
dependencies [ singleton : . storage ] . write { [ weak self , dependencies ] db in
var processedThreadVariant : SessionThread . Variant ?
var threadDisplayName : String ?
do {
let processedMessage : ProcessedMessage = try Message . processRawReceivedMessageAsNotification (
db ,
@ -148,6 +158,8 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
// / D u e t o t h e w a y t h e ` C a l l M e s s a g e ` w o r k s w e n e e d t o c u s t o m h a n d l e i t ' s b e h a v i o u r w i t h i n t h e n o t i f i c a t i o n
// / e x t e n s i o n , f o r a l l o t h e r m e s s a g e t y p e s w e w a n t t o j u s t u s e t h e s t a n d a r d ` M e s s a g e R e c e i v e r . h a n d l e ` c a l l
case . standard ( let threadId , let threadVariant , _ , let messageInfo ) where messageInfo . message is CallMessage :
processedThreadVariant = threadVariant
guard let callMessage = messageInfo . message as ? CallMessage else {
throw MessageReceiverError . ignorableMessage
}
@ -241,6 +253,32 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
)
case . standard ( let threadId , let threadVariant , let proto , let messageInfo ) :
processedThreadVariant = threadVariant
threadDisplayName = SessionThread . displayName (
threadId : threadId ,
variant : threadVariant ,
closedGroupName : ( threadVariant != . group && threadVariant != . legacyGroup ? nil :
try ? ClosedGroup
. select ( . name )
. filter ( id : threadId )
. asRequest ( of : String . self )
. fetchOne ( db )
) ,
openGroupName : ( threadVariant != . community ? nil :
try ? OpenGroup
. select ( . name )
. filter ( id : threadId )
. asRequest ( of : String . self )
. fetchOne ( db )
) ,
isNoteToSelf : ( threadId = = dependencies [ cache : . general ] . sessionId . hexString ) ,
profile : ( threadVariant != . contact ? nil :
try ? Profile
. filter ( id : threadId )
. fetchOne ( db )
)
)
try MessageReceiver . handle (
db ,
threadId : threadId ,
@ -288,6 +326,8 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
self ? . handleFailure (
for : notificationContent ,
metadata : metadata ,
threadVariant : processedThreadVariant ,
threadDisplayName : threadDisplayName ,
resolution : . errorMessageHandling ( msgError ) ,
runId : runId
)
@ -296,6 +336,8 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
self ? . handleFailure (
for : notificationContent ,
metadata : metadata ,
threadVariant : processedThreadVariant ,
threadDisplayName : threadDisplayName ,
resolution : . errorOther ( error ) ,
runId : runId
)
@ -492,6 +534,8 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
private func handleFailure (
for content : UNMutableNotificationContent ,
metadata : PushNotificationAPI . NotificationMetadata ,
threadVariant : SessionThread . Variant ? ,
threadDisplayName : String ? ,
resolution : NotificationResolution ,
runId : String
) {
@ -504,11 +548,27 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
}
content . title = Constants . app_name
content . body = " messageNewYouveGot "
. putNumber ( 1 )
. localized ( )
let userInfo : [ String : Any ] = [ NotificationServiceExtension . isFromRemoteKey : true ]
content . userInfo = userInfo
content . userInfo = [ NotificationServiceExtension . isFromRemoteKey : true ]
// / I f i t ' s a n o t i f i c a t i o n f o r a g r o u p c o n v e r s a t i o n , t h e n o t i f i c a t i o n p r e f e r e n c e s a r e r i g h t a n d w e h a v e a n a m e f o r t h e g r o u p
// / t h e n w e s h o u l d i n c l u d e i t i n t h e n o t i f i c a t i o n c o n t e n t
let previewType : Preferences . NotificationPreviewType = dependencies [ singleton : . storage , key : . preferencesNotificationPreviewType ]
. defaulting ( to : . nameAndPreview )
switch ( threadVariant , previewType , threadDisplayName ) {
case ( . group , . nameAndPreview , . some ( let name ) ) , ( . group , . nameNoPreview , . some ( let name ) ) ,
( . legacyGroup , . nameAndPreview , . some ( let name ) ) , ( . legacyGroup , . nameNoPreview , . some ( let name ) ) :
content . body = " messageNewYouveGotGroup "
. putNumber ( 1 )
. put ( key : " group_name " , value : name )
. localized ( )
default :
content . body = " messageNewYouveGot "
. putNumber ( 1 )
. localized ( )
}
contentHandler ! ( content )
hasCompleted = true
}