2017-08-03 18:23:43 +00:00
|
|
|
import Realm from 'realm';
|
2017-09-21 17:08:00 +00:00
|
|
|
// import { AsyncStorage } from 'react-native';
|
2017-08-03 18:23:43 +00:00
|
|
|
|
|
|
|
const serversSchema = {
|
|
|
|
name: 'servers',
|
|
|
|
primaryKey: 'id',
|
|
|
|
properties: {
|
|
|
|
id: 'string',
|
|
|
|
current: 'bool'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const settingsSchema = {
|
|
|
|
name: 'settings',
|
|
|
|
primaryKey: '_id',
|
|
|
|
properties: {
|
|
|
|
_id: 'string',
|
2017-08-09 02:27:22 +00:00
|
|
|
_server: 'servers',
|
2017-08-13 23:02:46 +00:00
|
|
|
valueAsString: { type: 'string', optional: true },
|
|
|
|
valueAsBoolean: { type: 'bool', optional: true },
|
2017-11-19 04:10:29 +00:00
|
|
|
valueAsNumber: { type: 'int', optional: true },
|
|
|
|
|
|
|
|
_updatedAt: { type: 'date', optional: true }
|
2017-08-03 18:23:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-24 20:44:52 +00:00
|
|
|
const permissionsRolesSchema = {
|
|
|
|
name: 'permissionsRoles',
|
|
|
|
properties: {
|
|
|
|
value: 'string'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const permissionsSchema = {
|
|
|
|
name: 'permissions',
|
|
|
|
primaryKey: '_id',
|
|
|
|
properties: {
|
|
|
|
_id: 'string',
|
|
|
|
_server: 'servers',
|
|
|
|
roles: { type: 'list', objectType: 'permissionsRoles' },
|
|
|
|
_updatedAt: { type: 'date', optional: true }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-08 20:23:46 +00:00
|
|
|
const roomsSchema = {
|
|
|
|
name: 'rooms',
|
|
|
|
primaryKey: '_id',
|
|
|
|
properties: {
|
|
|
|
_id: 'string',
|
|
|
|
_server: 'servers',
|
|
|
|
t: 'string',
|
|
|
|
_updatedAt: { type: 'date', optional: true }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-24 20:44:52 +00:00
|
|
|
const subscriptionRolesSchema = {
|
|
|
|
name: 'subscriptionRolesSchema',
|
|
|
|
properties: {
|
|
|
|
value: 'string'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-03 18:23:43 +00:00
|
|
|
const subscriptionSchema = {
|
|
|
|
name: 'subscriptions',
|
|
|
|
primaryKey: '_id',
|
|
|
|
properties: {
|
|
|
|
_id: 'string',
|
2017-08-09 02:27:22 +00:00
|
|
|
_server: 'servers',
|
2017-11-22 16:40:59 +00:00
|
|
|
f: { type: 'bool', optional: true },
|
2017-08-03 18:23:43 +00:00
|
|
|
t: 'string',
|
2017-08-07 00:34:35 +00:00
|
|
|
ts: { type: 'date', optional: true },
|
|
|
|
ls: { type: 'date', optional: true },
|
2017-08-03 18:23:43 +00:00
|
|
|
name: 'string',
|
2017-08-05 18:16:32 +00:00
|
|
|
fname: { type: 'string', optional: true },
|
2017-08-03 18:23:43 +00:00
|
|
|
rid: 'string',
|
2017-08-07 00:34:35 +00:00
|
|
|
open: { type: 'bool', optional: true },
|
|
|
|
alert: { type: 'bool', optional: true },
|
2017-11-24 20:44:52 +00:00
|
|
|
roles: { type: 'list', objectType: 'subscriptionRolesSchema' },
|
2017-08-11 18:18:09 +00:00
|
|
|
unread: { type: 'int', optional: true },
|
2017-11-22 16:40:59 +00:00
|
|
|
userMentions: { type: 'int', optional: true },
|
2017-08-03 18:23:43 +00:00
|
|
|
// userMentions: 0,
|
|
|
|
// groupMentions: 0,
|
2017-11-24 17:21:21 +00:00
|
|
|
roomUpdatedAt: { type: 'date', optional: true }
|
2017-08-03 18:23:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-04 00:34:37 +00:00
|
|
|
const usersSchema = {
|
|
|
|
name: 'users',
|
|
|
|
primaryKey: '_id',
|
|
|
|
properties: {
|
|
|
|
_id: 'string',
|
2017-08-09 02:27:22 +00:00
|
|
|
_server: 'servers',
|
2017-08-04 00:34:37 +00:00
|
|
|
username: 'string',
|
2017-08-05 18:16:32 +00:00
|
|
|
name: { type: 'string', optional: true }
|
2017-08-04 00:34:37 +00:00
|
|
|
}
|
2017-08-05 18:16:32 +00:00
|
|
|
};
|
2017-08-04 00:34:37 +00:00
|
|
|
|
2017-12-02 13:19:58 +00:00
|
|
|
const attachmentFields = {
|
|
|
|
name: 'attachmentFields',
|
|
|
|
properties: {
|
|
|
|
title: { type: 'string', optional: true },
|
|
|
|
value: { type: 'string', optional: true },
|
|
|
|
short: { type: 'bool', optional: true }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-15 19:28:46 +00:00
|
|
|
const attachment = {
|
|
|
|
name: 'attachment',
|
|
|
|
properties: {
|
|
|
|
description: { type: 'string', optional: true },
|
|
|
|
image_size: { type: 'int', optional: true },
|
|
|
|
image_type: { type: 'string', optional: true },
|
|
|
|
image_url: { type: 'string', optional: true },
|
2017-12-02 13:19:58 +00:00
|
|
|
audio_size: { type: 'int', optional: true },
|
|
|
|
audio_type: { type: 'string', optional: true },
|
|
|
|
audio_url: { type: 'string', optional: true },
|
|
|
|
video_size: { type: 'int', optional: true },
|
|
|
|
video_type: { type: 'string', optional: true },
|
|
|
|
video_url: { type: 'string', optional: true },
|
2017-08-15 19:28:46 +00:00
|
|
|
title: { type: 'string', optional: true },
|
|
|
|
title_link: { type: 'string', optional: true },
|
|
|
|
title_link_download: { type: 'bool', optional: true },
|
2017-12-02 13:19:58 +00:00
|
|
|
type: { type: 'string', optional: true },
|
|
|
|
author_icon: { type: 'string', optional: true },
|
|
|
|
author_name: { type: 'string', optional: true },
|
|
|
|
author_link: { type: 'string', optional: true },
|
|
|
|
text: { type: 'string', optional: true },
|
|
|
|
color: { type: 'string', optional: true },
|
|
|
|
ts: { type: 'date', optional: true },
|
|
|
|
attachments: { type: 'list', objectType: 'attachment' },
|
|
|
|
fields: { type: 'list', objectType: 'attachmentFields' }
|
2017-08-15 19:28:46 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-02 13:19:58 +00:00
|
|
|
const url = {
|
|
|
|
name: 'url',
|
|
|
|
properties: {
|
|
|
|
_id: 'int',
|
|
|
|
url: { type: 'string', optional: true },
|
|
|
|
title: { type: 'string', optional: true },
|
|
|
|
description: { type: 'string', optional: true },
|
|
|
|
image: { type: 'string', optional: true }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-11-21 14:55:50 +00:00
|
|
|
const messagesEditedBySchema = {
|
|
|
|
name: 'messagesEditedBy',
|
|
|
|
properties: {
|
|
|
|
_id: { type: 'string', optional: true },
|
|
|
|
username: { type: 'string', optional: true }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-04 00:34:37 +00:00
|
|
|
const messagesSchema = {
|
|
|
|
name: 'messages',
|
|
|
|
primaryKey: '_id',
|
|
|
|
properties: {
|
|
|
|
_id: 'string',
|
2017-08-09 02:27:22 +00:00
|
|
|
_server: 'servers',
|
2017-08-05 18:16:32 +00:00
|
|
|
msg: { type: 'string', optional: true },
|
2017-12-02 13:19:58 +00:00
|
|
|
t: { type: 'string', optional: true },
|
2017-08-04 00:34:37 +00:00
|
|
|
rid: 'string',
|
|
|
|
ts: 'date',
|
|
|
|
u: 'users',
|
|
|
|
// mentions: [],
|
|
|
|
// channels: [],
|
2017-08-13 23:45:47 +00:00
|
|
|
alias: { type: 'string', optional: true },
|
|
|
|
parseUrls: { type: 'bool', optional: true },
|
|
|
|
groupable: { type: 'bool', optional: true },
|
|
|
|
avatar: { type: 'string', optional: true },
|
2017-08-15 19:28:46 +00:00
|
|
|
attachments: { type: 'list', objectType: 'attachment' },
|
2017-12-02 13:19:58 +00:00
|
|
|
urls: { type: 'list', objectType: 'url' },
|
2017-08-09 20:08:50 +00:00
|
|
|
_updatedAt: { type: 'date', optional: true },
|
2017-12-13 15:00:26 +00:00
|
|
|
status: { type: 'int', optional: true },
|
2017-11-21 14:55:50 +00:00
|
|
|
pinned: { type: 'bool', optional: true },
|
|
|
|
starred: { type: 'bool', optional: true },
|
|
|
|
editedBy: 'messagesEditedBy'
|
2017-08-04 00:34:37 +00:00
|
|
|
}
|
|
|
|
};
|
2017-08-21 00:11:46 +00:00
|
|
|
//
|
2017-08-17 16:55:47 +00:00
|
|
|
// Realm.clearTestState();
|
2017-08-21 00:11:46 +00:00
|
|
|
// AsyncStorage.clear();
|
2017-08-03 18:23:43 +00:00
|
|
|
const realm = new Realm({
|
2017-11-21 14:55:50 +00:00
|
|
|
schema: [
|
|
|
|
settingsSchema,
|
|
|
|
serversSchema,
|
|
|
|
subscriptionSchema,
|
2017-11-24 20:44:52 +00:00
|
|
|
subscriptionRolesSchema,
|
2017-11-21 14:55:50 +00:00
|
|
|
messagesSchema,
|
|
|
|
usersSchema,
|
|
|
|
roomsSchema,
|
|
|
|
attachment,
|
2017-12-02 13:19:58 +00:00
|
|
|
attachmentFields,
|
2017-11-24 20:44:52 +00:00
|
|
|
messagesEditedBySchema,
|
|
|
|
permissionsSchema,
|
2017-12-02 13:19:58 +00:00
|
|
|
permissionsRolesSchema,
|
|
|
|
url
|
2017-11-22 16:40:59 +00:00
|
|
|
],
|
|
|
|
deleteRealmIfMigrationNeeded: true
|
2017-08-03 18:23:43 +00:00
|
|
|
});
|
|
|
|
export default realm;
|
|
|
|
|
2017-08-11 18:18:09 +00:00
|
|
|
// realm.write(() => {
|
2017-11-07 20:25:04 +00:00
|
|
|
// realm.create('servers', { id: 'https://open.rocket.chat', current: false }, true);
|
2017-08-13 01:35:09 +00:00
|
|
|
// realm.create('servers', { id: 'http://localhost:3000', current: false }, true);
|
|
|
|
// realm.create('servers', { id: 'http://10.0.2.2:3000', current: false }, true);
|
2017-08-11 18:18:09 +00:00
|
|
|
// });
|