-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Chore: Migrate lib/rocketchat.js to TS - structure PoC #3661
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
7d61c6a
Update imports for rocketchat.js, create sdk.ts and dehydrate getUser…
gerzonc f753daa
move methods to rocketchat/methods
gerzonc e73d72f
update rocketchat.js imports
gerzonc 1308354
update sdk.ts
gerzonc 58704fe
fix rocketchat imports
gerzonc 46e637d
Fix rocketchat.js imports
gerzonc 0f958ad
undo changes to methods folder
gerzonc 15ccc45
Dehydrate some non-server methods, update interfaces and refactor new…
gerzonc e6f39bc
remove dehydrated functions from rocketchat/index.js
gerzonc 9d6719c
minor tweak
gerzonc 7cf8944
fix imports
gerzonc 1eda41a
remove changes from rocketchat.js
gerzonc 40e667b
update structure
gerzonc 700c667
update imports for rocketchat.js
gerzonc b859c1c
Merge branch 'develop' into chore.migrate-rocketchatjs-to-ts-poc
diegolmello 9277f55
Few fixes
diegolmello 7d15747
Fix sdk
gerzonc 8a3655f
Create sdk.initialize
diegolmello fde84e2
Clean up
diegolmello 1a5ee33
Add sdk.disconnect()
diegolmello fa7611d
Remove unnecessary `public`
diegolmello d8b44ba
post and methodCall
diegolmello fb56b1c
Add methodCallWrapper
diegolmello 50acb15
Actually use isGroupChat refactor
diegolmello a385866
Merge branch 'develop' into chore.migrate-rocketchatjs-to-ts-poc
diegolmello 7fc0948
Lint
diegolmello 36fe961
Remove unnecessary return types
diegolmello a5404f0
Merge branch 'develop' into chore.migrate-rocketchatjs-to-ts-poc
dnlsilva ea427ed
Merge branch 'develop' into chore.migrate-rocketchatjs-to-ts-poc
diegolmello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| // https://github.com/RocketChat/Rocket.Chat/blob/develop/definition/ITeam.ts | ||
| exports.TEAM_TYPE = { | ||
| PUBLIC: 0, | ||
| PRIVATE: 1 | ||
| }; | ||
| export enum TEAM_TYPE { | ||
| PUBLIC = 0, | ||
| PRIVATE = 1 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import RocketChat, { THEME_PREFERENCES_KEY, CRASH_REPORT_KEY, ANALYTICS_EVENTS_KEY } from './rocketchat'; | ||
|
|
||
| export { THEME_PREFERENCES_KEY, CRASH_REPORT_KEY, ANALYTICS_EVENTS_KEY }; | ||
| export default RocketChat; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import database from '../../database'; | ||
|
|
||
| export default async function clearCache({ server }: { server: string }): Promise<void> { | ||
| try { | ||
| const serversDB = database.servers; | ||
| await serversDB.write(async () => { | ||
| const serverCollection = serversDB.get('servers'); | ||
| const serverRecord = await serverCollection.find(server); | ||
| await serverRecord.update(s => { | ||
| s.roomsUpdatedAt = null; | ||
| }); | ||
| }); | ||
| } catch (e) { | ||
| // Do nothing | ||
| } | ||
|
|
||
| try { | ||
| const db = database.active; | ||
| await db.write(() => db.unsafeResetDatabase()); | ||
| } catch (e) { | ||
| // Do nothing | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import log from '../../../utils/log'; | ||
| import { TMessageModel, TSubscriptionModel } from '../../../definitions'; | ||
| import reduxStore from '../../createStore'; | ||
| import getRoom from './getRoom'; | ||
| import isGroupChat from './isGroupChat'; | ||
|
|
||
| type TRoomType = 'p' | 'c' | 'd'; | ||
|
|
||
| export default async function getPermalinkMessage(message: TMessageModel): Promise<string | null> { | ||
| let room: TSubscriptionModel; | ||
| try { | ||
| room = await getRoom(message.subscription.id); | ||
| } catch (e) { | ||
| log(e); | ||
| return null; | ||
| } | ||
| const { server } = reduxStore.getState().server; | ||
| const roomType = { | ||
| p: 'group', | ||
| c: 'channel', | ||
| d: 'direct' | ||
| }[room.t as TRoomType]; | ||
| return `${server}/${roomType}/${isGroupChat(room) ? room.rid : room.name}?msg=${message.id}`; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { TSubscriptionModel } from '../../../definitions'; | ||
| import database from '../../database'; | ||
|
|
||
| export default async function getRoom(rid: string): Promise<TSubscriptionModel> { | ||
| try { | ||
| const db = database.active; | ||
| const room = await db.get('subscriptions').find(rid); | ||
| return Promise.resolve(room); | ||
| } catch (error) { | ||
| return Promise.reject(new Error('Room not found')); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { ISubscription } from '../../../definitions'; | ||
|
|
||
| export default function isGroupChat(room: ISubscription): boolean | undefined { | ||
| return (room.uids && room.uids.length > 2) || (room.usernames && room.usernames.length > 2); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import sdk from './sdk'; | ||
|
|
||
| export default function getUserInfo(userId: string): Promise<unknown> { | ||
| // RC 0.48.0 | ||
| return sdk.get('users.info', { userId }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { Rocketchat } from '@rocket.chat/sdk'; | ||
|
|
||
| import store from '../../createStore'; | ||
| import { useSsl } from '../../../utils/url'; | ||
|
|
||
| class Sdk { | ||
| public get(...args: any[]): Promise<unknown> { | ||
| const { server } = store.getState().server; | ||
| const sdk = new Rocketchat({ host: server, protocol: 'ddp', useSsl: useSsl(server) }); | ||
| return sdk.get(...args); | ||
| } | ||
|
|
||
| public post(...args: any[]): Promise<unknown> { | ||
| const { server } = store.getState().server; | ||
| const sdk = new Rocketchat({ host: server, protocol: 'ddp', useSsl: useSsl(server) }); | ||
| return sdk.post(...args); | ||
| } | ||
|
|
||
| public methodCallWrapper(...args: any[]): Promise<unknown> { | ||
| const { server } = store.getState().server; | ||
| const sdk = new Rocketchat({ host: server, protocol: 'ddp', useSsl: useSsl(server) }); | ||
| return sdk.methodCall(...args); | ||
| } | ||
| } | ||
|
|
||
| const sdk = new Sdk(); | ||
|
|
||
| export default sdk; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.