aboutsummaryrefslogtreecommitdiff
path: root/internal/chat/logs.go
blob: 09d60fedb6b31486a4d5a9cf649bafe7aab19599 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package chat

import "time"

type Logs struct {
	entries [20]LogEntry
	start   int
}

func (l *Logs) Append(le LogEntry) {
	l.entries[l.start] = le
	l.start++
	if l.start == len(l.entries) {
		l.start = 0
	}
}

func (l *Logs) Get() []LogEntry {
	result := make([]LogEntry, 0, len(l.entries))
	for i := l.start; i < len(l.entries); i++ {
		result = append(result, l.entries[i])
	}
	for i := 0; i < l.start; i++ {
		result = append(result, l.entries[i])
	}

	return result
}

type LogEntry struct {
	Username string
	Time     time.Time
	Message  string
	Type     LogEntryType
}

type LogEntryType int

const (
	TypeNone LogEntryType = iota
	TypeJoined
	TypeLeft
	TypeMessage
)