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

We can has ressource with priority now. #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Config struct {
Proxies []string `json:",omitempty"`
Password string `json:",omitempty"`
Port int `json:",omitempty"`
Priority int8 `json:",omitempty"`
PrivateKey []byte
KnownFingerprints []KnownFingerprint
RawLogFile string `json:",omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var uiCommands = []uiCommand{
{"otr-info", otrInfoCommand{}, "Print OTR information such as OTR fingerprint"},
{"otr-start", otrCommand{}, "Start an OTR session with the given user"},
{"paste", pasteCommand{}, "Start interpreting text verbatim"},
{"priority", priorityCommand{}, "Set priority."},
{"quit", quitCommand{}, "Quit the program"},
{"rostereditdone", rosterEditDoneCommand{}, "Load the edited roster from disk"},
{"rosteredit", rosterEditCommand{}, "Write the roster to disk"},
Expand Down Expand Up @@ -112,6 +113,11 @@ type otrCommand struct {
type otrInfoCommand struct{}

type pasteCommand struct{}

type priorityCommand struct {
Priority string
}

type quitCommand struct{}

type rosterCommand struct {
Expand Down
29 changes: 23 additions & 6 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ type Session struct {
account string
conn *xmpp.Conn
term *terminal.Terminal
//I don't know where to put this variable
state string
roster []xmpp.RosterEntry
input Input
// conversations maps from a JID (without the resource) to an OTR
Expand Down Expand Up @@ -384,6 +386,7 @@ func main() {
s := Session{
account: config.Account,
conn: conn,
state: "",
term: term,
conversations: make(map[string]*otr.Conversation),
knownStates: make(map[string]string),
Expand All @@ -404,7 +407,7 @@ func main() {
return
}

conn.SignalPresence("")
conn.SignalPresence(s.state, s.config.Priority)

s.input = Input{
term: term,
Expand Down Expand Up @@ -646,21 +649,35 @@ MainLoop:
s.config.Save()
info(s.term, fmt.Sprintf("Saved manually verified fingerprint %s for %s", cmd.Fingerprint, cmd.User))
case awayCommand:
s.conn.SignalPresence("away")
s.state="away"
s.conn.SignalPresence("away", s.config.Priority)
case chatCommand:
s.conn.SignalPresence("chat")
s.state="chat"
s.conn.SignalPresence("chat", s.config.Priority)
case dndCommand:
s.conn.SignalPresence("dnd")
s.state="dnd"
s.conn.SignalPresence("dnd", s.config.Priority)
case xaCommand:
s.conn.SignalPresence("xa")
s.state="xa"
s.conn.SignalPresence("xa", s.config.Priority)
case onlineCommand:
s.conn.SignalPresence("")
s.state=""
s.conn.SignalPresence("", s.config.Priority)
case ignoreCommand:
s.ignoreUser(cmd.User)
case unignoreCommand:
s.unignoreUser(cmd.User)
case ignoreListCommand:
s.ignoreList()
case priorityCommand:
Priority, err := strconv.ParseInt(cmd.Priority, 10, 8)
if err != nil {
alert(s.term, fmt.Sprintf("Error setting priority to %s", cmd.Priority))
break
}
s.config.Priority = int8(Priority)
s.conn.SignalPresence(s.state, s.config.Priority)
info(s.term, fmt.Sprintf("Set priority to %d for the duration of this session", Priority))
}
case rawStanza, ok := <-stanzaChan:
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions xmpp/xmpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ func (c *Conn) SendPresence(to, typ, id string) error {
return err
}

func (c *Conn) SignalPresence(state string) error {
_, err := fmt.Fprintf(c.out, "<presence><show>%s</show></presence>", xmlEscape(state))
func (c *Conn) SignalPresence(state string, priority int8) error {
_, err := fmt.Fprintf(c.out, "<presence><show>%s</show><priority>%d</priority></presence>", xmlEscape(state), priority)
return err
}

Expand Down