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

Chore: Migrate lib/rocketchat.js to TS - structure PoC #3661

Merged
merged 29 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 Jan 27, 2022
f753daa
move methods to rocketchat/methods
gerzonc Jan 27, 2022
e73d72f
update rocketchat.js imports
gerzonc Jan 27, 2022
1308354
update sdk.ts
gerzonc Jan 27, 2022
58704fe
fix rocketchat imports
gerzonc Jan 27, 2022
46e637d
Fix rocketchat.js imports
gerzonc Jan 27, 2022
0f958ad
undo changes to methods folder
gerzonc Jan 28, 2022
15ccc45
Dehydrate some non-server methods, update interfaces and refactor new…
gerzonc Jan 28, 2022
e6f39bc
remove dehydrated functions from rocketchat/index.js
gerzonc Jan 28, 2022
9d6719c
minor tweak
gerzonc Jan 28, 2022
7cf8944
fix imports
gerzonc Jan 28, 2022
1eda41a
remove changes from rocketchat.js
gerzonc Jan 28, 2022
40e667b
update structure
gerzonc Jan 31, 2022
700c667
update imports for rocketchat.js
gerzonc Jan 31, 2022
b859c1c
Merge branch 'develop' into chore.migrate-rocketchatjs-to-ts-poc
diegolmello Feb 1, 2022
9277f55
Few fixes
diegolmello Feb 1, 2022
7d15747
Fix sdk
gerzonc Feb 8, 2022
8a3655f
Create sdk.initialize
diegolmello Feb 8, 2022
fde84e2
Clean up
diegolmello Feb 8, 2022
1a5ee33
Add sdk.disconnect()
diegolmello Feb 8, 2022
fa7611d
Remove unnecessary `public`
diegolmello Feb 8, 2022
d8b44ba
post and methodCall
diegolmello Feb 8, 2022
fb56b1c
Add methodCallWrapper
diegolmello Feb 8, 2022
50acb15
Actually use isGroupChat refactor
diegolmello Feb 9, 2022
a385866
Merge branch 'develop' into chore.migrate-rocketchatjs-to-ts-poc
diegolmello Feb 9, 2022
7fc0948
Lint
diegolmello Feb 9, 2022
36fe961
Remove unnecessary return types
diegolmello Feb 9, 2022
a5404f0
Merge branch 'develop' into chore.migrate-rocketchatjs-to-ts-poc
dnlsilva Feb 9, 2022
ea427ed
Merge branch 'develop' into chore.migrate-rocketchatjs-to-ts-poc
diegolmello Feb 10, 2022
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
2 changes: 1 addition & 1 deletion app/definitions/IServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface IServer {
useRealName: boolean;
FileUpload_MediaTypeWhiteList: string;
FileUpload_MaxFileSize: number;
roomsUpdatedAt: Date;
roomsUpdatedAt: Date | null;
version: string;
lastLocalAuthenticatedSession: Date;
autoLock: boolean;
Expand Down
8 changes: 4 additions & 4 deletions app/definitions/ITeam.ts
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
}
4 changes: 4 additions & 0 deletions app/lib/rocketchat/index.ts
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;
23 changes: 23 additions & 0 deletions app/lib/rocketchat/methods/clearCache.ts
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
}
}
24 changes: 24 additions & 0 deletions app/lib/rocketchat/methods/getPermalinkMessage.ts
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}`;
}
12 changes: 12 additions & 0 deletions app/lib/rocketchat/methods/getRoom.ts
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'));
}
}
5 changes: 5 additions & 0 deletions app/lib/rocketchat/methods/isGroupChat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ISubscription, TSubscriptionModel } from '../../../definitions';

export default function isGroupChat(room: ISubscription | TSubscriptionModel): boolean {
return ((room.uids && room.uids.length > 2) || (room.usernames && room.usernames.length > 2)) ?? false;
}
Loading