Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reply to outbox messages #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions client/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,17 +1145,18 @@ func (c *cliClient) processCommand(cmd interface{}) (shouldQuit bool) {
}

case replyCommand:
msg, ok := c.currentObj.(*InboxMessage)
if !ok {
c.Printf("%s Select inbox message first\n", termWarnPrefix)
return
}
if msg.from == 0 {
c.Printf("%s Cannot reply to server announcement\n", termWarnPrefix)
return
switch msg := c.currentObj.(type) {
case *InboxMessage:
if msg.from == 0 {
c.Printf("%s Cannot reply to server announcement\n", termWarnPrefix)
return
}
c.compose(c.contacts[msg.from], nil, msg)
case *queuedMessage:
c.compose(c.contacts[msg.to], nil, msg)
default:
c.Printf("%s Select inbox or outbox message first\n", termWarnPrefix)
}
c.compose(c.contacts[msg.from], nil, msg)

default:
goto Handle
}
Expand Down Expand Up @@ -1656,17 +1657,26 @@ Handle:
return
}

func (c *cliClient) compose(to *Contact, draft *Draft, inReplyTo *InboxMessage) {
func (c *cliClient) compose(to *Contact, draft *Draft, inReplyTo interface{}) {
if draft == nil {
draft = &Draft{
id: c.randId(),
created: time.Now(),
to: to.id,
cliId: c.newCliId(),
}
if inReplyTo != nil && inReplyTo.message != nil {
draft.inReplyTo = inReplyTo.message.GetId()
draft.body = indentForReply(inReplyTo.message.GetBody())
if inReplyTo != nil {
switch obj := inReplyTo.(type) {
case *InboxMessage:
if obj.message != nil {
draft.inReplyTo = obj.message.GetId()
draft.body = indentForReply(obj.message.GetBody())
}
case *queuedMessage:
if obj.message != nil {
draft.body = indentForReply(obj.message.GetBody())
}
}
}
c.Printf("%s Created new draft: %s%s%s\n", termInfoPrefix, termCliIdStart, draft.cliId.String(), termReset)
c.drafts[draft.id] = draft
Expand Down