Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matrix: Add room retention policy #2040

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/matrix/docker/synapse/dev/homeserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ log_config: "/data/log.config"
presence:
enabled: false

retention:
enabled: true

rc_messages_per_second: 10000
rc_message_burst_count: 10000
rc_registration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ database:

log_config: "/data/log.config"

retention:
enabled: true

rc_messages_per_second: 10000
rc_message_burst_count: 10000
rc_registration:
Expand Down
3 changes: 3 additions & 0 deletions packages/matrix/docker/synapse/test/homeserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ log_config: "/data/log.config"
presence:
enabled: false

retention:
enabled: true

rc_messages_per_second: 10000
rc_message_burst_count: 10000
rc_registration:
Expand Down
36 changes: 36 additions & 0 deletions packages/runtime-common/matrix-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,45 @@ export class MatrixClient {
} - ${JSON.stringify(json)}`,
);
}

await this.setRoomRetentionPolicy(json.room_id, 60 * 60 * 1000);

return json.room_id;
}

async setRoomRetentionPolicy(roomId: string, maxLifetimeMs: number) {
let roomState = await this.request(
`_matrix/client/v3/rooms/${roomId}/state`,
);

let roomStateJson = await roomState.json();
console.log('roomState', roomStateJson);
try {
let retentionState = roomStateJson.find(
(event) => event.type === 'm.room.retention',
);

let retentionStateKey = retentionState?.content.key ?? '';

let retentionUpdateResponse = await this.request(
`_matrix/client/v3/rooms/${roomId}/state/m.room.retention/${retentionStateKey}`,
'PUT',
{
body: JSON.stringify({ max_lifetime: maxLifetimeMs }),
},
);

console.log('retention update ok?', retentionUpdateResponse.ok);

console.log(
'retentionUpdateResponse',
await retentionUpdateResponse.json(),
);
} catch (e) {
console.error('error setting retention policy', e);
}
}

async setAccountData<T>(type: string, data: T) {
let response = await this.request(
`_matrix/client/v3/user/${encodeURIComponent(
Expand Down
Loading