-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvite.go
36 lines (34 loc) · 974 Bytes
/
invite.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
package main
import (
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
)
func (fs *FeedServ) HandleInvite(_ mautrix.EventSource, evt *event.Event) {
if evt.GetStateKey() != fs.Client.UserID.String() || evt.Content.AsMember().Membership != event.MembershipInvite {
return
}
log := fs.Log.With().
Str("room_id", evt.RoomID.String()).
Str("sender", evt.Sender.String()).
Str("event_id", evt.ID.String()).
Str("action", "invite").
Logger()
_, allowed := fs.Config.feedsByRoomID[evt.RoomID]
if !allowed {
log.Info().Msg("Rejecting invite to non-feed room")
_, err := fs.Client.LeaveRoom(evt.RoomID)
if err != nil {
log.Err(err).Msg("Failed to reject invite")
} else {
log.Debug().Msg("Rejected invite")
}
} else {
log.Info().Msg("Accepting invite to feed room")
_, err := fs.Client.JoinRoomByID(evt.RoomID)
if err != nil {
log.Err(err).Msg("Failed to accept invite")
} else {
log.Debug().Msg("Accepted invite")
}
}
}