mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Implement /joined_rooms (#911)
* Implemented /joined_rooms * Removed account endpoint added by mistake * trigger ci
This commit is contained in:
parent
ec38783192
commit
dc06c69887
9 changed files with 112 additions and 2 deletions
|
@ -33,6 +33,7 @@ type Database interface {
|
|||
CreateGuestAccount(ctx context.Context) (*authtypes.Account, error)
|
||||
UpdateMemberships(ctx context.Context, eventsToAdd []gomatrixserverlib.Event, idsToRemove []string) error
|
||||
GetMembershipInRoomByLocalpart(ctx context.Context, localpart, roomID string) (authtypes.Membership, error)
|
||||
GetRoomIDsByLocalPart(ctx context.Context, localpart string) ([]string, error)
|
||||
GetMembershipsByLocalpart(ctx context.Context, localpart string) (memberships []authtypes.Membership, err error)
|
||||
SaveAccountData(ctx context.Context, localpart, roomID, dataType, content string) error
|
||||
GetAccountData(ctx context.Context, localpart string) (global []gomatrixserverlib.ClientEvent, rooms map[string][]gomatrixserverlib.ClientEvent, err error)
|
||||
|
|
|
@ -53,6 +53,9 @@ const selectMembershipsByLocalpartSQL = "" +
|
|||
const selectMembershipInRoomByLocalpartSQL = "" +
|
||||
"SELECT event_id FROM account_memberships WHERE localpart = $1 AND room_id = $2"
|
||||
|
||||
const selectRoomIDsByLocalPartSQL = "" +
|
||||
"SELECT room_id FROM account_memberships WHERE localpart = $1"
|
||||
|
||||
const deleteMembershipsByEventIDsSQL = "" +
|
||||
"DELETE FROM account_memberships WHERE event_id = ANY($1)"
|
||||
|
||||
|
@ -61,6 +64,7 @@ type membershipStatements struct {
|
|||
insertMembershipStmt *sql.Stmt
|
||||
selectMembershipInRoomByLocalpartStmt *sql.Stmt
|
||||
selectMembershipsByLocalpartStmt *sql.Stmt
|
||||
selectRoomIDsByLocalPartStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func (s *membershipStatements) prepare(db *sql.DB) (err error) {
|
||||
|
@ -80,6 +84,9 @@ func (s *membershipStatements) prepare(db *sql.DB) (err error) {
|
|||
if s.selectMembershipsByLocalpartStmt, err = db.Prepare(selectMembershipsByLocalpartSQL); err != nil {
|
||||
return
|
||||
}
|
||||
if s.selectRoomIDsByLocalPartStmt, err = db.Prepare(selectRoomIDsByLocalPartSQL); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -131,3 +138,23 @@ func (s *membershipStatements) selectMembershipsByLocalpart(
|
|||
}
|
||||
return memberships, rows.Err()
|
||||
}
|
||||
|
||||
func (s *membershipStatements) selectRoomIDsByLocalPart(
|
||||
ctx context.Context, localPart string,
|
||||
) ([]string, error) {
|
||||
stmt := s.selectRoomIDsByLocalPartStmt
|
||||
rows, err := stmt.QueryContext(ctx, localPart)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
roomIDs := []string{}
|
||||
defer rows.Close() // nolint: errcheck
|
||||
for rows.Next() {
|
||||
var roomID string
|
||||
if err = rows.Scan(&roomID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
roomIDs = append(roomIDs, roomID)
|
||||
}
|
||||
return roomIDs, rows.Err()
|
||||
}
|
||||
|
|
|
@ -234,6 +234,16 @@ func (d *Database) GetMembershipInRoomByLocalpart(
|
|||
return d.memberships.selectMembershipInRoomByLocalpart(ctx, localpart, roomID)
|
||||
}
|
||||
|
||||
// GetRoomIDsByLocalPart returns an array containing the room ids of all
|
||||
// the rooms a user matching a given localpart is a member of
|
||||
// If no membership match the given localpart, returns an empty array
|
||||
// If there was an issue during the retrieval, returns the SQL error
|
||||
func (d *Database) GetRoomIDsByLocalPart(
|
||||
ctx context.Context, localpart string,
|
||||
) ([]string, error) {
|
||||
return d.memberships.selectRoomIDsByLocalPart(ctx, localpart)
|
||||
}
|
||||
|
||||
// GetMembershipsByLocalpart returns an array containing the memberships for all
|
||||
// the rooms a user matching a given localpart is a member of
|
||||
// If no membership match the given localpart, returns an empty array
|
||||
|
|
|
@ -51,6 +51,9 @@ const selectMembershipsByLocalpartSQL = "" +
|
|||
const selectMembershipInRoomByLocalpartSQL = "" +
|
||||
"SELECT event_id FROM account_memberships WHERE localpart = $1 AND room_id = $2"
|
||||
|
||||
const selectRoomIDsByLocalPartSQL = "" +
|
||||
"SELECT room_id FROM account_memberships WHERE localpart = $1"
|
||||
|
||||
const deleteMembershipsByEventIDsSQL = "" +
|
||||
"DELETE FROM account_memberships WHERE event_id IN ($1)"
|
||||
|
||||
|
@ -58,6 +61,7 @@ type membershipStatements struct {
|
|||
insertMembershipStmt *sql.Stmt
|
||||
selectMembershipInRoomByLocalpartStmt *sql.Stmt
|
||||
selectMembershipsByLocalpartStmt *sql.Stmt
|
||||
selectRoomIDsByLocalPartStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func (s *membershipStatements) prepare(db *sql.DB) (err error) {
|
||||
|
@ -74,6 +78,9 @@ func (s *membershipStatements) prepare(db *sql.DB) (err error) {
|
|||
if s.selectMembershipsByLocalpartStmt, err = db.Prepare(selectMembershipsByLocalpartSQL); err != nil {
|
||||
return
|
||||
}
|
||||
if s.selectRoomIDsByLocalPartStmt, err = db.Prepare(selectRoomIDsByLocalPartSQL); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -130,3 +137,22 @@ func (s *membershipStatements) selectMembershipsByLocalpart(
|
|||
|
||||
return
|
||||
}
|
||||
func (s *membershipStatements) selectRoomIDsByLocalPart(
|
||||
ctx context.Context, localPart string,
|
||||
) ([]string, error) {
|
||||
stmt := s.selectRoomIDsByLocalPartStmt
|
||||
rows, err := stmt.QueryContext(ctx, localPart)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
roomIDs := []string{}
|
||||
defer rows.Close() // nolint: errcheck
|
||||
for rows.Next() {
|
||||
var roomID string
|
||||
if err = rows.Scan(&roomID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
roomIDs = append(roomIDs, roomID)
|
||||
}
|
||||
return roomIDs, rows.Err()
|
||||
}
|
||||
|
|
|
@ -253,6 +253,16 @@ func (d *Database) GetMembershipsByLocalpart(
|
|||
return d.memberships.selectMembershipsByLocalpart(ctx, localpart)
|
||||
}
|
||||
|
||||
// GetRoomIDsByLocalPart returns an array containing the room ids of all
|
||||
// the rooms a user matching a given localpart is a member of
|
||||
// If no membership match the given localpart, returns an empty array
|
||||
// If there was an issue during the retrieval, returns the SQL error
|
||||
func (d *Database) GetRoomIDsByLocalPart(
|
||||
ctx context.Context, localpart string,
|
||||
) ([]string, error) {
|
||||
return d.memberships.selectRoomIDsByLocalPart(ctx, localpart)
|
||||
}
|
||||
|
||||
// newMembership saves a new membership in the database.
|
||||
// If the event isn't a valid m.room.member event with type `join`, does nothing.
|
||||
// If an error occurred, returns the SQL error
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue