Skip to content

Commit

Permalink
Merge pull request #131 from linagora/client-server/sync
Browse files Browse the repository at this point in the history
Client server : implementing filters
  • Loading branch information
guimard authored Jul 23, 2024
2 parents bffa57f + 86ea1fa commit c558216
Show file tree
Hide file tree
Showing 13 changed files with 1,862 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
jsonContent,
send,
validateParameters,
type expressAppHandler
type expressAppHandler,
clientSecretRegex,
validCountryRegex,
validPhoneNumberRegex
} from '@twake/utils'
import type MatrixClientServer from '../../../index'
import SmsSender from '../../../utils/smsSender'
Expand Down Expand Up @@ -36,10 +39,6 @@ const schema = {
id_server: false,
id_access_token: false
}

const clientSecretRegex = /^[0-9a-zA-Z.=_-]{6,255}$/
const validCountryRegex = /^[A-Z]{2}$/ // ISO 3166-1 alpha-2 as per the spec : https://spec.matrix.org/v1.11/client-server-api/#post_matrixclientv3registermsisdnrequesttoken
const validPhoneNumberRegex = /^[1-9]\d{1,14}$/
const maxAttemps = 1000000000

const RequestToken = (clientServer: MatrixClientServer): expressAppHandler => {
Expand Down
10 changes: 7 additions & 3 deletions packages/matrix-client-server/src/presence/getStatus.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type MatrixClientServer from '..'
import { errMsg, type expressAppHandler, send, epoch } from '@twake/utils'

const matrixIdRegex = /^@[0-9a-zA-Z._=-]+:[0-9a-zA-Z.-]+$/
import {
errMsg,
type expressAppHandler,
send,
epoch,
matrixIdRegex
} from '@twake/utils'

// TODO : Handle error 403 where the user isn't allowed to see this user's presence status, may have to do with the "users_to_send_full_presence_to" table in the matrixDb
const getStatus = (clientServer: MatrixClientServer): expressAppHandler => {
Expand Down
5 changes: 2 additions & 3 deletions packages/matrix-client-server/src/presence/putStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
validateParameters,
errMsg,
type expressAppHandler,
send
send,
matrixIdRegex
} from '@twake/utils'

interface PutRequestBody {
Expand All @@ -16,8 +17,6 @@ const schema = {
presence: true,
status_msg: false
}

const matrixIdRegex = /^@[0-9a-zA-Z._=-]+:[0-9a-zA-Z.-]+$/
const statusMsgRegex = /^.{0,2048}$/

// If status message is longer than 2048 characters, we refuse it to prevent clients from sending too long messages that could crash the DB. This value is arbitrary and could be changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
jsonContent,
send,
validateParameters,
type expressAppHandler
type expressAppHandler,
clientSecretRegex,
validCountryRegex,
validPhoneNumberRegex
} from '@twake/utils'
import type MatrixClientServer from '../../index'
import SmsSender from '../../utils/smsSender'
Expand All @@ -33,10 +36,6 @@ const schema = {
id_server: false,
id_access_token: false
}

const clientSecretRegex = /^[0-9a-zA-Z.=_-]{6,255}$/
const validCountryRegex = /^[A-Z]{2}$/ // ISO 3166-1 alpha-2 as per the spec : https://spec.matrix.org/v1.11/client-server-api/#post_matrixclientv3registermsisdnrequesttoken
const validPhoneNumberRegex = /^[1-9]\d{1,14}$/
const maxAttemps = 1000000000

export const formatPhoneNumber = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import type MatrixClientServer from '../..'
import { errMsg, type expressAppHandler, send } from '@twake/utils'
import {
errMsg,
type expressAppHandler,
send,
matrixIdRegex,
eventTypeRegex
} from '@twake/utils'

interface Parameters {
userId: string
type: string
}

const matrixIdRegex = /^@[0-9a-zA-Z._=-]+:[0-9a-zA-Z.-]+$/
const eventTypeRegex = /^(?:[a-z]+(?:\.[a-z][a-z0-9]*)*)$/ // Following Java's package naming convention as per : https://spec.matrix.org/v1.11/#events

const getAccountData = (
clientServer: MatrixClientServer
): expressAppHandler => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
validateParameters,
errMsg,
type expressAppHandler,
send
send,
matrixIdRegex,
eventTypeRegex
} from '@twake/utils'

interface Parameters {
Expand All @@ -19,9 +21,6 @@ interface PutRequestBody {
const schema = {
content: true
}

const matrixIdRegex = /^@[0-9a-zA-Z._=-]+:[0-9a-zA-Z.-]+$/
const eventTypeRegex = /^(?:[a-z]+(?:\.[a-z][a-z0-9]*)*)$/ // Following Java's package naming convention as per : https://spec.matrix.org/v1.11/#events
const contentRegex = /^.{0,2048}$/ // Prevent the client from sending too long messages that could crash the DB. This value is arbitrary and could be changed

const putAccountData = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import type MatrixClientServer from '../..'
import { errMsg, type expressAppHandler, send } from '@twake/utils'
import {
errMsg,
type expressAppHandler,
send,
matrixIdRegex,
eventTypeRegex,
roomIdRegex
} from '@twake/utils'

interface Parameters {
userId: string
type: string
roomId: string
}

const matrixIdRegex = /^@[0-9a-zA-Z._=-]+:[0-9a-zA-Z.-]+$/
const eventTypeRegex = /^(?:[a-z]+(?:\.[a-z][a-z0-9]*)*)$/ // Following Java's package naming convention as per : https://spec.matrix.org/v1.11/#events
const roomIdRegex = /^![0-9a-zA-Z._=/+-]+:[0-9a-zA-Z.-]+$/ // From : https://spec.matrix.org/v1.11/#room-structure

const getRoomAccountData = (
clientServer: MatrixClientServer
): expressAppHandler => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
validateParameters,
errMsg,
type expressAppHandler,
send
send,
matrixIdRegex,
eventTypeRegex,
roomIdRegex
} from '@twake/utils'

interface Parameters {
Expand All @@ -21,9 +24,6 @@ const schema = {
content: true
}

const matrixIdRegex = /^@[0-9a-zA-Z._=-]+:[0-9a-zA-Z.-]+$/
const eventTypeRegex = /^(?:[a-z]+(?:\.[a-z][a-z0-9]*)*)$/ // Following Java's package naming convention as per : https://spec.matrix.org/v1.11/#events
const roomIdRegex = /^![0-9a-zA-Z._=/+-]+:[0-9a-zA-Z.-]+$/ // From : https://spec.matrix.org/v1.11/#room-structure
const contentRegex = /^.{0,2048}$/ // Prevent the client from sending too long messages that could crash the DB. This value is arbitrary and could be changed

// TODO : Handle error 405 where the type of account data is controlled by the server and cannot be modified by the client
Expand Down
Loading

0 comments on commit c558216

Please sign in to comment.