-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
56 lines (50 loc) · 1.06 KB
/
main.go
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
45
46
47
48
49
50
51
52
53
54
55
56
package goMatrix
import "log"
// Session .
type Session struct {
NextBatch string
Rooms map[string]RoomInfo // The rooms a user is part of
AccessToken string
HomeServer string
OnNewMsg chan RoomMessage
OnJoin chan string // When we find a new room
TxnID int
stop chan bool // stop the service
}
// Start ..
func (session *Session) Start() {
go func() {
Loop:
for {
select {
case <-session.stop:
break Loop
default:
err := session.Sync()
if err != nil {
switch {
case err.Error()[(len(err.Error())-11):] == "i/o timeout": // Just ignore this one
default:
log.Println(err)
}
}
}
}
}()
}
// Close closes everything down
func (session *Session) Close() {
session.stop <- true
}
// Init .
func Init(homeserver string) *Session {
session := Session{HomeServer: homeserver,
NextBatch: "s9_13_0_1_1_1",
OnNewMsg: make(chan RoomMessage, 10),
OnJoin: make(chan string, 10),
Rooms: make(map[string]RoomInfo),
TxnID: 0,
stop: make(chan bool),
}
return &session
}