Chore: Migrate Model's folder to Typescript (#3564)

This commit is contained in:
Reinaldo Neto 2022-01-11 10:51:48 -03:00 committed by GitHub
parent 01d22ed96b
commit 13af9d80ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 535 additions and 126 deletions

View File

@ -13,6 +13,7 @@ import { themes } from '../../constants/colors';
import MessageContext from './Context';
import { fileDownloadAndPreview } from '../../utils/fileDownload';
import { formatAttachmentUrl } from '../../lib/utils';
import { IAttachment } from '../../definitions/IAttachment';
import RCActivityIndicator from '../ActivityIndicator';
const styles = StyleSheet.create({
@ -90,43 +91,26 @@ const styles = StyleSheet.create({
}
});
interface IMessageReplyAttachment {
author_name: string;
message_link: string;
ts: string;
text: string;
title: string;
short: boolean;
value: string;
title_link: string;
author_link: string;
type: string;
color: string;
description: string;
fields: IMessageReplyAttachment[];
thumb_url: string;
}
interface IMessageTitle {
attachment: Partial<IMessageReplyAttachment>;
attachment: IAttachment;
timeFormat: string;
theme: string;
}
interface IMessageDescription {
attachment: Partial<IMessageReplyAttachment>;
attachment: IAttachment;
getCustomEmoji: Function;
theme: string;
}
interface IMessageFields {
attachment: Partial<IMessageReplyAttachment>;
attachment: IAttachment;
theme: string;
getCustomEmoji: Function;
}
interface IMessageReply {
attachment: IMessageReplyAttachment;
attachment: IAttachment;
timeFormat: string;
index: number;
theme: string;
@ -198,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}

View File

@ -13,6 +13,7 @@ import { fileDownload } from '../../utils/fileDownload';
import EventEmitter from '../../utils/events';
import { LISTENER } from '../Toast';
import I18n from '../../i18n';
import { IAttachment } from '../../definitions/IAttachment';
import RCActivityIndicator from '../ActivityIndicator';
const SUPPORTED_TYPES = ['video/quicktime', 'video/mp4', ...(isIOS ? [] : ['video/3gp', 'video/mkv'])];
@ -30,14 +31,7 @@ const styles = StyleSheet.create({
});
interface IMessageVideo {
file: {
title: string;
title_link: string;
type: string;
video_type: string;
video_url: string;
description: string;
};
file: IAttachment;
showAttachment: Function;
getCustomEmoji: Function;
theme: string;

View File

@ -1,4 +1,5 @@
export interface IAttachment {
ts: Date;
title: string;
type: string;
description: string;
@ -7,4 +8,18 @@ export interface IAttachment {
image_type?: string;
video_url?: string;
video_type?: string;
title_link_download?: boolean;
fields?: IAttachment[];
image_dimensions?: { width?: number; height?: number };
image_preview?: string;
image_size?: number;
author_name?: string;
author_icon?: string;
message_link?: string;
text?: string;
short?: boolean;
value?: string;
author_link?: string;
color?: string;
thumb_url?: string;
}

View File

@ -0,0 +1,10 @@
import Model from '@nozbe/watermelondb/Model';
export interface ICustomEmoji {
name?: string;
aliases?: string;
extension: string;
_updatedAt: Date;
}
export type TCustomEmojiModel = ICustomEmoji & Model;

View File

@ -0,0 +1,10 @@
import Model from '@nozbe/watermelondb/Model';
export interface IFrequentlyUsedEmoji {
content?: string;
extension?: string;
isCustom: boolean;
count: number;
}
export type TFrequentlyUsedEmoji = IFrequentlyUsedEmoji & Model;

View File

@ -0,0 +1,18 @@
import Model from '@nozbe/watermelondb/Model';
export interface ILoggedUser {
id: string;
token: string;
username: string;
name: string;
language?: string;
status: string;
statusText?: string;
roles: string[];
avatarETag?: string;
showMessageInMainThread: boolean;
isFromWebView: boolean;
enableMessageParserEarlyAdoption?: boolean;
}
export type TLoggedUser = ILoggedUser & Model;

View File

@ -1,3 +1,95 @@
export interface IMessage {
msg: string;
import Model from '@nozbe/watermelondb/Model';
import { MarkdownAST } from '@rocket.chat/message-parser';
import { IAttachment } from './IAttachment';
import { IReaction } from './IReaction';
import { SubscriptionType } from './ISubscription';
export interface IUserMessage {
_id: string;
username?: string;
name?: string;
}
export interface IUserMention extends IUserMessage {
type: string;
}
export interface IUserChannel {
[index: number]: string | number;
name: string;
_id: string;
}
export interface IEditedBy {
_id: string;
username: string;
}
export type TOnLinkPress = (link: string) => void;
export interface ITranslations {
_id: string;
language: string;
value: string;
}
export interface ILastMessage {
_id: string;
rid: string;
tshow: boolean;
tmid: string;
msg: string;
ts: Date;
u: IUserMessage;
_updatedAt: Date;
urls: string[];
mentions: IUserMention[];
channels: IUserChannel[];
md: MarkdownAST;
attachments: IAttachment[];
reactions: IReaction[];
unread: boolean;
status: boolean;
}
export interface IMessage {
msg?: string;
t?: SubscriptionType;
ts: Date;
u: IUserMessage;
alias: string;
parseUrls: boolean;
groupable?: boolean;
avatar?: string;
emoji?: string;
attachments?: IAttachment[];
urls?: string[];
_updatedAt: Date;
status?: number;
pinned?: boolean;
starred?: boolean;
editedBy?: IEditedBy;
reactions?: IReaction[];
role?: string;
drid?: string;
dcount?: number;
dlm?: Date;
tmid?: string;
tcount?: number;
tlm?: Date;
replies?: string[];
mentions?: IUserMention[];
channels?: IUserChannel[];
unread?: boolean;
autoTranslate?: boolean;
translations?: ITranslations[];
tmsg?: string;
blocks?: any;
e2e?: string;
tshow?: boolean;
md?: MarkdownAST;
subscription: { id: string };
}
export type TMessageModel = IMessage & Model;

View File

@ -0,0 +1,9 @@
import Model from '@nozbe/watermelondb/Model';
export interface IPermission {
id: string;
roles: string[];
_updatedAt: Date;
}
export type TPermissionModel = IPermission & Model;

View File

@ -0,0 +1,5 @@
export interface IReaction {
_id: string;
emoji: string;
usernames: string[];
}

View File

@ -1,4 +0,0 @@
export interface IRocketChatRecord {
id: string;
updatedAt: Date;
}

8
app/definitions/IRole.ts Normal file
View File

@ -0,0 +1,8 @@
import Model from '@nozbe/watermelondb/Model';
export interface IRole {
id: string;
description?: string;
}
export type TRoleModel = IRole & Model;

View File

@ -1,27 +1,20 @@
import { IRocketChatRecord } from './IRocketChatRecord';
import Model from '@nozbe/watermelondb/Model';
export enum RoomType {
GROUP = 'p',
DIRECT = 'd',
CHANNEL = 'c',
OMNICHANNEL = 'l',
THREAD = 'thread'
import { IServedBy } from './IServedBy';
export interface IRoom {
id: string;
customFields: string[];
broadcast: boolean;
encrypted: boolean;
ro: boolean;
v?: string[];
servedBy?: IServedBy;
departmentId?: string;
livechatData?: any;
tags?: string[];
e2eKeyId?: string;
avatarETag?: string;
}
export interface IRoom extends IRocketChatRecord {
rid: string;
t: RoomType;
name: string;
fname: string;
prid?: string;
tmid?: string;
topic?: string;
teamMain?: boolean;
teamId?: string;
encrypted?: boolean;
visitor?: boolean;
autoTranslateLanguage?: boolean;
autoTranslate?: boolean;
observe?: Function;
usedCannedResponse: string;
}
export type TRoomModel = IRoom & Model;

View File

@ -0,0 +1,5 @@
export interface IServedBy {
_id: string;
username: string;
ts: Date;
}

View File

@ -1,3 +1,5 @@
import Model from '@nozbe/watermelondb/Model';
export interface IServer {
name: string;
iconURL: string;
@ -14,3 +16,5 @@ export interface IServer {
enterpriseModules: string;
E2E_Enable: boolean;
}
export type TServerModel = IServer & Model;

View File

@ -0,0 +1,10 @@
import Model from '@nozbe/watermelondb/Model';
export interface IServerHistory {
id: string;
url: string;
username: string;
updatedAt: Date;
}
export type TServerHistory = IServerHistory & Model;

View File

@ -0,0 +1,12 @@
import Model from '@nozbe/watermelondb/Model';
export interface ISettings {
id: string;
valueAsString?: string;
valueAsBoolean?: boolean;
valueAsNumber?: number;
valueAsArray?: string[];
_updatedAt?: Date;
}
export type TSettingsModel = ISettings & Model;

View File

@ -0,0 +1,12 @@
import Model from '@nozbe/watermelondb/Model';
export interface ISlashCommand {
id: string;
params?: string;
description?: string;
clientOnly?: boolean;
providesPreview?: boolean;
appId?: string;
}
export type TSlashCommandModel = ISlashCommand & Model;

View File

@ -0,0 +1,89 @@
import Model from '@nozbe/watermelondb/Model';
import Relation from '@nozbe/watermelondb/Relation';
import { ILastMessage, TMessageModel } from './IMessage';
import { IServedBy } from './IServedBy';
import { TThreadModel } from './IThread';
import { TThreadMessageModel } from './IThreadMessage';
import { TUploadModel } from './IUpload';
export enum SubscriptionType {
GROUP = 'p',
DIRECT = 'd',
CHANNEL = 'c',
OMNICHANNEL = 'l',
THREAD = 'thread'
}
export interface IVisitor {
_id: string;
username: string;
token: string;
status: string;
lastMessageTs: Date;
}
export interface ISubscription {
_id: string; // _id belongs watermelonDB
id: string; // id from server
f: boolean;
t: SubscriptionType;
ts: Date;
ls: Date;
name: string;
fname?: string;
rid: string; // the same as id
open: boolean;
alert: boolean;
roles?: string[];
unread: number;
userMentions: number;
groupMentions: number;
tunread?: string[];
tunreadUser?: string[];
tunreadGroup?: string[];
roomUpdatedAt: Date;
ro: boolean;
lastOpen?: Date;
description?: string;
announcement?: string;
bannerClosed?: boolean;
topic?: string;
blocked?: boolean;
blocker?: boolean;
reactWhenReadOnly?: boolean;
archived: boolean;
joinCodeRequired?: boolean;
muted?: string[];
ignored?: string[];
broadcast?: boolean;
prid?: string;
draftMessage?: string;
lastThreadSync?: Date;
jitsiTimeout?: number;
autoTranslate?: boolean;
autoTranslateLanguage: string;
lastMessage?: ILastMessage;
hideUnreadStatus?: boolean;
sysMes?: string[] | boolean;
uids?: string[];
usernames?: string[];
visitor?: IVisitor;
departmentId?: string;
servedBy?: IServedBy;
livechatData?: any;
tags?: string[];
E2EKey?: string;
encrypted?: boolean;
e2eKeyId?: string;
avatarETag?: string;
teamId?: string;
teamMain?: boolean;
// https://nozbe.github.io/WatermelonDB/Relation.html#relation-api
messages: Relation<TMessageModel>;
threads: Relation<TThreadModel>;
threadMessages: Relation<TThreadMessageModel>;
uploads: Relation<TUploadModel>;
}
export type TSubscriptionModel = ISubscription & Model;

View File

@ -0,0 +1,78 @@
import Model from '@nozbe/watermelondb/Model';
import { MarkdownAST } from '@rocket.chat/message-parser';
import { IAttachment } from './IAttachment';
import { IEditedBy, IUserChannel, IUserMention, IUserMessage } from './IMessage';
import { IReaction } from './IReaction';
import { SubscriptionType } from './ISubscription';
export interface IUrl {
title: string;
description: string;
image: string;
url: string;
}
interface IFileThread {
_id: string;
name: string;
type: string;
}
export interface IThreadResult {
_id: string;
rid: string;
ts: string;
msg: string;
file?: IFileThread;
files?: IFileThread[];
groupable?: boolean;
attachments?: IAttachment[];
md?: MarkdownAST;
u: IUserMessage;
_updatedAt: string;
urls: IUrl[];
mentions: IUserMention[];
channels: IUserChannel[];
replies: string[];
tcount: number;
tlm: string;
}
export interface IThread {
id: string;
msg?: string;
t?: SubscriptionType;
rid: string;
_updatedAt: Date;
ts: Date;
u: IUserMessage;
alias?: string;
parseUrls?: boolean;
groupable?: boolean;
avatar?: string;
emoji?: string;
attachments?: IAttachment[];
urls?: IUrl[];
status?: number;
pinned?: boolean;
starred?: boolean;
editedBy?: IEditedBy;
reactions?: IReaction[];
role?: string;
drid?: string;
dcount?: number;
dlm?: number;
tmid?: string;
tcount?: number;
tlm?: Date;
replies?: string[];
mentions?: IUserMention[];
channels?: IUserChannel[];
unread?: boolean;
autoTranslate?: boolean;
translations?: any;
e2e?: string;
}
export type TThreadModel = IThread & Model;

View File

@ -0,0 +1,44 @@
import Model from '@nozbe/watermelondb/Model';
import { IAttachment } from './IAttachment';
import { IEditedBy, ITranslations, IUserChannel, IUserMention, IUserMessage } from './IMessage';
import { IReaction } from './IReaction';
import { SubscriptionType } from './ISubscription';
export interface IThreadMessage {
msg?: string;
t?: SubscriptionType;
rid: string;
ts: Date;
u: IUserMessage;
alias?: string;
parseUrls?: boolean;
groupable?: boolean;
avatar?: string;
emoji?: string;
attachments?: IAttachment[];
urls?: string[];
_updatedAt?: Date;
status?: number;
pinned?: boolean;
starred?: boolean;
editedBy?: IEditedBy;
reactions?: IReaction[];
role?: string;
drid?: string;
dcount?: number;
dlm?: Date;
tmid?: string;
tcount?: number;
tlm?: Date;
replies?: string[];
mentions?: IUserMention[];
channels?: IUserChannel[];
unread?: boolean;
autoTranslate?: boolean;
translations?: ITranslations[];
e2e?: string;
subscription?: { id: string };
}
export type TThreadMessageModel = IThreadMessage & Model;

View File

@ -0,0 +1,16 @@
import Model from '@nozbe/watermelondb/Model';
export interface IUpload {
id: string;
path?: string;
name?: string;
description?: string;
size: number;
type?: string;
store?: string;
progress: number;
error: boolean;
subscription: { id: string };
}
export type TUploadModel = IUpload & Model;

10
app/definitions/IUser.ts Normal file
View File

@ -0,0 +1,10 @@
import Model from '@nozbe/watermelondb/Model';
export interface IUser {
_id: string;
name?: string;
username: string;
avatarETag?: string;
}
export type TUserModel = IUser & Model;

View File

@ -1,6 +1,6 @@
import { NavigatorScreenParams } from '@react-navigation/core';
import { IRoom } from './definitions/IRoom';
import { ISubscription } from './definitions/ISubscription';
import { IServer } from './definitions/IServer';
import { IAttachment } from './definitions/IAttachment';
import { MasterDetailInsideStackParamList } from './stacks/MasterDetailStack/types';
@ -28,7 +28,7 @@ export type ShareInsideStackParamList = {
isShareExtension: boolean;
serverInfo: IServer;
text: string;
room: IRoom;
room: ISubscription;
thread: any; // TODO: Change
};
SelectServerView: undefined;

View File

@ -3,18 +3,18 @@ import { NavigatorScreenParams } from '@react-navigation/core';
import { IAttachment } from '../../definitions/IAttachment';
import { IMessage } from '../../definitions/IMessage';
import { IRoom, RoomType } from '../../definitions/IRoom';
import { ISubscription, SubscriptionType } from '../../definitions/ISubscription';
export type MasterDetailChatsStackParamList = {
RoomView: {
rid: string;
t: RoomType;
t: SubscriptionType;
tmid?: string;
message?: string;
name?: string;
fname?: string;
prid?: string;
room: IRoom;
room: ISubscription;
jumpToMessageId?: string;
jumpToThreadId?: string;
roomUserId?: string;
@ -27,17 +27,17 @@ export type MasterDetailDrawerParamList = {
export type ModalStackParamList = {
RoomActionsView: {
room: IRoom;
room: ISubscription;
member: any;
rid: string;
t: RoomType;
t: SubscriptionType;
joined: boolean;
};
RoomInfoView: {
room: IRoom;
room: ISubscription;
member: any;
rid: string;
t: RoomType;
t: SubscriptionType;
};
SelectListView: {
data: any;
@ -54,11 +54,11 @@ export type ModalStackParamList = {
};
RoomMembersView: {
rid: string;
room: IRoom;
room: ISubscription;
};
SearchMessagesView: {
rid: string;
t: RoomType;
t: SubscriptionType;
encrypted?: boolean;
showCloseModal?: boolean;
};
@ -84,18 +84,18 @@ export type ModalStackParamList = {
};
MessagesView: {
rid: string;
t: RoomType;
t: SubscriptionType;
name: string;
};
AutoTranslateView: {
rid: string;
room: IRoom;
room: ISubscription;
};
DirectoryView: undefined;
QueueListView: undefined;
NotificationPrefView: {
rid: string;
room: IRoom;
room: ISubscription;
};
ForwardLivechatView: {
rid: string;
@ -110,10 +110,10 @@ export type ModalStackParamList = {
scopeName: string;
tags: string[];
};
room: IRoom;
room: ISubscription;
};
LivechatEditView: {
room: IRoom;
room: ISubscription;
roomUser: any; // TODO: Change
};
PickerView: {
@ -126,7 +126,7 @@ export type ModalStackParamList = {
};
ThreadMessagesView: {
rid: string;
t: RoomType;
t: SubscriptionType;
};
TeamChannelsView: {
teamId: string;
@ -160,7 +160,7 @@ export type ModalStackParamList = {
teamId?: string;
};
CreateDiscussionView: {
channel: IRoom;
channel: ISubscription;
message: IMessage;
showCloseModal: boolean;
};
@ -194,7 +194,7 @@ export type MasterDetailInsideStackParamList = {
isShareView?: boolean;
serverInfo: {};
text: string;
room: IRoom;
room: ISubscription;
thread: any; // TODO: Change
};
};

View File

@ -6,28 +6,28 @@ import { IOptionsField } from '../views/NotificationPreferencesView/options';
import { IServer } from '../definitions/IServer';
import { IAttachment } from '../definitions/IAttachment';
import { IMessage } from '../definitions/IMessage';
import { IRoom, RoomType } from '../definitions/IRoom';
import { ISubscription, SubscriptionType, TSubscriptionModel } from '../definitions/ISubscription';
export type ChatsStackParamList = {
RoomsListView: undefined;
RoomView: {
rid: string;
t: RoomType;
t: SubscriptionType;
tmid?: string;
message?: string;
name?: string;
fname?: string;
prid?: string;
room: IRoom;
room: ISubscription;
jumpToMessageId?: string;
jumpToThreadId?: string;
roomUserId?: string;
};
RoomActionsView: {
room: IRoom;
room: ISubscription;
member: any;
rid: string;
t: RoomType;
t: SubscriptionType;
joined: boolean;
};
SelectListView: {
@ -41,21 +41,21 @@ export type ChatsStackParamList = {
isRadio?: boolean;
};
RoomInfoView: {
room: IRoom;
room: ISubscription;
member: any;
rid: string;
t: RoomType;
t: SubscriptionType;
};
RoomInfoEditView: {
rid: string;
};
RoomMembersView: {
rid: string;
room: IRoom;
room: ISubscription;
};
SearchMessagesView: {
rid: string;
t: RoomType;
t: SubscriptionType;
encrypted?: boolean;
showCloseModal?: boolean;
};
@ -74,12 +74,12 @@ export type ChatsStackParamList = {
};
MessagesView: {
rid: string;
t: RoomType;
t: SubscriptionType;
name: string;
};
AutoTranslateView: {
rid: string;
room: IRoom;
room: TSubscriptionModel;
};
DirectoryView: undefined;
NotificationPrefView: {
@ -90,7 +90,7 @@ export type ChatsStackParamList = {
rid: string;
};
LivechatEditView: {
room: IRoom;
room: ISubscription;
roomUser: any; // TODO: Change
};
PickerView: {
@ -103,7 +103,7 @@ export type ChatsStackParamList = {
};
ThreadMessagesView: {
rid: string;
t: RoomType;
t: SubscriptionType;
};
TeamChannelsView: {
teamId: string;
@ -138,7 +138,7 @@ export type ChatsStackParamList = {
scopeName: string;
tags: string[];
};
room: IRoom;
room: ISubscription;
};
};
@ -198,7 +198,7 @@ export type NewMessageStackParamList = {
teamId?: string;
};
CreateDiscussionView: {
channel: IRoom;
channel: ISubscription;
message: IMessage;
showCloseModal: boolean;
};
@ -230,7 +230,7 @@ export type InsideStackParamList = {
isShareExtension: boolean;
serverInfo: IServer;
text: string;
room: IRoom;
room: ISubscription;
thread: any; // TODO: Change
};
ModalBlockView: {

View File

@ -11,7 +11,7 @@ import { SWITCH_TRACK_COLOR, themes } from '../../constants/colors';
import { withTheme } from '../../theme';
import SafeAreaView from '../../containers/SafeAreaView';
import { events, logEvent } from '../../utils/log';
import { IRoom } from '../../definitions/IRoom';
import { ISubscription } from '../../definitions/ISubscription';
const styles = StyleSheet.create({
list: {
@ -42,7 +42,7 @@ class AutoTranslateView extends React.Component<IAutoTranslateViewProps, any> {
if (room && room.observe) {
this.roomObservable = room.observe();
this.subscription = this.roomObservable.subscribe((changes: IRoom) => {
this.subscription = this.roomObservable.subscribe((changes: ISubscription) => {
if (this.mounted) {
const { selectedLanguage, enableAutoTranslate } = this.state;
if (selectedLanguage !== changes.autoTranslateLanguage) {

View File

@ -20,7 +20,7 @@ import SafeAreaView from '../../containers/SafeAreaView';
import getThreadName from '../../lib/methods/getThreadName';
import styles from './styles';
import { ChatsStackParamList } from '../../stacks/types';
import { IRoom, RoomType } from '../../definitions/IRoom';
import { ISubscription, SubscriptionType } from '../../definitions/ISubscription';
interface IMessagesViewProps {
user: {
@ -40,10 +40,10 @@ interface IMessagesViewProps {
}
interface IRoomInfoParam {
room: IRoom;
room: ISubscription;
member: any;
rid: string;
t: RoomType;
t: SubscriptionType;
joined: boolean;
}
@ -72,13 +72,13 @@ interface IMessageItem {
interface IParams {
rid: string;
t: RoomType;
t: SubscriptionType;
tmid?: string;
message?: string;
name?: string;
fname?: string;
prid?: string;
room: IRoom;
room: ISubscription;
jumpToMessageId?: string;
jumpToThreadId?: string;
roomUserId?: string;
@ -86,7 +86,7 @@ interface IParams {
class MessagesView extends React.Component<IMessagesViewProps, any> {
private rid: string;
private t: RoomType;
private t: SubscriptionType;
private content: any;
private room: any;
@ -158,7 +158,7 @@ class MessagesView extends React.Component<IMessagesViewProps, any> {
...params,
tmid: item.tmid,
name: await getThreadName(this.rid, item.tmid, item._id),
t: RoomType.THREAD
t: SubscriptionType.THREAD
};
navigation.push('RoomView', params);
} else {

View File

@ -6,7 +6,7 @@ import { themes } from '../../../constants/colors';
import { CustomIcon } from '../../../lib/Icons';
import sharedStyles from '../../Styles';
import Touch from '../../../utils/touch';
import { IServer } from '../index';
import { TServerHistory } from '../../../definitions/IServerHistory';
const styles = StyleSheet.create({
container: {
@ -28,10 +28,10 @@ const styles = StyleSheet.create({
});
interface IItem {
item: IServer;
item: TServerHistory;
theme: string;
onPress(url: string): void;
onDelete(item: IServer): void;
onDelete(item: TServerHistory): void;
}
const Item = ({ item, theme, onPress, onDelete }: IItem): JSX.Element => (

View File

@ -5,8 +5,8 @@ import TextInput from '../../../containers/TextInput';
import * as List from '../../../containers/List';
import { themes } from '../../../constants/colors';
import I18n from '../../../i18n';
import { TServerHistory } from '../../../definitions/IServerHistory';
import Item from './Item';
import { IServer } from '../index';
const styles = StyleSheet.create({
container: {
@ -33,8 +33,8 @@ interface IServerInput extends TextInputProps {
theme: string;
serversHistory: any[];
onSubmit(): void;
onDelete(item: IServer): void;
onPressServerHistory(serverHistory: IServer): void;
onDelete(item: TServerHistory): void;
onPressServerHistory(serverHistory: TServerHistory): void;
}
const ServerInput = ({

View File

@ -8,7 +8,6 @@ import { TouchableOpacity } from 'react-native-gesture-handler';
import Orientation from 'react-native-orientation-locker';
import { StackNavigationProp } from '@react-navigation/stack';
import { Dispatch } from 'redux';
import Model from '@nozbe/watermelondb/Model';
import UserPreferences from '../../lib/userPreferences';
import EventEmitter from '../../utils/events';
@ -34,6 +33,7 @@ import { verticalScale, moderateScale } from '../../utils/scaling';
import { withDimensions } from '../../dimensions';
import ServerInput from './ServerInput';
import { OutsideParamList } from '../../stacks/types';
import { TServerHistory } from '../../definitions/IServerHistory';
const styles = StyleSheet.create({
onboardingImage: {
@ -68,11 +68,6 @@ const styles = StyleSheet.create({
}
});
export interface IServer extends Model {
url: string;
username: string;
}
interface INewServerView {
navigation: StackNavigationProp<OutsideParamList, 'NewServerView'>;
theme: string;
@ -90,7 +85,7 @@ interface IState {
text: string;
connectingOpen: boolean;
certificate: any;
serversHistory: IServer[];
serversHistory: TServerHistory[];
}
interface ISubmitParams {
@ -166,7 +161,7 @@ class NewServerView extends React.Component<INewServerView, IState> {
const likeString = sanitizeLikeString(text);
whereClause = [...whereClause, Q.where('url', Q.like(`%${likeString}%`))];
}
const serversHistory = (await serversHistoryCollection.query(...whereClause).fetch()) as IServer[];
const serversHistory = (await serversHistoryCollection.query(...whereClause).fetch()) as TServerHistory[];
this.setState({ serversHistory });
} catch {
// Do nothing
@ -190,7 +185,7 @@ class NewServerView extends React.Component<INewServerView, IState> {
connectServer(server);
};
onPressServerHistory = (serverHistory: IServer) => {
onPressServerHistory = (serverHistory: TServerHistory) => {
this.setState({ text: serverHistory.url }, () => this.submit({ fromServerHistory: true, username: serverHistory?.username }));
};
@ -283,14 +278,14 @@ class NewServerView extends React.Component<INewServerView, IState> {
});
};
deleteServerHistory = async (item: IServer) => {
deleteServerHistory = async (item: TServerHistory) => {
const db = database.servers;
try {
await db.write(async () => {
await item.destroyPermanently();
});
this.setState((prevstate: IState) => ({
serversHistory: prevstate.serversHistory.filter((server: IServer) => server.id !== item.id)
serversHistory: prevstate.serversHistory.filter((server: TServerHistory) => server.id !== item.id)
}));
} catch {
// Nothing

View File

@ -6,7 +6,7 @@ import { Q } from '@nozbe/watermelondb';
import { connect } from 'react-redux';
import { dequal } from 'dequal';
import { IRoom, RoomType } from '../../definitions/IRoom';
import { ISubscription, SubscriptionType } from '../../definitions/ISubscription';
import { IAttachment } from '../../definitions/IAttachment';
import RCTextInput from '../../containers/TextInput';
import ActivityIndicator from '../../containers/ActivityIndicator';
@ -42,10 +42,10 @@ interface ISearchMessagesViewState {
}
interface IRoomInfoParam {
room: IRoom;
room: ISubscription;
member: any;
rid: string;
t: RoomType;
t: SubscriptionType;
joined: boolean;
}

View File

@ -28,7 +28,7 @@ import Preview from './Preview';
import Header from './Header';
import styles from './styles';
import { IAttachment } from './interfaces';
import { IRoom } from '../../definitions/IRoom';
import { ISubscription } from '../../definitions/ISubscription';
interface IShareViewState {
selected: IAttachment;
@ -36,7 +36,7 @@ interface IShareViewState {
readOnly: boolean;
attachments: IAttachment[];
text: string;
room: IRoom;
room: ISubscription;
thread: any; // change
maxFileSize: number;
mediaAllowList: number;