mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-10 16:33:11 -06:00
Support visibility update and retrieval
This commit is contained in:
parent
4ff7c33e05
commit
9a96f94918
|
|
@ -64,6 +64,10 @@ const selectPublicRoomswithLimitSQL = "" +
|
|||
" ORDER BY joined_members DESC" +
|
||||
" OFFSET $1 LIMIT $2"
|
||||
|
||||
const selectRoomVisibilitySQL = "" +
|
||||
"SELECT visibility FROM publicroomsapi_public_rooms" +
|
||||
" WHERE room_id = $1"
|
||||
|
||||
const insertNewRoomSQL = "" +
|
||||
"INSERT INTO publicroomsapi_public_rooms(room_id)" +
|
||||
" VALUES ($1)"
|
||||
|
|
@ -87,6 +91,7 @@ type publicRoomsStatements struct {
|
|||
countPublicRoomsStmt *sql.Stmt
|
||||
selectPublicRoomsStmt *sql.Stmt
|
||||
selectPublicRoomswithLimitStmt *sql.Stmt
|
||||
selectRoomVisibilityStmt *sql.Stmt
|
||||
insertNewRoomStmt *sql.Stmt
|
||||
incrementJoinedMembersInRoomStmt *sql.Stmt
|
||||
decrementJoinedMembersInRoomStmt *sql.Stmt
|
||||
|
|
@ -107,6 +112,9 @@ func (s *publicRoomsStatements) prepare(db *sql.DB) (err error) {
|
|||
if s.selectPublicRoomswithLimitStmt, err = db.Prepare(selectPublicRoomswithLimitSQL); err != nil {
|
||||
return
|
||||
}
|
||||
if s.selectRoomVisibilityStmt, err = db.Prepare(selectRoomVisibilitySQL); err != nil {
|
||||
return
|
||||
}
|
||||
if s.insertNewRoomStmt, err = db.Prepare(insertNewRoomSQL); err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -165,6 +173,11 @@ func (s *publicRoomsStatements) selectPublicRooms(offset int64, limit int16) ([]
|
|||
return rooms, nil
|
||||
}
|
||||
|
||||
func (s *publicRoomsStatements) selectRoomVisibility(roomID string) (v bool, err error) {
|
||||
err = s.selectRoomVisibilityStmt.QueryRow(roomID).Scan(&v)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *publicRoomsStatements) insertNewRoom(roomID string) error {
|
||||
_, err := s.insertNewRoomStmt.Exec(roomID)
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
// PublicRoomsServerDatabase represents a public rooms server database
|
||||
// PublicRoomsServerDatabase represents a public rooms server database.
|
||||
type PublicRoomsServerDatabase struct {
|
||||
db *sql.DB
|
||||
partitions common.PartitionOffsetStatements
|
||||
|
|
@ -33,7 +33,7 @@ type PublicRoomsServerDatabase struct {
|
|||
|
||||
type attributeValue interface{}
|
||||
|
||||
// NewPublicRoomsServerDatabase creates a new public rooms server database
|
||||
// NewPublicRoomsServerDatabase creates a new public rooms server database.
|
||||
func NewPublicRoomsServerDatabase(dataSourceName string) (*PublicRoomsServerDatabase, error) {
|
||||
var db *sql.DB
|
||||
var err error
|
||||
|
|
@ -51,6 +51,20 @@ func NewPublicRoomsServerDatabase(dataSourceName string) (*PublicRoomsServerData
|
|||
return &PublicRoomsServerDatabase{db, partitions, statements}, nil
|
||||
}
|
||||
|
||||
// GetRoomVisibility returns the room visibility as a boolean: true if the room
|
||||
// is publicly visible, false if not.
|
||||
// Returns an error if the retrieval failed.
|
||||
func (d *PublicRoomsServerDatabase) GetRoomVisibility(roomID string) (bool, error) {
|
||||
return d.statements.selectRoomVisibility(roomID)
|
||||
}
|
||||
|
||||
// SetRoomVisibility updates the visibility attribute of a room. This attribute
|
||||
// must be set to true if the room is publicly visible, false if not.
|
||||
// Returns an error if the update failed.
|
||||
func (d *PublicRoomsServerDatabase) SetRoomVisibility(visible bool, roomID string) error {
|
||||
return d.statements.updateRoomAttribute("visibility", visible, roomID)
|
||||
}
|
||||
|
||||
// CountPublicRooms returns the number of room set as publicly visible on the server.
|
||||
// Returns an error if the retrieval failed.
|
||||
func (d *PublicRoomsServerDatabase) CountPublicRooms() (int64, error) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue