chat/message: Fix RecentActiveUsers sort order
[ssh-chat] / chat / message / user.go
index faea90c11e926467b936a4d6db5e68a9d44bb9c1..d4cc304c539c995076dcc27e02dba1adefc84538 100644 (file)
@@ -161,6 +161,9 @@ func (u *User) render(m Message) string {
        switch m := m.(type) {
        case PublicMsg:
                if u == m.From() {
+                       if !cfg.Echo {
+                               return ""
+                       }
                        out += m.RenderSelf(cfg)
                } else {
                        out += m.RenderFor(cfg)
@@ -182,7 +185,7 @@ func (u *User) render(m Message) string {
                } else {
                        ts = ts.UTC()
                }
-               return cfg.Theme.Timestamp(ts.Format(*cfg.Timeformat) + "  " + out + Newline)
+               return cfg.Theme.Timestamp(ts.Format(*cfg.Timeformat)) + "  " + out + Newline
        }
        return out + Newline
 }
@@ -226,6 +229,7 @@ type UserConfig struct {
        Highlight  *regexp.Regexp
        Bell       bool
        Quiet      bool
+       Echo       bool // Echo shows your own messages after sending, disabled for bots
        Timeformat *string
        Timezone   *time.Location
        Theme      *Theme
@@ -237,6 +241,7 @@ var DefaultUserConfig UserConfig
 func init() {
        DefaultUserConfig = UserConfig{
                Bell:  true,
+               Echo:  true,
                Quiet: false,
        }
 
@@ -253,5 +258,11 @@ func (a RecentActiveUsers) Less(i, j int) bool {
        defer a[i].mu.Unlock()
        a[j].mu.Lock()
        defer a[j].mu.Unlock()
-       return a[i].lastMsg.After(a[j].lastMsg)
+
+       if a[i].lastMsg.IsZero() {
+               return a[i].joined.Before(a[j].joined)
+       } else {
+               return a[i].lastMsg.Before(a[j].lastMsg)
+       }
+
 }