mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-20 20:43:09 -06:00
Allow passing AppserviceID and NetworkID as parameters
This commit is contained in:
parent
4378b529e3
commit
7ea8e83387
|
|
@ -168,8 +168,10 @@ type PerformBackfillResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PerformPublishRequest struct {
|
type PerformPublishRequest struct {
|
||||||
RoomID string
|
RoomID string
|
||||||
Visibility string
|
Visibility string
|
||||||
|
AppserviceID string
|
||||||
|
NetworkID string
|
||||||
}
|
}
|
||||||
|
|
||||||
type PerformPublishResponse struct {
|
type PerformPublishResponse struct {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ func (r *Publisher) PerformPublish(
|
||||||
req *api.PerformPublishRequest,
|
req *api.PerformPublishRequest,
|
||||||
res *api.PerformPublishResponse,
|
res *api.PerformPublishResponse,
|
||||||
) error {
|
) error {
|
||||||
err := r.DB.PublishRoom(ctx, req.RoomID, req.Visibility == "public")
|
err := r.DB.PublishRoom(ctx, req.RoomID, req.AppserviceID, req.NetworkID, req.Visibility == "public")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Msg: err.Error(),
|
Msg: err.Error(),
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ type Database interface {
|
||||||
// Returns an error if the retrieval went wrong.
|
// Returns an error if the retrieval went wrong.
|
||||||
EventsFromIDs(ctx context.Context, eventIDs []string) ([]types.Event, error)
|
EventsFromIDs(ctx context.Context, eventIDs []string) ([]types.Event, error)
|
||||||
// Publish or unpublish a room from the room directory.
|
// Publish or unpublish a room from the room directory.
|
||||||
PublishRoom(ctx context.Context, roomID string, publish bool) error
|
PublishRoom(ctx context.Context, roomID, appserviceID, networkID string, publish bool) error
|
||||||
// Returns a list of room IDs for rooms which are published.
|
// Returns a list of room IDs for rooms which are published.
|
||||||
GetPublishedRooms(ctx context.Context) ([]string, error)
|
GetPublishedRooms(ctx context.Context) ([]string, error)
|
||||||
// Returns whether a given room is published or not.
|
// Returns whether a given room is published or not.
|
||||||
|
|
|
||||||
|
|
@ -79,10 +79,10 @@ func PreparePublishedTable(db *sql.DB) (tables.Published, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *publishedStatements) UpsertRoomPublished(
|
func (s *publishedStatements) UpsertRoomPublished(
|
||||||
ctx context.Context, txn *sql.Tx, roomID string, published bool,
|
ctx context.Context, txn *sql.Tx, roomID, appserviceID, networkID string, published bool,
|
||||||
) (err error) {
|
) (err error) {
|
||||||
stmt := sqlutil.TxStmt(txn, s.upsertPublishedStmt)
|
stmt := sqlutil.TxStmt(txn, s.upsertPublishedStmt)
|
||||||
_, err = stmt.ExecContext(ctx, roomID, "", "", published)
|
_, err = stmt.ExecContext(ctx, roomID, appserviceID, networkID, published)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -722,9 +722,9 @@ func (d *Database) storeEvent(
|
||||||
}, redactionEvent, redactedEventID, err
|
}, redactionEvent, redactedEventID, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) PublishRoom(ctx context.Context, roomID string, publish bool) error {
|
func (d *Database) PublishRoom(ctx context.Context, roomID, appserviceID, networkID string, publish bool) error {
|
||||||
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
return d.PublishedTable.UpsertRoomPublished(ctx, txn, roomID, publish)
|
return d.PublishedTable.UpsertRoomPublished(ctx, txn, roomID, appserviceID, networkID, publish)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,10 +82,10 @@ func PreparePublishedTable(db *sql.DB) (tables.Published, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *publishedStatements) UpsertRoomPublished(
|
func (s *publishedStatements) UpsertRoomPublished(
|
||||||
ctx context.Context, txn *sql.Tx, roomID string, published bool,
|
ctx context.Context, txn *sql.Tx, roomID, appserviceID, networkID string, published bool,
|
||||||
) error {
|
) error {
|
||||||
stmt := sqlutil.TxStmt(txn, s.upsertPublishedStmt)
|
stmt := sqlutil.TxStmt(txn, s.upsertPublishedStmt)
|
||||||
_, err := stmt.ExecContext(ctx, roomID, "", "", published)
|
_, err := stmt.ExecContext(ctx, roomID, appserviceID, networkID, published)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ type Membership interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Published interface {
|
type Published interface {
|
||||||
UpsertRoomPublished(ctx context.Context, txn *sql.Tx, roomID string, published bool) (err error)
|
UpsertRoomPublished(ctx context.Context, txn *sql.Tx, roomID, appserviceID, networkID string, published bool) (err error)
|
||||||
SelectPublishedFromRoomID(ctx context.Context, txn *sql.Tx, roomID string) (published bool, err error)
|
SelectPublishedFromRoomID(ctx context.Context, txn *sql.Tx, roomID string) (published bool, err error)
|
||||||
SelectAllPublishedRooms(ctx context.Context, txn *sql.Tx, published bool) ([]string, error)
|
SelectAllPublishedRooms(ctx context.Context, txn *sql.Tx, published bool) ([]string, error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,10 +48,12 @@ func TestPublishedTable(t *testing.T) {
|
||||||
|
|
||||||
// Publish some rooms
|
// Publish some rooms
|
||||||
publishedRooms := []string{}
|
publishedRooms := []string{}
|
||||||
|
asID := ""
|
||||||
|
nwID := ""
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
room := test.NewRoom(t, alice)
|
room := test.NewRoom(t, alice)
|
||||||
published := i%2 == 0
|
published := i%2 == 0
|
||||||
err := tab.UpsertRoomPublished(ctx, nil, room.ID, published)
|
err := tab.UpsertRoomPublished(ctx, nil, room.ID, asID, nwID, published)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
if published {
|
if published {
|
||||||
publishedRooms = append(publishedRooms, room.ID)
|
publishedRooms = append(publishedRooms, room.ID)
|
||||||
|
|
@ -69,9 +71,9 @@ func TestPublishedTable(t *testing.T) {
|
||||||
|
|
||||||
// test an actual upsert
|
// test an actual upsert
|
||||||
room := test.NewRoom(t, alice)
|
room := test.NewRoom(t, alice)
|
||||||
err = tab.UpsertRoomPublished(ctx, nil, room.ID, true)
|
err = tab.UpsertRoomPublished(ctx, nil, room.ID, asID, nwID, true)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = tab.UpsertRoomPublished(ctx, nil, room.ID, false)
|
err = tab.UpsertRoomPublished(ctx, nil, room.ID, asID, nwID, false)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// should now be false, due to the upsert
|
// should now be false, due to the upsert
|
||||||
publishedRes, err := tab.SelectPublishedFromRoomID(ctx, nil, room.ID)
|
publishedRes, err := tab.SelectPublishedFromRoomID(ctx, nil, room.ID)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue