Skip to content

Commit

Permalink
Fix crash introduced by #604f255
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkorin committed Feb 14, 2019
1 parent ecccd91 commit 8f3edea
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ func NewGoCUI(c *Conversation) (*GoCUI, error) {
return gui, nil
}

func (gui *GoCUI) IsCurrentSpace(id string) bool {
if gui.currentSpaceIndex == -1 {
return false
}
return gui.spacesList[gui.currentSpaceIndex].Id == id

}

func (gui *GoCUI) Start() error {
if err := gui.MainLoop(); err != nil && err != gocui.ErrQuit {
return err
Expand Down Expand Up @@ -124,7 +132,7 @@ func (gui *GoCUI) NewActivityHandler(s *Space, a *Activity) {
if ok {
gui.moveToSpace(spaceIndex)
}
} else if a.Verb == "acknowledge" && gui.spacesList[gui.currentSpaceIndex].Id != a.Target.Id {
} else if a.Verb == "acknowledge" && !gui.IsCurrentSpace(a.Target.Id) {
gui.updateSpaceList()
} else if a.Verb == "post" || a.Verb == "share" {
spaceIndex := gui.spacesMap[s.Id]
Expand Down Expand Up @@ -284,14 +292,14 @@ func (gui *GoCUI) sendMessage(msg string) {
}
}
}
if msg[1:] == "leave" {
if msg[1:] == "leave" && gui.currentSpaceIndex != -1 {
gui.conversation.LeaveSpace(gui.spacesList[gui.currentSpaceIndex].Space)
}
if strings.HasPrefix(msg[1:], "create ") {
gui.conversation.CreateSpace(msg[8:])
}
// Unknown command
} else {
} else if gui.currentSpaceIndex != -1 {
gui.spacesList[gui.currentSpaceIndex].SendMessage(msg)
}
}
Expand Down Expand Up @@ -374,20 +382,21 @@ func (gui *GoCUI) updateSpaceStatus() {
v, _ := g.View("spaceStatus")
v.Clear()

space := gui.spacesList[gui.currentSpaceIndex]
if gui.currentSpaceIndex != -1 {
space := gui.spacesList[gui.currentSpaceIndex]

fmt.Fprintf(v, "[%s]", space.DisplayName())
fmt.Fprintf(v, "[%s]", space.DisplayName())

msgView, _ := g.View("messages")
if !msgView.Autoscroll {
_, viewHeight := msgView.Size()
_, oy := msgView.Origin()
nbLines := len(msgView.ViewBufferLines())
msgView, _ := g.View("messages")
if !msgView.Autoscroll {
_, viewHeight := msgView.Size()
_, oy := msgView.Origin()
nbLines := len(msgView.ViewBufferLines())

moreLines := nbLines - viewHeight - oy
fmt.Fprintf(v, " -MORE(%d)-", moreLines)
moreLines := nbLines - viewHeight - oy
fmt.Fprintf(v, " -MORE(%d)-", moreLines)
}
}

return nil
})
}
Expand Down

0 comments on commit 8f3edea

Please sign in to comment.