| 
									
										
										
										
											2022-12-06 09:31:44 -08:00
										 |  |  | // Copyright 2022 Signal Messenger, LLC
 | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import type { ConversationAttributesType } from '../model-types'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import * as log from '../logging/log'; | 
					
						
							|  |  |  | import { blockSendUntilConversationsAreVerified } from './blockSendUntilConversationsAreVerified'; | 
					
						
							| 
									
										
										
										
											2022-12-08 02:43:48 -05:00
										 |  |  | import { getRecipientsByConversation } from './getRecipientsByConversation'; | 
					
						
							| 
									
										
										
										
											2022-12-06 09:31:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-05 17:34:51 -07:00
										 |  |  | import type { SafetyNumberChangeSource } from '../components/SafetyNumberChangeDialog'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-06 09:31:44 -08:00
										 |  |  | export async function isCallSafe( | 
					
						
							| 
									
										
										
										
											2023-09-05 17:34:51 -07:00
										 |  |  |   attributes: ConversationAttributesType, | 
					
						
							|  |  |  |   source: SafetyNumberChangeSource | 
					
						
							| 
									
										
										
										
											2022-12-06 09:31:44 -08:00
										 |  |  | ): Promise<boolean> { | 
					
						
							| 
									
										
										
										
											2022-12-08 02:43:48 -05:00
										 |  |  |   const recipientsByConversation = getRecipientsByConversation([attributes]); | 
					
						
							| 
									
										
										
										
											2022-12-06 09:31:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const callAnyway = await blockSendUntilConversationsAreVerified( | 
					
						
							|  |  |  |     recipientsByConversation, | 
					
						
							| 
									
										
										
										
											2023-09-05 17:34:51 -07:00
										 |  |  |     source | 
					
						
							| 
									
										
										
										
											2022-12-06 09:31:44 -08:00
										 |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!callAnyway) { | 
					
						
							|  |  |  |     log.info('Safety number change dialog not accepted, new call not allowed.'); | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } |