summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.go13
-rw-r--r--commands.go19
-rw-r--r--irc/session.go34
3 files changed, 44 insertions, 22 deletions
diff --git a/app.go b/app.go
index 0e60b80..c44dc05 100644
--- a/app.go
+++ b/app.go
@@ -748,6 +748,9 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
})
case irc.MessageEvent:
buffer, line, notification := app.formatMessage(s, ev)
+ if buffer != "" && !s.IsChannel(buffer) {
+ app.win.AddBuffer(netID, "", buffer)
+ }
app.win.AddLine(netID, buffer, notification, line)
if notification == ui.NotifyHighlight {
app.notifyHighlight(buffer, ev.User, line.Body.String())
@@ -936,6 +939,7 @@ func (app *App) completions(cursorIdx int, text []rune) []ui.Completion {
// - what kind of notification senpai should send.
func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer string, line ui.Line, notification ui.NotifyType) {
isFromSelf := s.IsMe(ev.User)
+ isToSelf := s.IsMe(ev.Target)
isHighlight := app.isHighlight(s, ev.Content)
isAction := strings.HasPrefix(ev.Content, "\x01ACTION")
isQuery := !ev.TargetIsChannel && ev.Command == "PRIVMSG"
@@ -948,8 +952,8 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
} else {
isHighlight = true
}
- } else if !ev.TargetIsChannel {
- buffer = ""
+ } else if isToSelf {
+ buffer = ev.User
} else {
buffer = ev.Target
}
@@ -965,10 +969,7 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
head := ev.User
headColor := tcell.ColorWhite
- if isFromSelf && isQuery {
- head = "\u2192 " + ev.Target
- headColor = identColor(ev.Target)
- } else if isAction || isNotice {
+ if isAction || isNotice {
head = "*"
} else {
headColor = identColor(head)
diff --git a/commands.go b/commands.go
index 1dd5cd0..4e534c1 100644
--- a/commands.go
+++ b/commands.go
@@ -152,7 +152,7 @@ func noCommand(app *App, content string) error {
buffer, line, _ := app.formatMessage(s, irc.MessageEvent{
User: s.Nick(),
Target: buffer,
- TargetIsChannel: true,
+ TargetIsChannel: s.IsChannel(buffer),
Command: "PRIVMSG",
Content: content,
Time: time.Now(),
@@ -280,7 +280,7 @@ func commandDoMe(app *App, args []string) (err error) {
buffer, line, _ := app.formatMessage(s, irc.MessageEvent{
User: s.Nick(),
Target: buffer,
- TargetIsChannel: true,
+ TargetIsChannel: s.IsChannel(buffer),
Command: "PRIVMSG",
Content: content,
Time: time.Now(),
@@ -303,11 +303,15 @@ func commandDoMsg(app *App, args []string) (err error) {
buffer, line, _ := app.formatMessage(s, irc.MessageEvent{
User: s.Nick(),
Target: target,
- TargetIsChannel: true,
+ TargetIsChannel: s.IsChannel(target),
Command: "PRIVMSG",
Content: content,
Time: time.Now(),
})
+ if buffer != "" && !s.IsChannel(target) {
+ app.win.AddBuffer(netID, "", buffer)
+ }
+
app.win.AddLine(netID, buffer, ui.NotifyNone, line)
}
return nil
@@ -397,7 +401,12 @@ func commandDoPart(app *App, args []string) (err error) {
if channel == "" {
return fmt.Errorf("cannot part this buffer")
}
- s.Part(channel, reason)
+
+ if s.IsChannel(channel) {
+ s.Part(channel, reason)
+ } else {
+ app.win.RemoveBuffer(netID, channel)
+ }
return nil
}
@@ -432,7 +441,7 @@ func commandDoR(app *App, args []string) (err error) {
buffer, line, _ := app.formatMessage(s, irc.MessageEvent{
User: s.Nick(),
Target: app.lastQuery,
- TargetIsChannel: true,
+ TargetIsChannel: s.IsChannel(app.lastQuery),
Command: "PRIVMSG",
Content: args[0],
Time: time.Now(),
diff --git a/irc/session.go b/irc/session.go
index 881cc4d..7e1c664 100644
--- a/irc/session.go
+++ b/irc/session.go
@@ -218,20 +218,32 @@ func (s *Session) Users() []string {
return users
}
-// Names returns the list of users in the given channel, or nil if this channel
-// is not known by the session.
+// Names returns the list of users in the given target, or nil if the target
+// is not a known channel or nick in the session.
// The list is sorted according to member name.
-func (s *Session) Names(channel string) []Member {
+func (s *Session) Names(target string) []Member {
var names []Member
- if c, ok := s.channels[s.Casemap(channel)]; ok {
- names = make([]Member, 0, len(c.Members))
- for u, pl := range c.Members {
- names = append(names, Member{
- PowerLevel: pl,
- Name: u.Name.Copy(),
- Away: u.Away,
- })
+ if s.IsChannel(target) {
+ if c, ok := s.channels[s.Casemap(target)]; ok {
+ names = make([]Member, 0, len(c.Members))
+ for u, pl := range c.Members {
+ names = append(names, Member{
+ PowerLevel: pl,
+ Name: u.Name.Copy(),
+ Away: u.Away,
+ })
+ }
}
+ } else if u, ok := s.users[s.Casemap(target)]; ok {
+ names = append(names, Member{
+ Name: u.Name.Copy(),
+ Away: u.Away,
+ })
+ names = append(names, Member{
+ Name: &Prefix{
+ Name: s.nick,
+ },
+ })
}
sort.Sort(members(names))
return names