Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b0b62af
Chore: Migrate Utils Folder to TS
reinaldonetof Dec 6, 2021
ee6be6c
avatar and twofactor
reinaldonetof Dec 6, 2021
498f009
debounce
reinaldonetof Dec 7, 2021
c680806
deviceInfo and isValidEmail
reinaldonetof Dec 7, 2021
2d25f76
events, fetch, goRoom, isReadOnly, layoutAnimation, media, messageTyp…
reinaldonetof Dec 7, 2021
844427c
moment, openLink, random, review, room, server, theme, fix externalMo…
reinaldonetof Dec 7, 2021
3296798
sslPinning, deleted info and throttle
reinaldonetof Dec 8, 2021
a343bc0
info.ts and tweaks
reinaldonetof Dec 8, 2021
756a4e2
localAuthentication and his tweaks
reinaldonetof Dec 8, 2021
0e6d162
shortnameToUnicode and base64 folders
reinaldonetof Dec 8, 2021
e35d883
log folder
reinaldonetof Dec 9, 2021
67858df
fileUpload folder
reinaldonetof Dec 9, 2021
f8b992f
eslint disable at sendFileMessage
reinaldonetof Dec 9, 2021
ca64f94
fix log lint's errors
reinaldonetof Dec 9, 2021
ad92472
animation e conditional from navigation folder
reinaldonetof Dec 9, 2021
905de04
make ts happy on actionsheet folder
reinaldonetof Dec 9, 2021
6ddcc2f
Merge branch 'develop' into chore.ts-utils-folder
reinaldonetof Dec 9, 2021
039a203
minor tweaks
reinaldonetof Dec 9, 2021
690b500
minor tweak
reinaldonetof Dec 10, 2021
29ad0cf
minor tweak
reinaldonetof Dec 23, 2021
32f6498
tweaks
reinaldonetof Dec 23, 2021
af186df
minor tweaks
reinaldonetof Dec 23, 2021
f6efc61
minor tweak
reinaldonetof Dec 24, 2021
49536cb
Event tweak
reinaldonetof Dec 24, 2021
37c1bb0
Merge branch 'develop' into chore.ts-utils-folder
reinaldonetof Dec 24, 2021
b9c5447
minor tweak
AlexAlexandre Dec 28, 2021
de36f1e
change some interface's name
reinaldonetof Dec 28, 2021
e220512
theme preferences
reinaldonetof Dec 28, 2021
d68f55a
refactor tservermodel
reinaldonetof Dec 28, 2021
5ef5ec1
Merge branch 'develop' into chore.ts-utils-folder
AlexAlexandre Jan 11, 2022
234d154
refactor: update new types and interfaces for use ISubscription
AlexAlexandre Jan 11, 2022
55a7498
Merge branch 'develop' into chore.ts-utils-folder
diegolmello Jan 12, 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
3 changes: 2 additions & 1 deletion app/containers/ActionSheet/Button.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { TouchableOpacity } from 'react-native';

import { isAndroid } from '../../utils/deviceInfo';
import Touch from '../../utils/touch';

// Taken from https://github.com/rgommezz/react-native-scroll-bottom-sheet#touchables
export const Button = isAndroid ? Touch : TouchableOpacity;
export const Button: typeof React.Component = isAndroid ? Touch : TouchableOpacity;
13 changes: 7 additions & 6 deletions app/containers/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Touchable from 'react-native-platform-touchable';
import { settings as RocketChatSettings } from '@rocket.chat/sdk';

import { avatarURL } from '../../utils/avatar';
import { RoomType } from '../../definitions/IRoom';
import Emoji from '../markdown/Emoji';
import { IAvatar } from './interfaces';

Expand All @@ -27,7 +28,7 @@ const Avatar = React.memo(
text,
size = 25,
borderRadius = 4,
type = 'd'
type = RoomType.DIRECT
}: Partial<IAvatar>) => {
if ((!text && !avatar && !emoji && !rid) || !server) {
return null;
Expand Down Expand Up @@ -56,15 +57,15 @@ const Avatar = React.memo(
if (!isStatic) {
uri = avatarURL({
type,
text,
text: text!,
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
size,
user,
user: user!,
avatar,
server,
avatarETag,
serverVersion,
avatarETag: avatarETag!,
serverVersion: serverVersion!,
rid,
blockUnauthenticatedAccess
blockUnauthenticatedAccess: blockUnauthenticatedAccess!
});
}

Expand Down
2 changes: 0 additions & 2 deletions app/containers/MessageActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ const MessageActions = React.memo(
};

const handleDelete = (message: any) => {
// TODO - migrate this function for ts when fix the lint erros
// @ts-ignore
showConfirmationAlert({
message: I18n.t('You_will_not_be_able_to_recover_this_message'),
confirmationText: I18n.t('Delete'),
Expand Down
20 changes: 10 additions & 10 deletions app/containers/Passcode/Base/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ import Touch from '../../../utils/touch';
import { CustomIcon } from '../../../lib/Icons';

interface IPasscodeButton {
text: string;
icon: string;
text?: string;
icon?: string;
theme: string;
disabled: boolean;
onPress: Function;
disabled?: boolean;
onPress?: Function;
}

const Button = React.memo(({ text, disabled, theme, onPress, icon }: Partial<IPasscodeButton>) => {
const press = () => onPress && onPress(text!);
const Button = React.memo(({ text, disabled, theme, onPress, icon }: IPasscodeButton) => {
const press = () => onPress && onPress(text);

return (
<Touch
style={[styles.buttonView, { backgroundColor: 'transparent' }]}
underlayColor={themes[theme!].passcodeButtonActive}
rippleColor={themes[theme!].passcodeButtonActive}
underlayColor={themes[theme].passcodeButtonActive}
rippleColor={themes[theme].passcodeButtonActive}
enabled={!disabled}
theme={theme}
onPress={press}>
{icon ? (
<CustomIcon name={icon} size={36} color={themes[theme!].passcodePrimary} />
<CustomIcon name={icon} size={36} color={themes[theme].passcodePrimary} />
) : (
<Text style={[styles.buttonText, { color: themes[theme!].passcodePrimary }]}>{text}</Text>
<Text style={[styles.buttonText, { color: themes[theme].passcodePrimary }]}>{text}</Text>
)}
</Touch>
);
Expand Down
2 changes: 1 addition & 1 deletion app/containers/message/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export interface IMessageContent {
export interface IMessageDiscussion {
msg: string;
dcount: number;
dlm: string;
dlm: Date;
theme: string;
}

Expand Down
8 changes: 8 additions & 0 deletions app/definitions/IRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ export interface IRoom extends IRocketChatRecord {
autoTranslate?: boolean;
observe?: Function;
usedCannedResponse: string;
search?: boolean;
username?: string;
archived?: boolean;
ro?: boolean;
muted?: string[];
joinCodeRequired?: boolean;
blocked?: boolean;
blocker?: boolean;
}
8 changes: 6 additions & 2 deletions app/definitions/IServer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Model from '@nozbe/watermelondb/Model';

export interface IServer {
name: string;
iconURL: string;
Expand All @@ -8,9 +10,11 @@ export interface IServer {
version: string;
lastLocalAuthenticatedSession: Date;
autoLock: boolean;
autoLockTime: number | null;
biometry: boolean | null;
autoLockTime?: number;
biometry?: boolean;
uniqueID: string;
enterpriseModules: string;
E2E_Enable: boolean;
}

export interface IServerRecord extends IServer, Model {}
4 changes: 4 additions & 0 deletions app/definitions/ITheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IThemePreference {
currentTheme: string;
darkLevel: string;
}
1 change: 1 addition & 0 deletions app/externalModules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ declare module 'react-native-mime-types';
declare module 'react-native-restart';
declare module 'react-native-prompt-android';
declare module 'react-native-jitsi-meet';
declare module 'rn-root-view';
3 changes: 2 additions & 1 deletion app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import InAppNotification from './containers/InAppNotification';
import { ActionSheetProvider } from './containers/ActionSheet';
import debounce from './utils/debounce';
import { isFDroidBuild } from './constants/environment';
import { IThemePreference } from './definitions/ITheme';

RNScreens.enableScreens();

Expand Down Expand Up @@ -175,7 +176,7 @@ export default class Root extends React.Component<{}, IState> {
setTheme = (newTheme = {}) => {
// change theme state
this.setState(
prevState => newThemeState(prevState, newTheme),
prevState => newThemeState(prevState, newTheme as IThemePreference),
() => {
const { themePreferences } = this.state;
// subscribe to Appearance changes
Expand Down
1 change: 1 addition & 0 deletions app/lib/methods/sendFileMessage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import { settings as RocketChatSettings } from '@rocket.chat/sdk';

// eslint-disable-next-line import/extensions, import/no-unresolved
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
import FileUpload from '../../utils/fileUpload';
import database from '../database';
import log from '../../utils/log';
Expand Down
3 changes: 2 additions & 1 deletion app/share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { defaultHeader, getActiveRouteName, navigationTheme, themedHeader } from
import RocketChat, { THEME_PREFERENCES_KEY } from './lib/rocketchat';
import { ThemeContext } from './theme';
import { localAuthenticate } from './utils/localAuthentication';
import { IThemePreference } from './definitions/ITheme';
import ScreenLockedView from './views/ScreenLockedView';
// Outside Stack
import WithoutServersView from './views/WithoutServersView';
Expand Down Expand Up @@ -135,7 +136,7 @@ class Root extends React.Component<{}, IState> {
setTheme = (newTheme = {}) => {
// change theme state
this.setState(
prevState => newThemeState(prevState, newTheme),
prevState => newThemeState(prevState, newTheme as IThemePreference),
() => {
const { themePreferences } = this.state;
// subscribe to Appearance changes
Expand Down
2 changes: 1 addition & 1 deletion app/utils/appGroup.js → app/utils/appGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isIOS } from './deviceInfo';

const { AppGroup } = NativeModules;

const appGroup = {
const appGroup: { path: string } = {
path: isIOS ? AppGroup.path : ''
};

Expand Down
20 changes: 17 additions & 3 deletions app/utils/avatar.js → app/utils/avatar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import { compareServerVersion, methods } from '../lib/utils';
import { RoomType } from '../definitions/IRoom';

const formatUrl = (url, size, query) => `${url}?format=png&size=${size}${query}`;
const formatUrl = (url: string, size: number, query: string) => `${url}?format=png&size=${size}${query}`;

interface IAvatarURL {
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
type: string;
text: string;
size?: number;
user: { id?: string; token?: string };
avatar?: string;
server: string;
avatarETag: string;
rid?: string;
blockUnauthenticatedAccess: boolean;
serverVersion: string;
}

export const avatarURL = ({
type,
Expand All @@ -13,9 +27,9 @@ export const avatarURL = ({
rid,
blockUnauthenticatedAccess,
serverVersion
}) => {
}: IAvatarURL): string => {
let room;
if (type === 'd') {
if (type === RoomType.DIRECT) {
room = text;
} else if (rid && !compareServerVersion(serverVersion, '3.6.0', methods.lowerThan)) {
room = `room/${rid}`;
Expand Down
19 changes: 10 additions & 9 deletions app/utils/base64-js/index.js → app/utils/base64-js/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-bitwise */
// https://github.com/beatgammit/base64-js/blob/master/index.js

const lookup = [];
const revLookup = [];
const lookup: any[] = [];
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
const revLookup: number[] = [];
const Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;

const code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
Expand All @@ -16,7 +16,7 @@ for (let i = 0, len = code.length; i < len; i += 1) {
revLookup['-'.charCodeAt(0)] = 62;
revLookup['_'.charCodeAt(0)] = 63;

const getLens = b64 => {
const getLens = (b64: string | string[]) => {
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
const len = b64.length;

// We're encoding some strings not multiple of 4, so, disable this check
Expand All @@ -37,16 +37,17 @@ const getLens = b64 => {
};

// base64 is 4/3 + up to two characters of the original data
export const byteLength = b64 => {
export const byteLength = (b64: string) => {
const lens = getLens(b64);
const validLen = lens[0];
const placeHoldersLen = lens[1];
return ((validLen + placeHoldersLen) * 3) / 4 - placeHoldersLen;
};

const _byteLength = (b64, validLen, placeHoldersLen) => ((validLen + placeHoldersLen) * 3) / 4 - placeHoldersLen;
const _byteLength = (b64: any, validLen: number, placeHoldersLen: number) =>
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
((validLen + placeHoldersLen) * 3) / 4 - placeHoldersLen;

export const toByteArray = b64 => {
export const toByteArray = (b64: string) => {
let tmp;
const lens = getLens(b64);
const validLen = lens[0];
Expand Down Expand Up @@ -92,10 +93,10 @@ export const toByteArray = b64 => {
return arr;
};

const tripletToBase64 = num =>
const tripletToBase64 = (num: number) =>
lookup[(num >> 18) & 0x3f] + lookup[(num >> 12) & 0x3f] + lookup[(num >> 6) & 0x3f] + lookup[num & 0x3f];

const encodeChunk = (uint8, start, end) => {
const encodeChunk = (uint8: number[] | Uint8Array, start: number, end: number) => {
let tmp;
const output = [];
for (let i = start; i < end; i += 3) {
Expand All @@ -105,7 +106,7 @@ const encodeChunk = (uint8, start, end) => {
return output.join('');
};

export const fromByteArray = uint8 => {
export const fromByteArray = (uint8: number[] | Uint8Array) => {
let tmp;
const len = uint8.length;
const extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
Expand Down
20 changes: 0 additions & 20 deletions app/utils/debounce.js

This file was deleted.

22 changes: 22 additions & 0 deletions app/utils/debounce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default function debounce(func: Function, wait?: number, immediate?: boolean) {
let timeout: number | null;
function _debounce(...args: any[]) {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-this-alias
const context = this;
const later = function __debounce() {
timeout = null;
if (!immediate) {
func.apply(context, args);
}
};
const callNow = immediate && !timeout;
clearTimeout(timeout!);
timeout = setTimeout(later, wait);
if (callNow) {
func.apply(context, args);
}
}
_debounce.stop = () => clearTimeout(timeout!);
return _debounce;
}
2 changes: 1 addition & 1 deletion app/utils/deviceInfo.js → app/utils/deviceInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const getBundleId = DeviceInfo.getBundleId();
export const getDeviceModel = DeviceInfo.getModel();

// Theme is supported by system on iOS 13+ or Android 10+
export const supportSystemTheme = () => {
export const supportSystemTheme = (): boolean => {
const systemVersion = parseInt(DeviceInfo.getSystemVersion(), 10);
return systemVersion >= (isIOS ? 13 : 10);
};
Expand Down
10 changes: 6 additions & 4 deletions app/utils/events.js → app/utils/events.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import log from './log';

class EventEmitter {
private events: { [key: string]: any };

constructor() {
this.events = {};
}

addEventListener(event, listener) {
addEventListener(event: string, listener: any) {
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
if (typeof this.events[event] !== 'object') {
this.events[event] = [];
}
this.events[event].push(listener);
return listener;
}

removeListener(event, listener) {
removeListener(event: string, listener: any) {
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
if (typeof this.events[event] === 'object') {
const idx = this.events[event].indexOf(listener);
if (idx > -1) {
Expand All @@ -25,9 +27,9 @@ class EventEmitter {
}
}

emit(event, ...args) {
emit(event: string, ...args: any[]) {
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
if (typeof this.events[event] === 'object') {
this.events[event].forEach(listener => {
this.events[event].forEach((listener: any) => {
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
try {
listener.apply(this, args);
} catch (e) {
Expand Down
Loading