Allow passing AppserviceID and NetworkID as parameters

This commit is contained in:
Till Faelligen 2022-10-27 09:23:37 +02:00
parent 4378b529e3
commit 7ea8e83387
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E
8 changed files with 18 additions and 14 deletions

View file

@ -168,8 +168,10 @@ type PerformBackfillResponse struct {
}
type PerformPublishRequest struct {
RoomID string
Visibility string
RoomID string
Visibility string
AppserviceID string
NetworkID string
}
type PerformPublishResponse struct {

View file

@ -30,7 +30,7 @@ func (r *Publisher) PerformPublish(
req *api.PerformPublishRequest,
res *api.PerformPublishResponse,
) 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 {
res.Error = &api.PerformError{
Msg: err.Error(),

View file

@ -139,7 +139,7 @@ type Database interface {
// Returns an error if the retrieval went wrong.
EventsFromIDs(ctx context.Context, eventIDs []string) ([]types.Event, error)
// 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.
GetPublishedRooms(ctx context.Context) ([]string, error)
// Returns whether a given room is published or not.

View file

@ -79,10 +79,10 @@ func PreparePublishedTable(db *sql.DB) (tables.Published, error) {
}
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) {
stmt := sqlutil.TxStmt(txn, s.upsertPublishedStmt)
_, err = stmt.ExecContext(ctx, roomID, "", "", published)
_, err = stmt.ExecContext(ctx, roomID, appserviceID, networkID, published)
return
}

View file

@ -722,9 +722,9 @@ func (d *Database) storeEvent(
}, 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.PublishedTable.UpsertRoomPublished(ctx, txn, roomID, publish)
return d.PublishedTable.UpsertRoomPublished(ctx, txn, roomID, appserviceID, networkID, publish)
})
}

View file

@ -82,10 +82,10 @@ func PreparePublishedTable(db *sql.DB) (tables.Published, error) {
}
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 {
stmt := sqlutil.TxStmt(txn, s.upsertPublishedStmt)
_, err := stmt.ExecContext(ctx, roomID, "", "", published)
_, err := stmt.ExecContext(ctx, roomID, appserviceID, networkID, published)
return err
}

View file

@ -146,7 +146,7 @@ type Membership 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)
SelectAllPublishedRooms(ctx context.Context, txn *sql.Tx, published bool) ([]string, error)
}

View file

@ -48,10 +48,12 @@ func TestPublishedTable(t *testing.T) {
// Publish some rooms
publishedRooms := []string{}
asID := ""
nwID := ""
for i := 0; i < 10; i++ {
room := test.NewRoom(t, alice)
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)
if published {
publishedRooms = append(publishedRooms, room.ID)
@ -69,9 +71,9 @@ func TestPublishedTable(t *testing.T) {
// test an actual upsert
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)
err = tab.UpsertRoomPublished(ctx, nil, room.ID, false)
err = tab.UpsertRoomPublished(ctx, nil, room.ID, asID, nwID, false)
assert.NoError(t, err)
// should now be false, due to the upsert
publishedRes, err := tab.SelectPublishedFromRoomID(ctx, nil, room.ID)