@@ -442,14 +442,14 @@ export class ServerManagerView {
442442 initServerActions ( ) : void {
443443 const $serverImgs : NodeListOf < HTMLImageElement > =
444444 document . querySelectorAll ( ".server-icons" ) ;
445- for ( const [ index , $serverImg ] of $serverImgs . entries ( ) ) {
446- this . addContextMenu ( $serverImg , index ) ;
445+ for ( const $serverImg of $serverImgs ) {
446+ this . addContextMenu ( $serverImg ) ;
447447 if ( $serverImg . src === defaultIcon ) {
448- this . displayInitialCharLogo ( $serverImg , index ) ;
448+ this . displayInitialCharLogo ( $serverImg ) ;
449449 }
450450
451451 $serverImg . addEventListener ( "error" , ( ) => {
452- this . displayInitialCharLogo ( $serverImg , index ) ;
452+ this . displayInitialCharLogo ( $serverImg ) ;
453453 } ) ;
454454 }
455455 }
@@ -501,11 +501,7 @@ export class ServerManagerView {
501501 return tab instanceof ServerTab ? ( await tab . webview ) . properties . url : "" ;
502502 }
503503
504- displayInitialCharLogo ( $img : HTMLImageElement , index : number ) : void {
505- // The index parameter is needed because webview[data-tab-id] can
506- // increment beyond the size of the sidebar org array and throw an
507- // error
508-
504+ displayInitialCharLogo ( $img : HTMLImageElement ) : void {
509505 const $altIcon = document . createElement ( "div" ) ;
510506 const $parent = $img . parentElement ! ;
511507 const $container = $parent . parentElement ! ;
@@ -526,7 +522,7 @@ export class ServerManagerView {
526522 $img . remove ( ) ;
527523 $parent . append ( $altIcon ) ;
528524
529- this . addContextMenu ( $altIcon , index ) ;
525+ this . addContextMenu ( $altIcon ) ;
530526 }
531527
532528 sidebarHoverEvent (
@@ -820,8 +816,8 @@ export class ServerManagerView {
820816 }
821817 }
822818
823- async isLoggedIn ( index : number ) : Promise < boolean > {
824- const tab = this . tabs [ index ] ;
819+ async isLoggedIn ( tabId : string ) : Promise < boolean > {
820+ const tab = this . getTabById ( tabId ) ;
825821 if ( ! ( tab instanceof ServerTab ) ) return false ;
826822 const webview = await tab . webview ;
827823 const url = webview . getWebContents ( ) . getURL ( ) ;
@@ -839,9 +835,16 @@ export class ServerManagerView {
839835 return this . tabs . find ( ( tab ) => tab . properties . tabId === tabId ) ;
840836 }
841837
842- addContextMenu ( $serverImg : HTMLElement , index : number ) : void {
838+ addContextMenu ( $serverImg : HTMLElement ) : void {
843839 $serverImg . addEventListener ( "contextmenu" , async ( event ) => {
844840 event . preventDefault ( ) ;
841+ const tabElement = $serverImg . closest ( ".tab" ) ;
842+ const tabId =
843+ tabElement instanceof HTMLElement
844+ ? tabElement . dataset . tabId
845+ : undefined ;
846+ if ( tabId === undefined ) return ;
847+
845848 const template = [
846849 {
847850 label : t . __ ( "Disconnect organization" ) ,
@@ -855,11 +858,11 @@ export class ServerManagerView {
855858 ) ,
856859 } ) ;
857860 if ( response === 0 ) {
858- if ( DomainUtil . removeDomain ( index ) ) {
861+ if ( DomainUtil . removeDomainById ( tabId ) ) {
859862 ipcRenderer . send ( "reload-full-app" ) ;
860863 } else {
861864 const { title, content} = Messages . orgRemovalError (
862- DomainUtil . getDomain ( index ) . url ,
865+ DomainUtil . getDomainById ( tabId ) ! . url ,
863866 ) ;
864867 dialog . showErrorBox ( title , content ) ;
865868 }
@@ -868,19 +871,19 @@ export class ServerManagerView {
868871 } ,
869872 {
870873 label : t . __ ( "Notification settings" ) ,
871- enabled : await this . isLoggedIn ( index ) ,
874+ enabled : await this . isLoggedIn ( tabId ) ,
872875 click : async ( ) => {
873876 // Switch to tab whose icon was right-clicked
874- const tab = this . tabs [ index ] ;
875- await this . activateTab ( tab . properties . tabId ) ;
877+ const tab = this . getTabById ( tabId ) ;
878+ await this . activateTab ( tabId ) ;
876879 if ( tab instanceof ServerTab )
877880 ( await tab . webview ) . showNotificationSettings ( ) ;
878881 } ,
879882 } ,
880883 {
881884 label : t . __ ( "Copy Zulip URL" ) ,
882885 click ( ) {
883- clipboard . writeText ( DomainUtil . getDomain ( index ) . url ) ;
886+ clipboard . writeText ( DomainUtil . getDomainById ( tabId ) ! . url ) ;
884887 } ,
885888 } ,
886889 ] ;
0 commit comments