mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 01:13:10 -06:00
Use the invite table to list the active invites for a user
This commit is contained in:
parent
37fcb77768
commit
ddd9841cb2
|
|
@ -140,7 +140,10 @@ func (s *currentRoomStateStatements) selectJoinedUsers(
|
|||
|
||||
// SelectRoomIDsWithMembership returns the list of room IDs which have the given user in the given membership state.
|
||||
func (s *currentRoomStateStatements) selectRoomIDsWithMembership(
|
||||
ctx context.Context, txn *sql.Tx, userID, membership string,
|
||||
ctx context.Context,
|
||||
txn *sql.Tx,
|
||||
userID string,
|
||||
membership string, // nolint: unparam
|
||||
) ([]string, error) {
|
||||
stmt := common.TxStmt(txn, s.selectRoomIDsWithMembershipStmt)
|
||||
rows, err := stmt.QueryContext(ctx, userID, membership)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
|
|
@ -67,11 +69,10 @@ func (s *inviteEventsStatements) insertInviteEvent(
|
|||
// selectInviteEventsInRange returns a map of room ID to invite event for the
|
||||
// active invites for the target user ID in the supplied range.
|
||||
func (s *inviteEventsStatements) selectInviteEventsInRange(
|
||||
ctx context.Context, targetUserID string, startPos, endPos int64,
|
||||
ctx context.Context, txn *sql.Tx, targetUserID string, startPos, endPos int64,
|
||||
) (map[string]gomatrixserverlib.Event, error) {
|
||||
rows, err := s.selectInviteEventsInRangeStmt.QueryContext(
|
||||
ctx, targetUserID, startPos, endPos,
|
||||
)
|
||||
stmt := common.TxStmt(txn, s.selectInviteEventsInRangeStmt)
|
||||
rows, err := stmt.QueryContext(ctx, targetUserID, startPos, endPos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -367,16 +367,20 @@ func (d *SyncServerDatabase) UpsertAccountData(
|
|||
func (d *SyncServerDatabase) addInvitesToResponse(
|
||||
ctx context.Context, txn *sql.Tx,
|
||||
userID string,
|
||||
_, _ types.StreamPosition,
|
||||
fromPos, toPos types.StreamPosition,
|
||||
res *types.Response,
|
||||
) error {
|
||||
// Add invites - TODO: This will break over federation as they won't be in the current state table according to Mark.
|
||||
roomIDs, err := d.roomstate.selectRoomIDsWithMembership(ctx, txn, userID, "invite")
|
||||
invites, err := d.invites.selectInviteEventsInRange(
|
||||
ctx, txn, userID, int64(fromPos), int64(toPos),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, roomID := range roomIDs {
|
||||
for roomID, inviteEvent := range invites {
|
||||
ir := types.NewInviteResponse()
|
||||
ir.InviteState.Events = gomatrixserverlib.ToClientEvents(
|
||||
[]gomatrixserverlib.Event{inviteEvent}, gomatrixserverlib.FormatSync,
|
||||
)
|
||||
// TODO: invite_state. The state won't be in the current state table in cases where you get invited over federation
|
||||
res.Rooms.Invite[roomID] = *ir
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue