( serverPrefixID: string, outputValidator: TType<T>, data: T, )
| 33 | } |
| 34 | |
| 35 | function convertClientIDsToServerIDs<T>( |
| 36 | serverPrefixID: string, |
| 37 | outputValidator: TType<T>, |
| 38 | data: T, |
| 39 | ): T { |
| 40 | const prefix = serverPrefixID + '|'; |
| 41 | const conversionFunction = (id: string) => { |
| 42 | if (id.startsWith(prefix)) { |
| 43 | return id.substr(prefix.length); |
| 44 | } |
| 45 | |
| 46 | const pendingIDContents = parsePendingThreadID(id); |
| 47 | if (!pendingIDContents) { |
| 48 | throw new Error('invalid_client_id_prefix'); |
| 49 | } |
| 50 | |
| 51 | if (!pendingIDContents.sourceMessageID) { |
| 52 | return id; |
| 53 | } |
| 54 | |
| 55 | return getPendingThreadID( |
| 56 | pendingIDContents.threadType, |
| 57 | pendingIDContents.memberIDs, |
| 58 | pendingIDContents.sourceMessageID.substr(prefix.length), |
| 59 | ); |
| 60 | }; |
| 61 | |
| 62 | return convertObject(outputValidator, data, [tID], conversionFunction); |
| 63 | } |
| 64 | |
| 65 | function extractUserIDsFromPayload<T>( |
| 66 | outputValidator: TType<T>, |
no test coverage detected