-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathsync.go
More file actions
65 lines (54 loc) · 1.33 KB
/
Copy pathsync.go
File metadata and controls
65 lines (54 loc) · 1.33 KB
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
57
58
59
60
61
62
63
64
65
package matrix
import (
"fmt"
"time"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
"github.com/davecgh/go-spew/spew"
)
type Syncer struct {
m *Matrix
}
func NewSyncer(m *Matrix) *Syncer {
return &Syncer{
m: m,
}
}
func (s *Syncer) ProcessResponse(resp *mautrix.RespSync, since string) error {
for room, sync := range resp.Rooms.Join {
fmt.Println(room)
for _, ev := range append(append(
append(sync.State.Events, sync.Timeline.Events...),
sync.Ephemeral.Events...),
sync.AccountData.Events...) {
ev.Content.ParseRaw(ev.Type) //nolint:errcheck
ev.RoomID = room
spew.Dump(ev)
switch ev.Type {
case event.StateCanonicalAlias:
s.m.handleCanonicalAlias(mautrix.EventSourceState, ev)
case event.StateRoomName:
s.m.handleRoomName(mautrix.EventSourceState, ev)
case event.StateMember:
s.m.handleMember(mautrix.EventSourceState, ev)
case event.AccountDataDirectChats:
s.m.handleDM(mautrix.EventSourceAccountData, ev)
}
}
return nil
}
return nil
}
func (s *Syncer) OnFailedSync(res *mautrix.RespSync, err error) (time.Duration, error) {
return 10 * time.Second, nil
}
func (s *Syncer) GetFilterJSON(userID id.UserID) *mautrix.Filter {
return &mautrix.Filter{
Room: mautrix.RoomFilter{
Timeline: mautrix.FilterPart{
Limit: 50,
},
},
}
}