| … | … | @@ -64,6 +64,65 @@ export class Router { |
| 64 | 64 | case 'raw': return this._raw(params) |
| 65 | 65 | case 'status': return this._status() |
| 66 | 66 | case 'shutdown': return this._shutdown() |
| 67 | |
| 68 | // --- Introspection --- |
| 69 | case 'introspect': return this._introspect(params) |
| 70 | |
| 71 | // --- Identity & Username --- |
| 72 | case 'identity.confirm': return this._identityConfirm() |
| 73 | case 'identity.store': return this._identityStore(params) |
| 74 | case 'identity.register': return this._identityRegister(params) |
| 75 | case 'identity.checkName': return this._identityCheckName(params) |
| 76 | case 'identity.lookup': return this._identityLookup(params) |
| 77 | case 'identity.lookupMember': return this._identityLookupMember(params) |
| 78 | |
| 79 | // --- Room Config & Management --- |
| 80 | case 'room.config': return this._roomConfig(params) |
| 81 | case 'room.config.set': return this._roomConfigSet(params) |
| 82 | case 'room.bookmark': return this._roomBookmark(params) |
| 83 | case 'room.unbookmark': return this._roomUnbookmark(params) |
| 84 | case 'room.preferences': return this._roomPreferences(params) |
| 85 | case 'room.preferences.set': return this._roomPreferencesSet(params) |
| 86 | case 'room.search': return this._roomSearch(params) |
| 87 | case 'room.unread': return this._roomUnread(params) |
| 88 | |
| 89 | // --- DM Management --- |
| 90 | case 'dm.list': return this._dmList() |
| 91 | case 'dm.requests': return this._dmRequests(params) |
| 92 | case 'dm.accept': return this._dmAccept(params) |
| 93 | case 'dm.reject': return this._dmReject(params) |
| 94 | |
| 95 | // --- File Management --- |
| 96 | case 'file.send': return this._fileSend(params) |
| 97 | case 'file.list': return this._fileList(params) |
| 98 | case 'file.info': return this._fileInfo(params) |
| 99 | case 'file.download': return this._fileDownload(params) |
| 100 | case 'file.cancel': return this._fileCancel(params) |
| 101 | case 'file.remove': return this._fileRemove(params) |
| 102 | case 'file.clear': return this._fileClear(params) |
| 103 | |
| 104 | // --- Advanced Members --- |
| 105 | case 'members.active': return this._membersActive(params) |
| 106 | case 'members.mods': return this._membersMods(params) |
| 107 | case 'members.count': return this._membersCount(params) |
| 108 | case 'members.connected': return this._membersConnected(params) |
| 109 | case 'members.search': return this._membersSearch(params) |
| 110 | |
| 111 | // --- Contacts --- |
| 112 | case 'contact.info': return this._contactInfo(params) |
| 113 | case 'contact.self': return this._contactSelf() |
| 114 | case 'dm.fromContact': return this._dmFromContact(params) |
| 115 | |
| 116 | // --- Sub-APIs --- |
| 117 | case 'network': return this._networkQuery() |
| 118 | case 'preferences': return this._preferencesQuery() |
| 119 | case 'preferences.set': return this._preferencesSet(params) |
| 120 | case 'debug.stats': return this._debugStats(params) |
| 121 | |
| 122 | // --- System --- |
| 123 | case 'version': return this._getVersion() |
| 124 | case 'stats': return this._getStats() |
| 125 | |
| 67 | 126 | default: throw new Error(`Unknown method: ${method}`) |
| 68 | 127 | } |
| 69 | 128 | } |
| … | … | @@ -511,4 +570,266 @@ export class Router { |
| 511 | 570 | }, 500) |
| 512 | 571 | return { ok: true, message: 'shutting down' } |
| 513 | 572 | } |
| 573 | |
| 574 | // --- Introspection --- |
| 575 | |
| 576 | async _introspect (params) { |
| 577 | const target = params.api || 'core' |
| 578 | const api = target === 'core' ? this.backend.api.core |
| 579 | : target === 'call' ? this.backend.api.call |
| 580 | : target === 'preferences' ? this.backend.api.preferences |
| 581 | : target === 'network' ? this.backend.api.network |
| 582 | : target === 'debug' ? this.backend.api.debug |
| 583 | : null |
| 584 | if (!api) throw new Error(`Unknown API: ${target}`) |
| 585 | const methods = [] |
| 586 | for (const key of Object.getOwnPropertyNames(Object.getPrototypeOf(api))) { |
| 587 | if (key === 'constructor') continue |
| 588 | if (typeof api[key] === 'function') methods.push(key) |
| 589 | } |
| 590 | for (const key of Object.keys(api)) { |
| 591 | if (typeof api[key] === 'function' && !methods.includes(key)) methods.push(key) |
| 592 | } |
| 593 | return { api: target, methods: methods.sort(), count: methods.length } |
| 594 | } |
| 595 | |
| 596 | // --- Identity & Username --- |
| 597 | |
| 598 | async _identityConfirm () { |
| 599 | await this.backend.api.core.confirmRecoveryPhrase() |
| 600 | return { ok: true } |
| 601 | } |
| 602 | |
| 603 | async _identityStore (params) { |
| 604 | if (!params.phrase) throw new Error('Missing required param: phrase') |
| 605 | await this.backend.api.core.storeRecoveryPhrase(params.phrase) |
| 606 | return { ok: true } |
| 607 | } |
| 608 | |
| 609 | async _identityRegister (params) { |
| 610 | if (!params.username) throw new Error('Missing required param: username') |
| 611 | const result = await this.backend.api.core.registerUsername(params.username) |
| 612 | return { ok: true, result } |
| 613 | } |
| 614 | |
| 615 | async _identityCheckName (params) { |
| 616 | if (!params.username) throw new Error('Missing required param: username') |
| 617 | const available = await this.backend.api.core.checkUsername(params.username) |
| 618 | return { username: params.username, available } |
| 619 | } |
| 620 | |
| 621 | async _identityLookup (params) { |
| 622 | if (!params.username) throw new Error('Missing required param: username') |
| 623 | return this.backend.api.core.lookupUsername(params.username) |
| 624 | } |
| 625 | |
| 626 | async _identityLookupMember (params) { |
| 627 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 628 | if (!params.memberId) throw new Error('Missing required param: memberId') |
| 629 | return this.backend.api.core.lookupUserByMemberId(params.roomId, params.memberId) |
| 630 | } |
| 631 | |
| 632 | // --- Room Config & Management --- |
| 633 | |
| 634 | async _roomConfig (params) { |
| 635 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 636 | return this.backend.api.core.getConfig(params.roomId) |
| 637 | } |
| 638 | |
| 639 | async _roomConfigSet (params) { |
| 640 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 641 | if (!params.key) throw new Error('Missing required param: key') |
| 642 | if (params.value === undefined) throw new Error('Missing required param: value') |
| 643 | await this.backend.api.core.updateConfig(params.roomId, params.key, params.value) |
| 644 | return { ok: true } |
| 645 | } |
| 646 | |
| 647 | async _roomBookmark (params) { |
| 648 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 649 | await this.backend.api.core.bookmark(params.roomId) |
| 650 | return { ok: true } |
| 651 | } |
| 652 | |
| 653 | async _roomUnbookmark (params) { |
| 654 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 655 | await this.backend.api.core.unbookmark(params.roomId) |
| 656 | return { ok: true } |
| 657 | } |
| 658 | |
| 659 | async _roomPreferences (params) { |
| 660 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 661 | return this.backend.api.core.getRoomPreferences(params.roomId) |
| 662 | } |
| 663 | |
| 664 | async _roomPreferencesSet (params) { |
| 665 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 666 | const { roomId, ...prefs } = params |
| 667 | await this.backend.api.core.updateRoomPreferences(roomId, prefs) |
| 668 | return { ok: true } |
| 669 | } |
| 670 | |
| 671 | async _roomSearch (params) { |
| 672 | if (!params.query) throw new Error('Missing required param: query') |
| 673 | return this.backend.api.core.searchRooms(params.query) |
| 674 | } |
| 675 | |
| 676 | async _roomUnread (params) { |
| 677 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 678 | if (params.unread === undefined) throw new Error('Missing required param: unread') |
| 679 | await this.backend.api.core.setRoomUnread(params.roomId, params.unread) |
| 680 | return { ok: true } |
| 681 | } |
| 682 | |
| 683 | // --- DM Management --- |
| 684 | |
| 685 | async _dmList () { |
| 686 | // No getDmList — use getDmRequestsByStatus(1) for accepted DMs |
| 687 | return this.backend.api.core.getDmRequestsByStatus(1) |
| 688 | } |
| 689 | |
| 690 | async _dmRequests (params) { |
| 691 | const status = params.status || 3 // default: pending |
| 692 | return this.backend.api.core.getDmRequestsByStatus(status) |
| 693 | } |
| 694 | |
| 695 | async _dmAccept (params) { |
| 696 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 697 | await this.backend.api.core.acceptDmRequest(params.roomId) |
| 698 | return { ok: true } |
| 699 | } |
| 700 | |
| 701 | async _dmReject (params) { |
| 702 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 703 | await this.backend.api.core.rejectDmRequest(params.roomId) |
| 704 | return { ok: true } |
| 705 | } |
| 706 | |
| 707 | // --- File Management --- |
| 708 | |
| 709 | async _fileSend (params) { |
| 710 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 711 | if (!params.file) throw new Error('Missing required param: file') |
| 712 | return this.backend.api.core.sendFile(params.roomId, params.file) |
| 713 | } |
| 714 | |
| 715 | async _fileList (params) { |
| 716 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 717 | return this.backend.api.core.getLocalFiles(params.roomId) |
| 718 | } |
| 719 | |
| 720 | async _fileInfo (params) { |
| 721 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 722 | if (!params.fileId) throw new Error('Missing required param: fileId') |
| 723 | return this.backend.api.core.getFileEntry(params.roomId, params.fileId) |
| 724 | } |
| 725 | |
| 726 | async _fileDownload (params) { |
| 727 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 728 | if (!params.fileId) throw new Error('Missing required param: fileId') |
| 729 | await this.backend.api.core.startDownload(params.roomId, params.fileId) |
| 730 | return { ok: true } |
| 731 | } |
| 732 | |
| 733 | async _fileCancel (params) { |
| 734 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 735 | if (!params.fileId) throw new Error('Missing required param: fileId') |
| 736 | await this.backend.api.core.cancelDownload(params.roomId, params.fileId) |
| 737 | return { ok: true } |
| 738 | } |
| 739 | |
| 740 | async _fileRemove (params) { |
| 741 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 742 | if (!params.fileId) throw new Error('Missing required param: fileId') |
| 743 | await this.backend.api.core.removeFile(params.roomId, params.fileId) |
| 744 | return { ok: true } |
| 745 | } |
| 746 | |
| 747 | async _fileClear (params) { |
| 748 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 749 | if (!params.fileId) throw new Error('Missing required param: fileId') |
| 750 | await this.backend.api.core.clearFile(params.roomId, params.fileId) |
| 751 | return { ok: true } |
| 752 | } |
| 753 | |
| 754 | // --- Advanced Members --- |
| 755 | |
| 756 | async _membersActive (params) { |
| 757 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 758 | return this.backend.api.core.getActiveMembers(params.roomId) |
| 759 | } |
| 760 | |
| 761 | async _membersMods (params) { |
| 762 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 763 | return this.backend.api.core.getModerators(params.roomId) |
| 764 | } |
| 765 | |
| 766 | async _membersCount (params) { |
| 767 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 768 | return this.backend.api.core.getMemberCount(params.roomId) |
| 769 | } |
| 770 | |
| 771 | async _membersConnected (params) { |
| 772 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 773 | return this.backend.api.core.getConnectedMembers(params.roomId) |
| 774 | } |
| 775 | |
| 776 | async _membersSearch (params) { |
| 777 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 778 | if (!params.query) throw new Error('Missing required param: query') |
| 779 | return this.backend.api.core.getSearchMembers(params.roomId, params.query) |
| 780 | } |
| 781 | |
| 782 | // --- Contacts --- |
| 783 | |
| 784 | async _contactInfo (params) { |
| 785 | if (!params.memberId) throw new Error('Missing required param: memberId') |
| 786 | return this.backend.api.core.getContactInfo(params.memberId) |
| 787 | } |
| 788 | |
| 789 | async _contactSelf () { |
| 790 | return this.backend.api.core.getSelfContactInfo() |
| 791 | } |
| 792 | |
| 793 | async _dmFromContact (params) { |
| 794 | if (!params.memberId) throw new Error('Missing required param: memberId') |
| 795 | return this.backend.api.core.sendDMFromContact(params.memberId) |
| 796 | } |
| 797 | |
| 798 | // --- Sub-APIs --- |
| 799 | |
| 800 | async _networkQuery () { |
| 801 | const api = this.backend.api.network |
| 802 | if (!api) throw new Error('Network API not available') |
| 803 | return api.query() |
| 804 | } |
| 805 | |
| 806 | async _preferencesQuery () { |
| 807 | const api = this.backend.api.preferences |
| 808 | if (!api) throw new Error('Preferences API not available') |
| 809 | return api.query() |
| 810 | } |
| 811 | |
| 812 | async _preferencesSet (params) { |
| 813 | const api = this.backend.api.preferences |
| 814 | if (!api) throw new Error('Preferences API not available') |
| 815 | await api.update(params) |
| 816 | return { ok: true } |
| 817 | } |
| 818 | |
| 819 | async _debugStats (params) { |
| 820 | const api = this.backend.api.debug |
| 821 | if (!api) throw new Error('Debug API not available') |
| 822 | if (!params.roomId) throw new Error('Missing required param: roomId') |
| 823 | return api.getCurrentRoomStats(params.roomId) |
| 824 | } |
| 825 | |
| 826 | // --- System (extended) --- |
| 827 | |
| 828 | async _getVersion () { |
| 829 | return this.backend.api.core.getVersion() |
| 830 | } |
| 831 | |
| 832 | async _getStats () { |
| 833 | return this.backend.api.core.getStats() |
| 834 | } |
| 514 | 835 | } |