Skip to content

Commit

Permalink
🐛 fix: room creation payload
Browse files Browse the repository at this point in the history
  • Loading branch information
rezk2ll committed Jan 10, 2025
1 parent 6210257 commit 576f464
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
41 changes: 18 additions & 23 deletions packages/tom-server/src/invitation-api/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class InvitationService implements IInvitationService {
authorization: string
): Promise<void> => {
try {
const room_id = await this._createPrivateRoom(payload, authorization)
const room_id = await this._createPrivateRoom(authorization)

if (!room_id) {
throw Error('Failed to create room')
Expand Down Expand Up @@ -84,7 +84,7 @@ export default class InvitationService implements IInvitationService {

if (!room_id) {
const payload = { medium, recepient, sender }
room_id = await this._createPrivateRoom(payload, authorization)
room_id = await this._createPrivateRoom(authorization)

if (!room_id) {
throw Error('Failed to create room')
Expand Down Expand Up @@ -154,7 +154,6 @@ export default class InvitationService implements IInvitationService {
* @returns {Promise<string>} - Room ID
*/
private _createPrivateRoom = async (
payload: InvitationPayload,
authorization: string
): Promise<string> => {
try {
Expand All @@ -167,13 +166,6 @@ export default class InvitationService implements IInvitationService {
Authorization: authorization
},
body: JSON.stringify({
invite_3pid: [
{
id_server: this.config.base_url,
medium: payload.medium,
address: payload.recepient
}
],
is_direct: true,
preset: 'private_chat'
} satisfies RoomCreationPayload)
Expand Down Expand Up @@ -261,19 +253,22 @@ export default class InvitationService implements IInvitationService {
room_id: string
) => {
try {
await fetch(`https://${this.config.matrix_server}/${this.MATRIX_INVITE_PATH}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: authorization
},
body: JSON.stringify({
medium: payload.medium,
address: payload.recepient,
sender: payload.sender,
room_id
})
})
await fetch(
`https://${this.config.matrix_server}/${this.MATRIX_INVITE_PATH}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: authorization
},
body: JSON.stringify({
medium: payload.medium,
address: payload.recepient,
sender: payload.sender,
room_id
})
}
)
} catch (error) {
this.logger.error(`Failed to store matrix invite`, { error })

Expand Down
7 changes: 0 additions & 7 deletions packages/tom-server/src/invitation-api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,10 @@ export interface InsertInvitationPayload extends InvitationPayload {
}

export interface RoomCreationPayload {
invite_3pid: Invite3pid[]
is_direct: boolean
preset: 'private_chat' | 'public_chat' | 'trusted_private_chat'
}

export interface Invite3pid {
id_server: string
medium: medium
address: string
}

export interface RoomCreationResponse {
room_id: string
}

0 comments on commit 576f464

Please sign in to comment.