h0kzdbvj commited on
Commit
8a6ddd2
·
1 Parent(s): e9bce6a

Improve virtual phone number generation and link communication apps

Browse files

Update virtual SIM provisioning to use a more robust number generation scheme and synchronize phone and messaging app identities.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 90a58ebe-9d8a-4efa-8f4a-d7ae87fb7468
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: f6a2cdd2-ad6a-493e-adbd-abcce6f2c81a
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/991703d2-f25a-4c3e-9f3d-fe8e89b62026/90a58ebe-9d8a-4efa-8f4a-d7ae87fb7468/6wnH8kV
Replit-Helium-Checkpoint-Created: true

Files changed (2) hide show
  1. communication_sync.md +14 -0
  2. routes.py +7 -3
communication_sync.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Phone and Messages Synchronization
2
+
3
+ The Phone and Messages apps have been unified to use a single virtual phone number per user.
4
+
5
+ ## Synchronization Logic
6
+ - **Single Source of Truth**: The `lun_numbers` table is now the primary source for a user's phone identity.
7
+ - **Bi-directional Linking**:
8
+ - If a user creates a number in the **Phone** app, it is automatically assigned to their primary **Virtual SIM** used by Messages.
9
+ - If a user provisions a **Virtual SIM** in the **Messages** app, it automatically creates the corresponding **LunNumber** record for the Phone app.
10
+ - **Persistence**: Numbers are tied to the `user_id`, ensuring they remain identical across logins and across all communication apps.
11
+
12
+ ## Database Tables
13
+ - `lun_numbers`: Stores the official identity number for the user.
14
+ - `virtual_sims`: Stores the SIM card details, with the `lun_number` field synchronized to the `lun_numbers` table.
routes.py CHANGED
@@ -5897,12 +5897,16 @@ def create_virtual_sim():
5897
  sim_id = f"lunsim_{random.randint(10000, 99999)}"
5898
 
5899
  # If a Lun number exists, use it for the primary SIM
5900
- if lun_num_record and existing_count == 0:
5901
  lun_number = lun_num_record.lun_number
5902
  else:
5903
- lun_number = f"700{random.randint(1000000, 9999999)}"
 
 
 
5904
  while VirtualSIM.query.filter_by(lun_number=lun_number).first() or LunNumber.query.filter_by(lun_number=lun_number).first():
5905
- lun_number = f"700{random.randint(1000000, 9999999)}"
 
5906
 
5907
  is_primary = existing_count == 0
5908
 
 
5897
  sim_id = f"lunsim_{random.randint(10000, 99999)}"
5898
 
5899
  # If a Lun number exists, use it for the primary SIM
5900
+ if lun_num_record:
5901
  lun_number = lun_num_record.lun_number
5902
  else:
5903
+ prefix = '7001'
5904
+ suffix = ''.join([str(secrets.randbelow(10)) for _ in range(6)])
5905
+ lun_number = f"{prefix}{suffix}"
5906
+
5907
  while VirtualSIM.query.filter_by(lun_number=lun_number).first() or LunNumber.query.filter_by(lun_number=lun_number).first():
5908
+ suffix = ''.join([str(secrets.randbelow(10)) for _ in range(6)])
5909
+ lun_number = f"{prefix}{suffix}"
5910
 
5911
  is_primary = existing_count == 0
5912