aboutsummaryrefslogtreecommitdiff
path: root/roomserver/api/perform.go
blob: 0f5394c945bb9c8a50619448fe4e006f486e0f26 (plain)
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
66
67
68
69
package api

import (
	"github.com/matrix-org/gomatrixserverlib"
	"github.com/matrix-org/util"
)

type JoinError int

const (
	// JoinErrorNotAllowed means the user is not allowed to join this room (e.g join_rule:invite or banned)
	JoinErrorNotAllowed JoinError = 1
	// JoinErrorBadRequest means the request was wrong in some way (invalid user ID, wrong server, etc)
	JoinErrorBadRequest JoinError = 2
	// JoinErrorNoRoom means that the room being joined doesn't exist.
	JoinErrorNoRoom JoinError = 3
)

type PerformJoinRequest struct {
	RoomIDOrAlias string                         `json:"room_id_or_alias"`
	UserID        string                         `json:"user_id"`
	Content       map[string]interface{}         `json:"content"`
	ServerNames   []gomatrixserverlib.ServerName `json:"server_names"`
}

type PerformJoinResponse struct {
	// The room ID, populated on success.
	RoomID string `json:"room_id"`
	// The reason why the join failed. Can be blank.
	Error JoinError `json:"error"`
	// Debugging description of the error. Always present on failure.
	ErrMsg string `json:"err_msg"`
}

type PerformLeaveRequest struct {
	RoomID string `json:"room_id"`
	UserID string `json:"user_id"`
}

type PerformLeaveResponse struct {
}

// PerformBackfillRequest is a request to PerformBackfill.
type PerformBackfillRequest struct {
	// The room to backfill
	RoomID string `json:"room_id"`
	// A map of backwards extremity event ID to a list of its prev_event IDs.
	BackwardsExtremities map[string][]string `json:"backwards_extremities"`
	// The maximum number of events to retrieve.
	Limit int `json:"limit"`
	// The server interested in the events.
	ServerName gomatrixserverlib.ServerName `json:"server_name"`
}

// PrevEventIDs returns the prev_event IDs of all backwards extremities, de-duplicated in a lexicographically sorted order.
func (r *PerformBackfillRequest) PrevEventIDs() []string {
	var prevEventIDs []string
	for _, pes := range r.BackwardsExtremities {
		prevEventIDs = append(prevEventIDs, pes...)
	}
	prevEventIDs = util.UniqueStrings(prevEventIDs)
	return prevEventIDs
}

// PerformBackfillResponse is a response to PerformBackfill.
type PerformBackfillResponse struct {
	// Missing events, arbritrary order.
	Events []gomatrixserverlib.HeaderedEvent `json:"events"`
}