chat/message: Fix RecentActiveUsers sort order
[ssh-chat] / chat / message / user.go
index 3bfca1be9fe870d2d7cc68b126379bef1beb8361..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)
@@ -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,8 +241,8 @@ var DefaultUserConfig UserConfig
 func init() {
        DefaultUserConfig = UserConfig{
                Bell:  true,
+               Echo:  true,
                Quiet: false,
-               Theme: DefaultTheme,
        }
 
        // TODO: Seed random?
@@ -254,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)
+       }
+
 }