From e7c41a4f8d498d8231dfeef75d4d0426d3be142e Mon Sep 17 00:00:00 2001 From: Derric Williams Date: Thu, 18 Jun 2020 23:12:33 -0700 Subject: [PATCH] added CTRL+N to go to next unread msg --- README.md | 6 ++++-- widgets/widgets.go | 49 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 56bd9c6..e368c11 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ bin/siggo * `oo` - Open Last Attachment * `ol` - Open Last Link * `ESC` - Normal Mode +* `CTRL+N` - Move to next conversation with unread messages * `CTRL+Q` - Quit (`CTRL+C` _should_ also work) ### Configuration @@ -111,9 +112,10 @@ Here is a list of features I'd like to add soonish. * gui configuration * colors and border styles * let user re-sort contact list (for example alphabetically) -* command to go to next contact with message waiting * command to go to contact with fuzzy matching * groups support -* use dbus to send instead of signal-cli, to avoid having to spin up the JVM (might also fix the read receipt issue) +* use dbus to send instead of signal-cli, to avoid having to spin up the JVM * there is still some data that i'm dropping on the floor +* weechat/BitlBee plugin that uses the siggo model without the UI * wouldn't tests be neat? +* signal-cli seems to delete old attachments after a while. maybe I should move them somewhere where they wont get deleted? diff --git a/widgets/widgets.go b/widgets/widgets.go index b439986..d1011a3 100644 --- a/widgets/widgets.go +++ b/widgets/widgets.go @@ -250,8 +250,10 @@ func (c *ChatWindow) currentConversation() (*model.Conversation, error) { // SetCurrentContact sets the active contact func (c *ChatWindow) SetCurrentContact(contact *model.Contact) error { + log.Debug("setting current contact to: %v", contact) c.currentContact = contact - c.contactsPanel.Update() + c.contactsPanel.GotoContact(contact) + c.contactsPanel.Render() conv, err := c.currentConversation() if err != nil { return err @@ -262,6 +264,20 @@ func (c *ChatWindow) SetCurrentContact(contact *model.Contact) error { return nil } +// NextUnreadMessage searches for the next conversation with unread messages and makes that the +// active conversation. +func (c *ChatWindow) NextUnreadMessage() error { + for contact, conv := range c.siggo.Conversations() { + if conv.HasNewMessage { + err := c.SetCurrentContact(contact) + if err != nil { + c.SetErrorStatus(err) + } + } + } + return nil +} + // TODO: remove code duplication with ContactDown() func (c *ChatWindow) ContactUp() { log.Debug("PREVIOUS CONVERSATION") @@ -341,7 +357,7 @@ func (c *ChatWindow) Quit() { func (c *ChatWindow) update() { convs := c.siggo.Conversations() if convs != nil { - c.contactsPanel.Update() + c.contactsPanel.Render() currentConv, ok := convs[c.currentContact] if ok { c.conversationPanel.Update(currentConv) @@ -434,7 +450,31 @@ func (cl *ContactListPanel) Previous() *model.Contact { return cl.sortedContacts[cl.currentIndex] } -func (cl *ContactListPanel) Update() { +// GotoIndex goes to a particular contact index and return the Contact. Negative indexing is +// allowed. +func (cl *ContactListPanel) GotoIndex(index int) *model.Contact { + if index < 0 { + return cl.GotoIndex(len(cl.sortedContacts) - index) + } + if index >= len(cl.sortedContacts) { + return cl.GotoIndex(-1) + } + cl.currentIndex = index + return cl.sortedContacts[index] +} + +// GotoContact goes to a particular contact. +// TODO: constant time way to do this? +func (cl *ContactListPanel) GotoContact(contact *model.Contact) { + for i, c := range cl.sortedContacts { + if contact == c { + cl.GotoIndex(i) + } + } +} + +// Render re-renders the contact list +func (cl *ContactListPanel) Render() { data := "" log.Debug("updating contact panel...") // this is dumb, we re-sort every update @@ -648,6 +688,9 @@ func NewChatWindow(siggo *model.Siggo, app *tview.Application) *ChatWindow { case tcell.KeyCtrlT: w.ShowContactSearch() return nil + case tcell.KeyCtrlN: + w.NextUnreadMessage() + return nil } return event }