switch m := m.(type) {
case PublicMsg:
if u == m.From() {
+ if !cfg.Echo {
+ return ""
+ }
out += m.RenderSelf(cfg)
} else {
out += m.RenderFor(cfg)
default:
out += m.Render(cfg.Theme)
}
- if cfg.Timestamp {
+ if cfg.Timeformat != nil {
ts := m.Timestamp()
if cfg.Timezone != nil {
ts = ts.In(cfg.Timezone)
} else {
ts = ts.UTC()
}
- return cfg.Theme.Timestamp(ts) + " " + out + Newline
+ return cfg.Theme.Timestamp(ts.Format(*cfg.Timeformat)) + " " + out + Newline
}
return out + Newline
}
// Container for per-user configurations.
type UserConfig struct {
- Highlight *regexp.Regexp
- Bell bool
- Quiet bool
- Timestamp bool
- Timezone *time.Location
- Theme *Theme
+ 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
}
// Default user configuration to use
func init() {
DefaultUserConfig = UserConfig{
- Bell: true,
- Quiet: false,
- Timestamp: false,
+ Bell: true,
+ Echo: true,
+ Quiet: false,
}
// TODO: Seed random?
}
+
+// RecentActiveUsers is a slice of *Users that knows how to be sorted by the time of the last message.
+type RecentActiveUsers []*User
+
+func (a RecentActiveUsers) Len() int { return len(a) }
+func (a RecentActiveUsers) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
+func (a RecentActiveUsers) Less(i, j int) bool {
+ a[i].mu.Lock()
+ defer a[i].mu.Unlock()
+ a[j].mu.Lock()
+ defer a[j].mu.Unlock()
+
+ if a[i].lastMsg.IsZero() {
+ return a[i].joined.Before(a[j].joined)
+ } else {
+ return a[i].lastMsg.Before(a[j].lastMsg)
+ }
+
+}