Skip to content
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
ee0eb77
Chore: Migrate Model's folder to Typescript
reinaldonetof Dec 21, 2021
b46f1e8
minor tweak
reinaldonetof Dec 21, 2021
196b2a5
IFrequentlyUsedEmoji
reinaldonetof Dec 21, 2021
6e2f18f
refactor IAttachments
reinaldonetof Dec 21, 2021
23cdabf
IReactions
reinaldonetof Dec 21, 2021
f431163
IMessage created, missing mix with Markdown
reinaldonetof Dec 21, 2021
d613be1
Chore: Migrate CustomEmoji to Typescript
reinaldonetof Dec 21, 2021
80faa18
Chore: Migrate FrequentlyUsedEmoji to Typescript
reinaldonetof Dec 21, 2021
51d95e1
Chore: Migrate Message definition to Typescript
reinaldonetof Dec 21, 2021
3c1d4f7
Chore: Migrate Permission definition to Typescript
reinaldonetof Dec 21, 2021
1068d11
Chore: Migrate Role definition to Typescript
reinaldonetof Dec 21, 2021
9168159
minor tweak
reinaldonetof Dec 21, 2021
027104a
Chore: Migrate Room and Subscription model to Typescript
reinaldonetof Dec 22, 2021
36e2aa7
TRoomModel
reinaldonetof Dec 22, 2021
58ab3b0
refactoring isubscription
reinaldonetof Dec 22, 2021
1ed5644
Merge branch 'chore.ts-definition-frequentlyusedemoji' into chore.ts-…
reinaldonetof Dec 22, 2021
ae8fc39
Merge branch 'chore.ts-definition-customemoji' into chore.ts-modelfolder
reinaldonetof Dec 22, 2021
41062fb
Merge branch 'chore.ts-definition-message' into chore.ts-modelfolder
reinaldonetof Dec 22, 2021
1af8280
Merge branch 'chore.ts-definition-permission' into chore.ts-modelfolder
reinaldonetof Dec 22, 2021
efc306d
Merge branch 'chore.ts-definition-role' into chore.ts-modelfolder
reinaldonetof Dec 22, 2021
107665f
Merge branch 'chore.ts-definition-room' into chore.ts-modelfolder
reinaldonetof Dec 22, 2021
d2a894d
ISubcription almost there, missing the Threads, ThreadsMessages and U…
reinaldonetof Dec 22, 2021
46a18d4
Subscription Model
reinaldonetof Dec 22, 2021
8d7b387
IServerHistory
reinaldonetof Dec 22, 2021
c824825
IServer
reinaldonetof Dec 22, 2021
6e336b4
fix lint serverHistory
reinaldonetof Dec 22, 2021
8352118
LoggedUser
reinaldonetof Dec 22, 2021
29be47b
ISettings
reinaldonetof Dec 22, 2021
5e40d6d
ISlashCommand
reinaldonetof Dec 22, 2021
6783bff
IThread and models
reinaldonetof Dec 22, 2021
cc35a76
IThreadMessage almost there
reinaldonetof Dec 22, 2021
0a918f6
IThreadMessagesModel
reinaldonetof Dec 22, 2021
220e2ba
minor tweak IUrl
reinaldonetof Dec 23, 2021
a23a3e8
IUploads
reinaldonetof Dec 23, 2021
8bf85cb
ISubscription done
reinaldonetof Dec 23, 2021
b5b0a7a
relation to ISubscrition
reinaldonetof Dec 23, 2021
aa16714
optionals to Subscription
reinaldonetof Dec 23, 2021
999d029
IUser done
reinaldonetof Dec 23, 2021
eb217ac
IRoom and IMessage optionals
reinaldonetof Dec 23, 2021
f5ff302
IThread and IThreadMessage optionals
reinaldonetof Dec 23, 2021
14a9921
optionals done
reinaldonetof Dec 23, 2021
ae3efe1
Chore: Migrate Database to Typescript
reinaldonetof Dec 29, 2021
fdc0147
Merge branch 'chore.ts-modelfolder' into chore.ts-database
reinaldonetof Dec 29, 2021
74de6a0
Created Interfaces.ts for database and fix lint errors
reinaldonetof Dec 30, 2021
3b2e62e
Fixes and complete server database
reinaldonetof Dec 30, 2021
50f7b12
Merge branch 'develop' into chore.ts-database
reinaldonetof Jan 19, 2022
f086695
refactor emojipicker
reinaldonetof Jan 20, 2022
787178a
fixed interface tlm and tcount threadDetails
reinaldonetof Jan 20, 2022
302fdce
fix types in goRoom
reinaldonetof Jan 20, 2022
74f4985
fix types in AddExistingChannelView
reinaldonetof Jan 20, 2022
0613138
fixed type threadMessagesView
reinaldonetof Jan 20, 2022
b1c368c
refactor threadmessageview
reinaldonetof Jan 20, 2022
f12977e
fix avatar index
reinaldonetof Jan 21, 2022
b54fd7a
fix reply
reinaldonetof Jan 21, 2022
308cb06
changed db.collections.get to db.get
reinaldonetof Jan 21, 2022
6e77e0a
refactor newMessageView
reinaldonetof Jan 21, 2022
7cfcb29
minor tweak ScreenLockConfig
reinaldonetof Jan 21, 2022
39dbfaa
Merge branch 'develop' into chore.ts-database
reinaldonetof Jan 27, 2022
fd8147e
refactor changes requested
reinaldonetof Jan 27, 2022
9210dfa
import * models and definitions
diegolmello Jan 27, 2022
f783289
Merge branch 'develop' into chore.ts-database
diegolmello Feb 1, 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
12 changes: 8 additions & 4 deletions app/containers/Avatar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import React from 'react';
import { connect } from 'react-redux';
import { Q } from '@nozbe/watermelondb';
import { Observable, Subscription } from 'rxjs';

import database from '../../lib/database';
import { getUserSelector } from '../../selectors/login';
import { TSubscriptionModel, TUserModel } from '../../definitions';
import Avatar from './Avatar';
import { IAvatar } from './interfaces';

class AvatarContainer extends React.Component<IAvatar, any> {
private mounted: boolean;

private subscription: any;
private subscription?: Subscription;

static defaultProps = {
text: '',
Expand Down Expand Up @@ -59,15 +61,17 @@ class AvatarContainer extends React.Component<IAvatar, any> {
record = user;
} else {
const { rid } = this.props;
record = await subsCollection.find(rid);
if (rid) {
record = await subsCollection.find(rid);
}
}
} catch {
// Record not found
}

if (record) {
const observable = record.observe();
this.subscription = observable.subscribe((r: any) => {
const observable = record.observe() as Observable<TSubscriptionModel | TUserModel>;
this.subscription = observable.subscribe(r => {
const { avatarETag } = r;
if (this.mounted) {
this.setState({ avatarETag });
Expand Down
8 changes: 4 additions & 4 deletions app/containers/EmojiPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface IEmojiPickerProps {
}

interface IEmojiPickerState {
frequentlyUsed: [];
frequentlyUsed: (string | { content?: string; extension?: string; isCustom: boolean })[];
customEmojis: any;
show: boolean;
width: number | null;
Expand Down Expand Up @@ -114,7 +114,7 @@ class EmojiPicker extends Component<IEmojiPickerProps, IEmojiPickerState> {
// Do nothing
}

await db.action(async () => {
await db.write(async () => {
if (freqEmojiRecord) {
await freqEmojiRecord.update((f: any) => {
f.count += 1;
Expand All @@ -132,8 +132,8 @@ class EmojiPicker extends Component<IEmojiPickerProps, IEmojiPickerState> {
updateFrequentlyUsed = async () => {
const db = database.active;
const frequentlyUsedRecords = await db.get('frequently_used_emojis').query().fetch();
let frequentlyUsed: any = orderBy(frequentlyUsedRecords, ['count'], ['desc']);
frequentlyUsed = frequentlyUsed.map((item: IEmoji) => {
const frequentlyUsedOrdered = orderBy(frequentlyUsedRecords, ['count'], ['desc']);
const frequentlyUsed = frequentlyUsedOrdered.map(item => {
if (item.isCustom) {
return { content: item.content, extension: item.extension, isCustom: item.isCustom };
}
Expand Down
5 changes: 3 additions & 2 deletions app/containers/MessageActions/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import database from '../../lib/database';
import { Button } from '../ActionSheet';
import { useDimensions } from '../../dimensions';
import sharedStyles from '../../views/Styles';
import { TFrequentlyUsedEmojiModel } from '../../definitions/IFrequentlyUsedEmoji';
import { IEmoji } from '../EmojiPicker/interfaces';

interface IHeader {
Expand Down Expand Up @@ -90,14 +91,14 @@ const HeaderFooter = React.memo(({ onReaction, theme }: THeaderFooter) => (
));

const Header = React.memo(({ handleReaction, server, message, isMasterDetail, theme }: IHeader) => {
const [items, setItems] = useState([]);
const [items, setItems] = useState<(TFrequentlyUsedEmojiModel | string)[]>([]);
const { width, height }: any = useDimensions();

const setEmojis = async () => {
try {
const db = database.active;
const freqEmojiCollection = db.get('frequently_used_emojis');
let freqEmojis = await freqEmojiCollection.query().fetch();
let freqEmojis: (TFrequentlyUsedEmojiModel | string)[] = await freqEmojiCollection.query().fetch();

const isLandscape = width > height;
const size = (isLandscape || isMasterDetail ? width / 2 : width) - CONTAINER_MARGIN * 2;
Expand Down
15 changes: 8 additions & 7 deletions app/containers/MessageActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { showConfirmationAlert } from '../../utils/info';
import { useActionSheet } from '../ActionSheet';
import Header, { HEADER_HEIGHT } from './Header';
import events from '../../utils/log/events';
import { TMessageModel } from '../../definitions/IMessage';

interface IMessageActions {
room: {
Expand Down Expand Up @@ -182,9 +183,9 @@ const MessageActions = React.memo(
if (result.success) {
const subCollection = db.get('subscriptions');
const subRecord = await subCollection.find(rid);
await db.action(async () => {
await db.write(async () => {
try {
await subRecord.update((sub: any) => (sub.lastOpen = ts));
await subRecord.update(sub => (sub.lastOpen = ts));
} catch {
// do nothing
}
Expand Down Expand Up @@ -269,11 +270,11 @@ const MessageActions = React.memo(
}
};

const handleToggleTranslation = async (message: any) => {
const handleToggleTranslation = async (message: TMessageModel) => {
try {
const db = database.active;
await db.action(async () => {
await message.update((m: any) => {
await db.write(async () => {
await message.update(m => {
m.autoTranslate = !m.autoTranslate;
m._updatedAt = new Date();
});
Expand Down Expand Up @@ -320,7 +321,7 @@ const MessageActions = React.memo(
});
};

const getOptions = (message: any) => {
const getOptions = (message: TMessageModel) => {
let options: any = [];

// Reply
Expand Down Expand Up @@ -446,7 +447,7 @@ const MessageActions = React.memo(
return options;
};

const showMessageActions = async (message: any) => {
const showMessageActions = async (message: TMessageModel) => {
logEvent(events.ROOM_SHOW_MSG_ACTIONS);
await getPermissions();
showActionSheet({
Expand Down
4 changes: 2 additions & 2 deletions app/containers/MessageErrorActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const MessageErrorActions = forwardRef(({ tmid }: any, ref): any => {
try {
// Find the thread header and update it
const msg = await msgCollection.find(tmid);
if (msg.tcount <= 1) {
if (msg?.tcount && msg.tcount <= 1) {
Comment thread
diegolmello marked this conversation as resolved.
deleteBatch.push(
msg.prepareUpdate((m: any) => {
m.tcount = null;
Expand All @@ -62,7 +62,7 @@ const MessageErrorActions = forwardRef(({ tmid }: any, ref): any => {
// Do nothing: message not found
}
}
await db.action(async () => {
await db.write(async () => {
await db.batch(...deleteBatch);
});
} catch (e) {
Expand Down
5 changes: 3 additions & 2 deletions app/containers/ThreadDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ interface IThreadDetails {
}

const ThreadDetails = ({ item, user, badgeColor, toggleFollowThread, style, theme }: IThreadDetails) => {
let { tcount } = item;
if (tcount! >= 1000) {
let tcount: number | string = item?.tcount ?? 0;

if (tcount >= 1000) {
tcount = '+999';
}

Expand Down
2 changes: 1 addition & 1 deletion app/containers/message/Reply.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const Fields = React.memo(
<Text style={[styles.fieldTitle, { color: themes[theme].bodyText }]}>{field.title}</Text>
{/* @ts-ignore*/}
<Markdown
msg={field.value!}
msg={field?.value || ''}
baseUrl={baseUrl}
username={user.username}
getCustomEmoji={getCustomEmoji}
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 @@ -101,7 +101,7 @@ export interface IMessageThread {
msg: string;
tcount: number;
theme: string;
tlm: string;
tlm: Date;
isThreadRoom: boolean;
id: string;
}
Expand Down
3 changes: 2 additions & 1 deletion app/containers/message/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TMessageModel } from '../../definitions/IMessage';
import I18n from '../../i18n';
import { DISCUSSION } from './constants';

Expand Down Expand Up @@ -149,7 +150,7 @@ export const getInfoMessage = ({ type, role, msg, author }: TInfoMessage) => {
return '';
};

export const getMessageTranslation = (message: { translations: any }, autoTranslateLanguage: string) => {
export const getMessageTranslation = (message: TMessageModel, autoTranslateLanguage: string) => {
if (!autoTranslateLanguage) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion app/definitions/IFrequentlyUsedEmoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export interface IFrequentlyUsedEmoji {
count: number;
}

export type TFrequentlyUsedEmoji = IFrequentlyUsedEmoji & Model;
export type TFrequentlyUsedEmojiModel = IFrequentlyUsedEmoji & Model;
2 changes: 1 addition & 1 deletion app/definitions/ILoggedUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ export interface ILoggedUser {
enableMessageParserEarlyAdoption?: boolean;
}

export type TLoggedUser = ILoggedUser & Model;
export type TLoggedUserModel = ILoggedUser & Model;
2 changes: 1 addition & 1 deletion app/definitions/IServerHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export interface IServerHistory {
updatedAt: Date;
}

export type TServerHistory = IServerHistory & Model;
export type TServerHistoryModel = IServerHistory & Model;
2 changes: 0 additions & 2 deletions app/definitions/ISubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ export interface ISubscription {
avatarETag?: string;
teamId?: string;
teamMain?: boolean;
search?: boolean;
username?: string;
// https://nozbe.github.io/WatermelonDB/Relation.html#relation-api
messages: Relation<TMessageModel>;
threads: Relation<TThreadModel>;
Expand Down
12 changes: 6 additions & 6 deletions app/definitions/IThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export interface IThread {
id: string;
msg?: string;
t?: SubscriptionType;
rid?: string;
_updatedAt?: Date;
ts?: Date;
u?: IUserMessage;
rid: string;
_updatedAt: Date;
ts: Date;
u: IUserMessage;
alias?: string;
parseUrls?: boolean;
groupable?: boolean;
Expand All @@ -64,8 +64,8 @@ export interface IThread {
dcount?: number;
dlm?: number;
tmid?: string;
tcount: number | string;
tlm?: string;
tcount?: number;
tlm?: Date;
replies?: string[];
mentions?: IUserMention[];
channels?: IUserChannel[];
Expand Down
17 changes: 14 additions & 3 deletions app/definitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ import { StackNavigationProp } from '@react-navigation/stack';
import { Dispatch } from 'redux';

export * from './IAttachment';
export * from './IMessage';
export * from './INotification';
export * from './IPreferences';
export * from './ISubscription';
export * from './IRoom';
export * from './IMessage';
export * from './IThread';
export * from './IThreadMessage';
export * from './ICustomEmoji';
export * from './IFrequentlyUsedEmoji';
export * from './IUpload';
export * from './ISettings';
export * from './IRole';
export * from './IPermission';
export * from './ISlashCommand';
export * from './IUser';
export * from './IServer';
export * from './ISubscription';
export * from './IPreferences';
export * from './ILoggedUser';
export * from './IServerHistory';

export interface IBaseScreen<T extends Record<string, object | undefined>, S extends string> {
Expand Down
3 changes: 1 addition & 2 deletions app/definitions/redux/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { ISelectedUsers } from '../../reducers/selectedUsers';
import { IConnect } from '../../reducers/connect';
import { ISettings } from '../../reducers/settings';


export interface IApplicationState {
settings: ISettings;
login: any;
Expand Down Expand Up @@ -49,4 +48,4 @@ export type TApplicationActions = TActionActiveUsers &
IActionSettings &
TActionEncryption &
TActionSortPreferences &
TActionUserTyping;
TActionUserTyping;
26 changes: 17 additions & 9 deletions app/lib/database/index.js → app/lib/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ import serversSchema from './schema/servers';
import appSchema from './schema/app';
import migrations from './model/migrations';
import serversMigrations from './model/servers/migrations';
import { TAppDatabase, TServerDatabase } from './interfaces';

const appGroupPath = isIOS ? appGroup.path : '';

if (__DEV__ && isIOS) {
console.log(appGroupPath);
}

const getDatabasePath = name => `${appGroupPath}${name}${isOfficial ? '' : '-experimental'}.db`;
const getDatabasePath = (name: string) => `${appGroupPath}${name}${isOfficial ? '' : '-experimental'}.db`;

export const getDatabase = (database = '') => {
export const getDatabase = (database = ''): Database => {
const path = database.replace(/(^\w+:|^)\/\//, '').replace(/\//g, '.');
const dbName = getDatabasePath(path);

Expand Down Expand Up @@ -64,20 +65,27 @@ export const getDatabase = (database = '') => {
});
};

interface IDatabases {
shareDB?: TAppDatabase;
serversDB: TServerDatabase;
activeDB?: TAppDatabase;
}

class DB {
databases = {
databases: IDatabases = {
serversDB: new Database({
adapter: new SQLiteAdapter({
dbName: getDatabasePath('default'),
schema: serversSchema,
migrations: serversMigrations
}),
modelClasses: [Server, LoggedUser, ServersHistory]
})
}) as TServerDatabase
};

get active() {
return this.databases.shareDB || this.databases.activeDB;
// Expected at least one database
get active(): TAppDatabase {
return this.databases.shareDB || this.databases.activeDB!;
}

get share() {
Expand Down Expand Up @@ -116,11 +124,11 @@ class DB {
Setting,
User
]
});
}) as TAppDatabase;
}

setActiveDB(database) {
this.databases.activeDB = getDatabase(database);
setActiveDB(database: string) {
this.databases.activeDB = getDatabase(database) as TAppDatabase;
}
}

Expand Down
Loading