Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
added CTRL+N to go to next unread msg
Browse files Browse the repository at this point in the history
  • Loading branch information
derricw committed Jun 19, 2020
1 parent 1548ca6 commit e7c41a4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
49 changes: 46 additions & 3 deletions widgets/widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit e7c41a4

Please sign in to comment.