Skip to content

Refactor unique-phones SIM tray and active-phone reachability - #82

Open
Im-Kayun wants to merge 5 commits into
Samuels-Development:mainfrom
Im-Kayun:refactor/unique-phones-sim-tray
Open

Refactor unique-phones SIM tray and active-phone reachability#82
Im-Kayun wants to merge 5 commits into
Samuels-Development:mainfrom
Im-Kayun:refactor/unique-phones-sim-tray

Conversation

@Im-Kayun

@Im-Kayun Im-Kayun commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Hardens unique phones so the phone you open is the only live line, and with ox tray mode using the phone opens the UI instead of the SIM container.

Root cause / design. With UseContainers = true, ox_inventory treats metadata.container as a nested inventory and intercepts USE before sd-phone exports, so players opened the SIM tray instead of the phone. The "active" phone also lived only in memory (prefs in session), so reconnects/restarts forgot which device you were acting as. Live traffic (calls, SMS banners, notifications) could still reach pocketed SIMs via getAnySourceByIdentifier / pocket-buzz banners.

(a) SIM tray UX (ox only). Drop nested phone containers. Each device gets a 1-slot stash sd_phone_sim_<deviceId>. USE always runs sd-phone.usePhone (opens UI + marks active). Inventory button "SIM Tray" calls openSimTray. Legacy nested containers migrate onto the stash on resolve/tray open. Item defs live in docs/ox_inventory_items.lua — SECTION A (tray button) when UseContainers = true, SECTION B when false; ox cannot toggle buttons at runtime. Blank sim_card wires client/server exports so first USE activates a number, then tray-insert (A) or use-again install (B).

(b) Active device persistence. Last-opened device is stored in phone_player_equipment and restored on session resolve (session.setActive / ensurePref). Phone metadata helpers getDevice / setPhoneDevice (deviceId, deviceOwner) back device identity so resolve no longer hits nil on missing getters.

(c) Active-phone-only reachability. Dial/payphone/LB-compat resolve with getSourceByIdentifier only. getAnySourceByIdentifier is an alias of the active resolver under unique phones. Incoming no longer auto-switches to the dialed pocketed phone. notifications.notifyCid is silent unless that identity is active (pocket buzz removed). Messages still persist for pocketed identities but skip live thread push / banner until that phone is equipped. README documents the new behaviour.

(d) Docs + defaults. configs/ox_inventory_items.luadocs/ (reference only, not loaded). Upstream defaults stay Enabled = false / UseContainers = false so opt-in servers are unchanged until they flip the flags and copy the matching item defs.

Type of Change

  • Bug Fix
  • New Feature
  • Improvement / Refactor
  • Performance
  • Documentation
  • Compatibility
  • Other

Related Issues

n/a (unique-phones tray + active-phone reachability)

Testing

  • Enable unique phones + UseContainers = true with SECTION A ox defs: USE phone opens UI; SIM Tray opens stash; blank SIM activates then inserts; eject by dragging out.

  • Metadata mode (UseContainers = false, SECTION B): use sim_card to install; eject from Settings → SIM & Backup.

  • Two phones on one character: call/SMS/notif to the pocketed number is unavailable/silent; open that phone → traffic works; stored SMS catch up on open.

  • Restart / relog: last-opened device remains active.

  • Defaults on a fresh config remain off (no behaviour change for servers that never enable unique phones).

  • Tested locally

  • Tested with latest sd-phone

  • Tested with latest ox_lib

  • Tested with latest ox_inventory

  • Multiplayer tested

Breaking Changes

Behavioural (only when unique phones are enabled): pocketed numbers are no longer reachable for live calls/SMS banners/notifications — previously any carried SIM rang/buzzed. Data is still stored and surfaces when that phone is opened. Servers that relied on multi-phone simultaneous reachability need to treat the last-opened phone as the only live line.

ox item defs: tray mode requires SECTION A (SIM Tray button) in ox_inventory; nested container metadata on phones is obsolete and migrates on first resolve. Copy from docs/ox_inventory_items.lua.

No schema change for servers with unique phones already off. With unique phones on, phone_player_equipment is created/used for active-device persistence.

Checklist

  • My code follows the existing style of the project.
  • I have tested my changes.
  • I have updated any necessary documentation.
  • I have removed any debug code.
  • This PR does not include unrelated changes.
  • I have verified this works on the latest version of sd-phone.

Im-Kayun added 5 commits July 22, 2026 17:35
Replace ox nested containers (use opened the tray) with per-device stashes so using a phone opens the UI and an inventory SIM Tray button swaps cards. Persist last-opened device in phone_player_equipment, add getDevice/setPhoneDevice metadata helpers, and wire ox client/server exports for phone and SIM activation.
Pocketed SIMs stay unreachable and silent until equipped (ng-phone style), while stored data still catches up on next open.
Keeps reference copy-paste defs out of configs and leaves room for future docs.
Restore Enabled/UseContainers and phone_black so local test toggles are not shipped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant