commit 360302f

Hubert Hirtz  ·  2020-11-23 10:16:37 +0000 UTC
parent 2221f93
Document irc/typing.go
1 files changed,  +11, -4
+11, -4
 1@@ -5,18 +5,21 @@ import (
 2 	"time"
 3 )
 4 
 5+// Typing is an event of Name actively typing in Target.
 6 type Typing struct {
 7 	Target string
 8 	Name   string
 9 }
10 
11+// Typings keeps track of typing notification timeouts.
12 type Typings struct {
13 	l        sync.Mutex
14-	targets  map[Typing]time.Time
15-	timeouts chan Typing
16-	stops    chan Typing
17+	targets  map[Typing]time.Time // @+typing TAGMSG timestamps.
18+	timeouts chan Typing          // transmits unfiltered timeout notifications.
19+	stops    chan Typing          // transmits filtered timeout notifications.
20 }
21 
22+// NewTypings initializes the Typings structures and filtering coroutine.
23 func NewTypings() *Typings {
24 	ts := &Typings{
25 		targets:  map[Typing]time.Time{},
26@@ -40,18 +43,21 @@ func NewTypings() *Typings {
27 	return ts
28 }
29 
30+// Stop cleanly closes all channels and stops all coroutines.
31 func (ts *Typings) Stop() {
32 	close(ts.timeouts)
33 	close(ts.stops)
34 }
35 
36+// Stops is a channel that transmits typing timeouts.
37 func (ts *Typings) Stops() <-chan Typing {
38 	return ts.stops
39 }
40 
41+// Active should be called when a user is typing to some target.
42 func (ts *Typings) Active(target, name string) {
43-	t := Typing{target, name}
44 	ts.l.Lock()
45+	t := Typing{target, name}
46 	ts.targets[t] = time.Now()
47 	ts.l.Unlock()
48 
49@@ -61,6 +67,7 @@ func (ts *Typings) Active(target, name string) {
50 	}()
51 }
52 
53+// Active should be called when a user is done typing to some target.
54 func (ts *Typings) Done(target, name string) {
55 	ts.l.Lock()
56 	delete(ts.targets, Typing{target, name})