-
Notifications
You must be signed in to change notification settings - Fork 2
/
invitev3.go
62 lines (53 loc) · 1.65 KB
/
invitev3.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
57
58
59
60
61
62
package fclient
import (
"encoding/json"
"github.com/neilalexander/harmony/internal/gomatrixserverlib"
)
func NewInviteV3Request(event gomatrixserverlib.ProtoEvent, version gomatrixserverlib.RoomVersion, state []gomatrixserverlib.InviteStrippedState) (
request InviteV3Request, err error,
) {
if !gomatrixserverlib.KnownRoomVersion(version) {
err = gomatrixserverlib.UnsupportedRoomVersionError{
Version: version,
}
return
}
request.fields.inviteV2RequestHeaders = inviteV2RequestHeaders{
RoomVersion: version,
InviteRoomState: state,
}
request.fields.Event = event
return
}
// InviteV3Request is used in the body of a /_matrix/federation/v3/invite request.
type InviteV3Request struct {
fields struct {
inviteV2RequestHeaders
Event gomatrixserverlib.ProtoEvent `json:"event"`
}
}
// MarshalJSON implements json.Marshaller
func (i InviteV3Request) MarshalJSON() ([]byte, error) {
return json.Marshal(i.fields)
}
// UnmarshalJSON implements json.Unmarshaller
func (i *InviteV3Request) UnmarshalJSON(data []byte) error {
err := json.Unmarshal(data, &i.fields)
if err != nil {
return err
}
return err
}
// Event returns the invite event.
func (i *InviteV3Request) Event() gomatrixserverlib.ProtoEvent {
return i.fields.Event
}
// RoomVersion returns the room version of the invited room.
func (i *InviteV3Request) RoomVersion() gomatrixserverlib.RoomVersion {
return i.fields.RoomVersion
}
// InviteRoomState returns stripped state events for the room, containing
// enough information for the client to identify the room.
func (i *InviteV3Request) InviteRoomState() []gomatrixserverlib.InviteStrippedState {
return i.fields.InviteRoomState
}