Fix removing rooms

This commit is contained in:
Tulir Asokan 2018-03-17 16:09:53 +02:00
parent b0ebb4b9a4
commit b536064882

View File

@ -18,6 +18,7 @@ package main
import ( import (
"fmt" "fmt"
"sort"
"strings" "strings"
"time" "time"
"unicode" "unicode"
@ -252,11 +253,17 @@ func (view *MainView) RemoveRoom(room string) {
if !view.HasRoom(room) { if !view.HasRoom(room) {
return return
} }
view.roomList.RemoveItem(view.currentRoomIndex) removeIndex := 0
if view.CurrentRoomID() == room { if view.CurrentRoomID() == room {
removeIndex = view.currentRoomIndex
view.SwitchRoom(view.currentRoomIndex - 1) view.SwitchRoom(view.currentRoomIndex - 1)
} else {
removeIndex = sort.StringSlice(view.roomIDs).Search(room)
} }
view.roomList.RemoveItem(removeIndex)
view.roomIDs = append(view.roomIDs[:removeIndex], view.roomIDs[removeIndex+1:]...)
view.roomView.RemovePage(room) view.roomView.RemovePage(room)
view.Render()
} }
func (view *MainView) SetRoomList(rooms []string) { func (view *MainView) SetRoomList(rooms []string) {