diff --git a/app/containers/Avatar/index.js b/app/containers/Avatar/index.js index 8c4ca0ad40..4d7c6d7a50 100644 --- a/app/containers/Avatar/index.js +++ b/app/containers/Avatar/index.js @@ -52,8 +52,8 @@ class AvatarContainer extends React.Component { init = async() => { const db = database.active; - const usersCollection = db.collections.get('users'); - const subsCollection = db.collections.get('subscriptions'); + const usersCollection = db.get('users'); + const subsCollection = db.get('subscriptions'); let record; try { diff --git a/app/containers/EmojiPicker/index.js b/app/containers/EmojiPicker/index.js index 64d941c6fe..89446c067a 100644 --- a/app/containers/EmojiPicker/index.js +++ b/app/containers/EmojiPicker/index.js @@ -95,7 +95,7 @@ class EmojiPicker extends Component { // eslint-disable-next-line react/sort-comp _addFrequentlyUsed = protectedFunction(async(emoji) => { const db = database.active; - const freqEmojiCollection = db.collections.get('frequently_used_emojis'); + const freqEmojiCollection = db.get('frequently_used_emojis'); let freqEmojiRecord; try { freqEmojiRecord = await freqEmojiCollection.find(emoji.content); @@ -120,7 +120,7 @@ class EmojiPicker extends Component { updateFrequentlyUsed = async() => { const db = database.active; - const frequentlyUsedRecords = await db.collections.get('frequently_used_emojis').query().fetch(); + const frequentlyUsedRecords = await db.get('frequently_used_emojis').query().fetch(); let frequentlyUsed = orderBy(frequentlyUsedRecords, ['count'], ['desc']); frequentlyUsed = frequentlyUsed.map((item) => { if (item.isCustom) { diff --git a/app/containers/MessageActions/Header.js b/app/containers/MessageActions/Header.js index ab011e445d..78aa9ae3d5 100644 --- a/app/containers/MessageActions/Header.js +++ b/app/containers/MessageActions/Header.js @@ -96,7 +96,7 @@ const Header = React.memo(({ const setEmojis = async() => { try { const db = database.active; - const freqEmojiCollection = db.collections.get('frequently_used_emojis'); + const freqEmojiCollection = db.get('frequently_used_emojis'); let freqEmojis = await freqEmojiCollection.query().fetch(); const isLandscape = width > height; diff --git a/app/containers/MessageActions/index.js b/app/containers/MessageActions/index.js index d5b998629a..cf0ba69188 100644 --- a/app/containers/MessageActions/index.js +++ b/app/containers/MessageActions/index.js @@ -145,7 +145,7 @@ const MessageActions = React.memo(forwardRef(({ const db = database.active; const result = await RocketChat.markAsUnread({ messageId }); if (result.success) { - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); const subRecord = await subCollection.find(rid); await db.action(async() => { try { diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index d509004bc3..2a318a7113 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -190,8 +190,8 @@ class MessageBox extends Component { } = this.props; let msg; try { - const threadsCollection = db.collections.get('threads'); - const subsCollection = db.collections.get('subscriptions'); + const threadsCollection = db.get('threads'); + const subsCollection = db.get('subscriptions'); try { this.room = await subsCollection.find(rid); } catch (error) { @@ -364,7 +364,7 @@ class MessageBox extends Component { const slashCommand = text.match(/^\/([a-z0-9._-]+) (.+)/im); if (slashCommand) { const [, name, params] = slashCommand; - const commandsCollection = db.collections.get('slash_commands'); + const commandsCollection = db.get('slash_commands'); try { const command = await commandsCollection.find(name); if (command.providesPreview) { @@ -505,7 +505,7 @@ class MessageBox extends Component { getEmojis = debounce(async(keyword) => { const db = database.active; if (keyword) { - const customEmojisCollection = db.collections.get('custom_emojis'); + const customEmojisCollection = db.get('custom_emojis'); const likeString = sanitizeLikeString(keyword); let customEmojis = await customEmojisCollection.query( Q.where('name', Q.like(`${ likeString }%`)) @@ -519,7 +519,7 @@ class MessageBox extends Component { getSlashCommands = debounce(async(keyword) => { const db = database.active; - const commandsCollection = db.collections.get('slash_commands'); + const commandsCollection = db.get('slash_commands'); const likeString = sanitizeLikeString(keyword); const commands = await commandsCollection.query( Q.where('id', Q.like(`${ likeString }%`)) @@ -751,7 +751,7 @@ class MessageBox extends Component { // Slash command if (message[0] === MENTIONS_TRACKING_TYPE_COMMANDS) { const db = database.active; - const commandsCollection = db.collections.get('slash_commands'); + const commandsCollection = db.get('slash_commands'); const command = message.replace(/ .*/, '').slice(1); const likeString = sanitizeLikeString(command); const slashCommand = await commandsCollection.query( diff --git a/app/containers/MessageErrorActions.js b/app/containers/MessageErrorActions.js index c9975b0e33..e84a990483 100644 --- a/app/containers/MessageErrorActions.js +++ b/app/containers/MessageErrorActions.js @@ -19,8 +19,8 @@ const MessageErrorActions = forwardRef(({ tmid }, ref) => { try { const db = database.active; const deleteBatch = []; - const msgCollection = db.collections.get('messages'); - const threadCollection = db.collections.get('threads'); + const msgCollection = db.get('messages'); + const threadCollection = db.get('threads'); // Delete the object (it can be Message or ThreadMessage instance) deleteBatch.push(message.prepareDestroyPermanently()); diff --git a/app/lib/encryption/encryption.js b/app/lib/encryption/encryption.js index 972f2c5889..e4a7f2c145 100644 --- a/app/lib/encryption/encryption.js +++ b/app/lib/encryption/encryption.js @@ -229,9 +229,9 @@ class Encryption { decryptPendingMessages = async(roomId) => { const db = database.active; - const messagesCollection = db.collections.get('messages'); - const threadsCollection = db.collections.get('threads'); - const threadMessagesCollection = db.collections.get('thread_messages'); + const messagesCollection = db.get('messages'); + const threadsCollection = db.get('threads'); + const threadMessagesCollection = db.get('thread_messages'); // e2e status is null or 'pending' and message type is 'e2e' const whereClause = [ @@ -286,7 +286,7 @@ class Encryption { // after initialize the encryption client decryptPendingSubscriptions = async() => { const db = database.active; - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); try { // Find all rooms that can have a lastMessage encrypted // If we select only encrypted rooms we can miss some room that changed their encrypted status @@ -347,7 +347,7 @@ class Encryption { const { rid } = subscription; const db = database.active; - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); let subRecord; try { @@ -400,7 +400,7 @@ class Encryption { encryptMessage = async(message) => { const { rid } = message; const db = database.active; - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); try { // Find the subscription diff --git a/app/lib/encryption/room.js b/app/lib/encryption/room.js index 835bd9ab5f..0aa1b932e6 100644 --- a/app/lib/encryption/room.js +++ b/app/lib/encryption/room.js @@ -49,7 +49,7 @@ export default class EncryptionRoom { } const db = database.active; - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); try { // Find the subscription const subscription = await subCollection.find(this.roomId); diff --git a/app/lib/methods/canOpenRoom.js b/app/lib/methods/canOpenRoom.js index 343d494456..c233899b86 100644 --- a/app/lib/methods/canOpenRoom.js +++ b/app/lib/methods/canOpenRoom.js @@ -57,7 +57,7 @@ async function open({ type, rid, name }) { export default async function canOpenRoom({ rid, path, isCall }) { try { const db = database.active; - const subsCollection = db.collections.get('subscriptions'); + const subsCollection = db.get('subscriptions'); if (isCall && !rid) { // Extract rid from a Jitsi URL diff --git a/app/lib/methods/enterpriseModules.js b/app/lib/methods/enterpriseModules.js index 5cb68e7a99..35c6672d26 100644 --- a/app/lib/methods/enterpriseModules.js +++ b/app/lib/methods/enterpriseModules.js @@ -13,7 +13,7 @@ export async function setEnterpriseModules() { try { const { server: serverId } = reduxStore.getState().server; const serversDB = database.servers; - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); let server; try { server = await serversCollection.find(serverId); @@ -39,7 +39,7 @@ export function getEnterpriseModules() { const enterpriseModules = await this.methodCallWrapper('license:getModules'); if (enterpriseModules) { const serversDB = database.servers; - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); const server = await serversCollection.find(serverId); await serversDB.action(async() => { await server.update((s) => { diff --git a/app/lib/methods/getCustomEmojis.js b/app/lib/methods/getCustomEmojis.js index 1df285d84b..31108fb625 100644 --- a/app/lib/methods/getCustomEmojis.js +++ b/app/lib/methods/getCustomEmojis.js @@ -20,7 +20,7 @@ const updateEmojis = async({ update = [], remove = [], allRecords }) => { return; } const db = database.active; - const emojisCollection = db.collections.get('custom_emojis'); + const emojisCollection = db.get('custom_emojis'); let emojisToCreate = []; let emojisToUpdate = []; let emojisToDelete = []; @@ -62,7 +62,7 @@ const updateEmojis = async({ update = [], remove = [], allRecords }) => { export async function setCustomEmojis() { const db = database.active; - const emojisCollection = db.collections.get('custom_emojis'); + const emojisCollection = db.get('custom_emojis'); const allEmojis = await emojisCollection.query().fetch(); const parsed = allEmojis.reduce((ret, item) => { ret[item.name] = { @@ -85,7 +85,7 @@ export function getCustomEmojis() { try { const serverVersion = reduxStore.getState().server.version; const db = database.active; - const emojisCollection = db.collections.get('custom_emojis'); + const emojisCollection = db.get('custom_emojis'); const allRecords = await emojisCollection.query().fetch(); const updatedSince = await getUpdatedSince(allRecords); diff --git a/app/lib/methods/getPermissions.js b/app/lib/methods/getPermissions.js index 33333cad09..15ee221b84 100644 --- a/app/lib/methods/getPermissions.js +++ b/app/lib/methods/getPermissions.js @@ -69,7 +69,7 @@ const updatePermissions = async({ update = [], remove = [], allRecords }) => { return; } const db = database.active; - const permissionsCollection = db.collections.get('permissions'); + const permissionsCollection = db.get('permissions'); // filter permissions let permissionsToCreate = []; @@ -119,7 +119,7 @@ export function getPermissions() { try { const serverVersion = reduxStore.getState().server.version; const db = database.active; - const permissionsCollection = db.collections.get('permissions'); + const permissionsCollection = db.get('permissions'); const allRecords = await permissionsCollection.query().fetch(); // if server version is lower than 0.73.0, fetches from old api diff --git a/app/lib/methods/getRoles.js b/app/lib/methods/getRoles.js index 72f01bc6da..df22d382be 100644 --- a/app/lib/methods/getRoles.js +++ b/app/lib/methods/getRoles.js @@ -19,7 +19,7 @@ export default function() { if (roles && roles.length) { await db.action(async() => { - const rolesCollections = db.collections.get('roles'); + const rolesCollections = db.get('roles'); const allRolesRecords = await rolesCollections.query().fetch(); // filter roles diff --git a/app/lib/methods/getSettings.js b/app/lib/methods/getSettings.js index f433f4a9a1..6935631ef9 100644 --- a/app/lib/methods/getSettings.js +++ b/app/lib/methods/getSettings.js @@ -44,7 +44,7 @@ const loginSettings = [ const serverInfoUpdate = async(serverInfo, iconSetting) => { const serversDB = database.servers; const serverId = reduxStore.getState().server.server; - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); const server = await serversCollection.find(serverId); let info = serverInfo.reduce((allSettings, setting) => { @@ -118,7 +118,7 @@ export async function getLoginSettings({ server }) { export async function setSettings() { const db = database.active; - const settingsCollection = db.collections.get('settings'); + const settingsCollection = db.get('settings'); const settingsRecords = await settingsCollection.query().fetch(); const parsed = Object.values(settingsRecords).map(item => ({ _id: item.id, @@ -157,7 +157,7 @@ export default async function() { } await db.action(async() => { - const settingsCollection = db.collections.get('settings'); + const settingsCollection = db.get('settings'); const allSettingsRecords = await settingsCollection .query(Q.where('id', Q.oneOf(filteredSettingsIds))) .fetch(); diff --git a/app/lib/methods/getSlashCommands.js b/app/lib/methods/getSlashCommands.js index 33c75f1c02..c37e077f49 100644 --- a/app/lib/methods/getSlashCommands.js +++ b/app/lib/methods/getSlashCommands.js @@ -20,7 +20,7 @@ export default function() { if (commands && commands.length) { await db.action(async() => { - const slashCommandsCollection = db.collections.get('slash_commands'); + const slashCommandsCollection = db.get('slash_commands'); const allSlashCommandsRecords = await slashCommandsCollection.query().fetch(); // filter slash commands diff --git a/app/lib/methods/getUsersPresence.js b/app/lib/methods/getUsersPresence.js index 68d9b1eaa0..83e5ce815c 100644 --- a/app/lib/methods/getUsersPresence.js +++ b/app/lib/methods/getUsersPresence.js @@ -72,7 +72,7 @@ export default async function getUsersPresence() { ids = []; const db = database.active; - const userCollection = db.collections.get('users'); + const userCollection = db.get('users'); users.forEach(async(user) => { try { const userRecord = await userCollection.find(user._id); diff --git a/app/lib/methods/helpers/findSubscriptionsRooms.js b/app/lib/methods/helpers/findSubscriptionsRooms.js index f1714932db..a64a889406 100644 --- a/app/lib/methods/helpers/findSubscriptionsRooms.js +++ b/app/lib/methods/helpers/findSubscriptionsRooms.js @@ -5,7 +5,7 @@ import database from '../../database'; export default async(subscriptions = [], rooms = []) => { try { const db = database.active; - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); const roomIds = rooms.filter(r => !subscriptions.find(s => s.rid === r._id)).map(r => r._id); let existingSubs = await subCollection.query(Q.where('rid', Q.oneOf(roomIds))).fetch(); diff --git a/app/lib/methods/loadMissedMessages.js b/app/lib/methods/loadMissedMessages.js index 82c2e1bda6..d1acaf0b4a 100644 --- a/app/lib/methods/loadMissedMessages.js +++ b/app/lib/methods/loadMissedMessages.js @@ -5,7 +5,7 @@ import updateMessages from './updateMessages'; const getLastUpdate = async(rid) => { try { const db = database.active; - const subsCollection = db.collections.get('subscriptions'); + const subsCollection = db.get('subscriptions'); const sub = await subsCollection.find(rid); return sub.lastOpen.toISOString(); } catch (e) { diff --git a/app/lib/methods/loadThreadMessages.js b/app/lib/methods/loadThreadMessages.js index a3cda71bea..de6f244c61 100644 --- a/app/lib/methods/loadThreadMessages.js +++ b/app/lib/methods/loadThreadMessages.js @@ -33,7 +33,7 @@ export default function loadThreadMessages({ tmid, rid, offset = 0 }) { data = data.map(m => buildMessage(m)); data = await Encryption.decryptMessages(data); const db = database.active; - const threadMessagesCollection = db.collections.get('thread_messages'); + const threadMessagesCollection = db.get('thread_messages'); const allThreadMessagesRecords = await threadMessagesCollection.query(Q.where('rid', tmid)).fetch(); let threadMessagesToCreate = data.filter(i1 => !allThreadMessagesRecords.find(i2 => i1._id === i2.id)); let threadMessagesToUpdate = allThreadMessagesRecords.filter(i1 => data.find(i2 => i1.id === i2._id)); diff --git a/app/lib/methods/logout.js b/app/lib/methods/logout.js index 0a1923de0f..bb6950835a 100644 --- a/app/lib/methods/logout.js +++ b/app/lib/methods/logout.js @@ -42,12 +42,12 @@ async function removeServerData({ server }) { const serversDB = database.servers; const userId = await UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ server }`); - const usersCollection = serversDB.collections.get('users'); + const usersCollection = serversDB.get('users'); if (userId) { const userRecord = await usersCollection.find(userId); batch.push(userRecord.prepareDestroyPermanently()); } - const serverCollection = serversDB.collections.get('servers'); + const serverCollection = serversDB.get('servers'); const serverRecord = await serverCollection.find(server); batch.push(serverRecord.prepareDestroyPermanently()); diff --git a/app/lib/methods/readMessages.js b/app/lib/methods/readMessages.js index e813a68b41..1376126486 100644 --- a/app/lib/methods/readMessages.js +++ b/app/lib/methods/readMessages.js @@ -4,7 +4,7 @@ import log from '../../utils/log'; export default async function readMessages(rid, ls, updateLastOpen = false) { try { const db = database.active; - const subscription = await db.collections.get('subscriptions').find(rid); + const subscription = await db.get('subscriptions').find(rid); // RC 0.61.0 await this.sdk.post('subscriptions.read', { rid }); diff --git a/app/lib/methods/sendFileMessage.js b/app/lib/methods/sendFileMessage.js index 923da17235..435e377cba 100644 --- a/app/lib/methods/sendFileMessage.js +++ b/app/lib/methods/sendFileMessage.js @@ -40,7 +40,7 @@ export function sendFileMessage(rid, fileInfo, tmid, server, user) { fileInfo.rid = rid; const db = database.active; - const uploadsCollection = db.collections.get('uploads'); + const uploadsCollection = db.get('uploads'); let uploadRecord; try { uploadRecord = await uploadsCollection.find(fileInfo.path); diff --git a/app/lib/methods/sendMessage.js b/app/lib/methods/sendMessage.js index ef22cd8047..9b1bc6d101 100644 --- a/app/lib/methods/sendMessage.js +++ b/app/lib/methods/sendMessage.js @@ -9,8 +9,8 @@ import { E2E_MESSAGE_TYPE, E2E_STATUS } from '../encryption/constants'; const changeMessageStatus = async(id, tmid, status, message) => { const db = database.active; - const msgCollection = db.collections.get('messages'); - const threadMessagesCollection = db.collections.get('thread_messages'); + const msgCollection = db.get('messages'); + const threadMessagesCollection = db.get('thread_messages'); const successBatch = []; const messageRecord = await msgCollection.find(id); successBatch.push( @@ -89,10 +89,10 @@ export async function resendMessage(message, tmid) { export default async function(rid, msg, tmid, user, tshow) { try { const db = database.active; - const subsCollection = db.collections.get('subscriptions'); - const msgCollection = db.collections.get('messages'); - const threadCollection = db.collections.get('threads'); - const threadMessagesCollection = db.collections.get('thread_messages'); + const subsCollection = db.get('subscriptions'); + const msgCollection = db.get('messages'); + const threadCollection = db.get('threads'); + const threadMessagesCollection = db.get('thread_messages'); const messageId = random(17); const batch = []; diff --git a/app/lib/methods/subscriptions/room.js b/app/lib/methods/subscriptions/room.js index a6e4e34ad6..885c2469ab 100644 --- a/app/lib/methods/subscriptions/room.js +++ b/app/lib/methods/subscriptions/room.js @@ -109,9 +109,9 @@ export default class RoomSubscription { try { const { _id } = ddpMessage.fields.args[0]; const db = database.active; - const msgCollection = db.collections.get('messages'); - const threadsCollection = db.collections.get('threads'); - const threadMessagesCollection = db.collections.get('thread_messages'); + const msgCollection = db.get('messages'); + const threadsCollection = db.get('threads'); + const threadMessagesCollection = db.get('thread_messages'); let deleteMessage; let deleteThread; let deleteThreadMessage; @@ -163,9 +163,9 @@ export default class RoomSubscription { } const db = database.active; - const msgCollection = db.collections.get('messages'); - const threadsCollection = db.collections.get('threads'); - const threadMessagesCollection = db.collections.get('thread_messages'); + const msgCollection = db.get('messages'); + const threadsCollection = db.get('threads'); + const threadMessagesCollection = db.get('thread_messages'); // Decrypt the message if necessary message = await Encryption.decryptMessage(message); diff --git a/app/lib/methods/subscriptions/rooms.js b/app/lib/methods/subscriptions/rooms.js index 42918da134..f4b5c7b1d7 100644 --- a/app/lib/methods/subscriptions/rooms.js +++ b/app/lib/methods/subscriptions/rooms.js @@ -32,8 +32,8 @@ const WINDOW_TIME = 500; const createOrUpdateSubscription = async(subscription, room) => { try { const db = database.active; - const subCollection = db.collections.get('subscriptions'); - const roomsCollection = db.collections.get('rooms'); + const subCollection = db.get('subscriptions'); + const roomsCollection = db.get('rooms'); if (!subscription) { try { @@ -185,7 +185,7 @@ const createOrUpdateSubscription = async(subscription, room) => { const { rooms } = store.getState().room; if (tmp.lastMessage && !rooms.includes(tmp.rid)) { const lastMessage = buildMessage(tmp.lastMessage); - const messagesCollection = db.collections.get('messages'); + const messagesCollection = db.get('messages'); let messageRecord; try { messageRecord = await messagesCollection.find(lastMessage._id); @@ -281,7 +281,7 @@ export default function subscribeRooms() { if (/subscriptions/.test(ev)) { if (type === 'removed') { try { - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); const sub = await subCollection.find(data.rid); const messages = await sub.messages.fetch(); const threads = await sub.threads.fetch(); @@ -335,7 +335,7 @@ export default function subscribeRooms() { } }; try { - const msgCollection = db.collections.get('messages'); + const msgCollection = db.get('messages'); await db.action(async() => { await msgCollection.create(protectedFunction((m) => { m._raw = sanitizedRaw({ id: message._id }, msgCollection.schema); diff --git a/app/lib/methods/updateMessages.js b/app/lib/methods/updateMessages.js index 0dc63e9ba0..5f0db0f66e 100644 --- a/app/lib/methods/updateMessages.js +++ b/app/lib/methods/updateMessages.js @@ -16,7 +16,7 @@ export default function updateMessages({ rid, update = [], remove = [] }) { return db.action(async() => { // Decrypt these messages update = await Encryption.decryptMessages(update); - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); let sub; try { sub = await subCollection.find(rid); @@ -26,9 +26,9 @@ export default function updateMessages({ rid, update = [], remove = [] }) { } const messagesIds = [...update.map(m => m._id), ...remove.map(m => m._id)]; - const msgCollection = db.collections.get('messages'); - const threadCollection = db.collections.get('threads'); - const threadMessagesCollection = db.collections.get('thread_messages'); + const msgCollection = db.get('messages'); + const threadCollection = db.get('threads'); + const threadMessagesCollection = db.get('thread_messages'); const allMessagesRecords = await msgCollection .query(Q.where('rid', rid), Q.where('id', Q.oneOf(messagesIds))) .fetch(); diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index b9f49ab203..4d1b2fbb5a 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -275,7 +275,7 @@ const RocketChat = { } else if (/updateAvatar/.test(eventName)) { const { username, etag } = ddpMessage.fields.args[0]; const db = database.active; - const userCollection = db.collections.get('users'); + const userCollection = db.get('users'); try { const [userRecord] = await userCollection.query(Q.where('username', Q.eq(username))).fetch(); await db.action(async() => { @@ -289,7 +289,7 @@ const RocketChat = { } else if (/Users:NameChanged/.test(eventName)) { const userNameChanged = ddpMessage.fields.args[0]; const db = database.active; - const userCollection = db.collections.get('users'); + const userCollection = db.get('users'); try { const userRecord = await userCollection.find(userNameChanged._id); await db.action(async() => { @@ -333,7 +333,7 @@ const RocketChat = { // set Server const currentServer = { server }; const serversDB = database.servers; - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); try { const serverRecord = await serversCollection.find(server); currentServer.version = serverRecord.version; @@ -348,7 +348,7 @@ const RocketChat = { // set Settings const settings = ['Accounts_AvatarBlockUnauthenticatedAccess']; const db = database.active; - const settingsCollection = db.collections.get('settings'); + const settingsCollection = db.get('settings'); const settingsRecords = await settingsCollection.query(Q.where('id', Q.oneOf(settings))).fetch(); const parsed = Object.values(settingsRecords).map(item => ({ _id: item.id, @@ -362,7 +362,7 @@ const RocketChat = { // set User info const userId = await UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ server }`); - const userCollections = serversDB.collections.get('users'); + const userCollections = serversDB.get('users'); let user = null; if (userId) { const userRecord = await userCollections.find(userId); @@ -544,7 +544,7 @@ const RocketChat = { try { const serversDB = database.servers; await serversDB.action(async() => { - const serverCollection = serversDB.collections.get('servers'); + const serverCollection = serversDB.get('servers'); const serverRecord = await serverCollection.find(server); await serverRecord.update((s) => { s.roomsUpdatedAt = null; @@ -604,7 +604,7 @@ const RocketChat = { } const db = database.active; const likeString = sanitizeLikeString(searchText); - let data = await db.collections.get('subscriptions').query( + let data = await db.get('subscriptions').query( Q.or( Q.where('name', Q.like(`%${ likeString }%`)), Q.where('fname', Q.like(`%${ likeString }%`)) @@ -792,7 +792,7 @@ const RocketChat = { async getRoom(rid) { try { const db = database.active; - const room = await db.collections.get('subscriptions').find(rid); + const room = await db.get('subscriptions').find(rid); return Promise.resolve(room); } catch (error) { return Promise.reject(new Error('Room not found')); @@ -1174,7 +1174,7 @@ const RocketChat = { */ async hasPermission(permissions, rid) { const db = database.active; - const subsCollection = db.collections.get('subscriptions'); + const subsCollection = db.get('subscriptions'); let roomRoles = []; try { // get the room from database diff --git a/app/sagas/createChannel.js b/app/sagas/createChannel.js index 6bcedad631..613aedec2c 100644 --- a/app/sagas/createChannel.js +++ b/app/sagas/createChannel.js @@ -53,7 +53,7 @@ const handleRequest = function* handleRequest({ data }) { try { const db = database.active; - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); yield db.action(async() => { await subCollection.create((s) => { s._raw = sanitizedRaw({ id: sub.rid }, subCollection.schema); diff --git a/app/sagas/createDiscussion.js b/app/sagas/createDiscussion.js index 732268779e..746ab15839 100644 --- a/app/sagas/createDiscussion.js +++ b/app/sagas/createDiscussion.js @@ -27,7 +27,7 @@ const handleRequest = function* handleRequest({ data }) { try { const db = database.active; - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); yield db.action(async() => { await subCollection.create((s) => { s._raw = sanitizedRaw({ id: sub.rid }, subCollection.schema); diff --git a/app/sagas/deepLinking.js b/app/sagas/deepLinking.js index e0961c7cf1..ff10bd76bd 100644 --- a/app/sagas/deepLinking.js +++ b/app/sagas/deepLinking.js @@ -72,7 +72,7 @@ const fallbackNavigation = function* fallbackNavigation() { const handleOpen = function* handleOpen({ params }) { const serversDB = database.servers; - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); let { host } = params; if (params.isCall && !host) { diff --git a/app/sagas/encryption.js b/app/sagas/encryption.js index f28c778341..395923a431 100644 --- a/app/sagas/encryption.js +++ b/app/sagas/encryption.js @@ -30,7 +30,7 @@ const handleEncryptionInit = function* handleEncryptionInit() { // Fetch server info to check E2E enable const serversDB = database.servers; - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); let serverInfo; try { serverInfo = yield serversCollection.find(server); diff --git a/app/sagas/init.js b/app/sagas/init.js index 5c0cb7286a..03a6c5a78a 100644 --- a/app/sagas/init.js +++ b/app/sagas/init.js @@ -38,7 +38,7 @@ const restore = function* restore() { yield put(appStart({ root: ROOT_OUTSIDE })); } else { const serversDB = database.servers; - const serverCollections = serversDB.collections.get('servers'); + const serverCollections = serversDB.get('servers'); let serverObj; try { diff --git a/app/sagas/login.js b/app/sagas/login.js index cf487eed42..b5c2672633 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -57,7 +57,7 @@ const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnE // Saves username on server history const serversDB = database.servers; - const serversHistoryCollection = serversDB.collections.get('servers_history'); + const serversHistoryCollection = serversDB.get('servers_history'); yield serversDB.action(async() => { try { const serversHistory = await serversHistoryCollection.query(Q.where('url', server)).fetch(); @@ -145,7 +145,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) { moment.locale(toMomentLocale(user.language)); const serversDB = database.servers; - const usersCollection = serversDB.collections.get('users'); + const usersCollection = serversDB.get('users'); const u = { token: user.token, username: user.username, @@ -222,7 +222,7 @@ const handleLogout = function* handleLogout({ forcedByServer }) { } else { const serversDB = database.servers; // all servers - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); const servers = yield serversCollection.query().fetch(); // see if there're other logged in servers and selects first one diff --git a/app/sagas/messages.js b/app/sagas/messages.js index 2879b2b644..2674be42e5 100644 --- a/app/sagas/messages.js +++ b/app/sagas/messages.js @@ -12,7 +12,7 @@ const handleReplyBroadcast = function* handleReplyBroadcast({ message }) { try { const db = database.active; const { username } = message.u; - const subsCollection = db.collections.get('subscriptions'); + const subsCollection = db.get('subscriptions'); const subscriptions = yield subsCollection.query(Q.where('name', username)).fetch(); const isMasterDetail = yield select(state => state.app.isMasterDetail); diff --git a/app/sagas/rooms.js b/app/sagas/rooms.js index 94670ea1f0..f963a29485 100644 --- a/app/sagas/rooms.js +++ b/app/sagas/rooms.js @@ -15,7 +15,7 @@ import protectedFunction from '../lib/methods/helpers/protectedFunction'; const updateRooms = function* updateRooms({ server, newRoomsUpdatedAt }) { const serversDB = database.servers; - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); try { const serverRecord = yield serversCollection.find(server); @@ -39,7 +39,7 @@ const handleRoomsRequest = function* handleRoomsRequest({ params }) { if (params.allData) { yield put(roomsRefresh()); } else { - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); try { const serverRecord = yield serversCollection.find(server); ({ roomsUpdatedAt } = serverRecord); @@ -51,8 +51,8 @@ const handleRoomsRequest = function* handleRoomsRequest({ params }) { const { subscriptions } = yield mergeSubscriptionsRooms(subscriptionsResult, roomsResult); const db = database.active; - const subCollection = db.collections.get('subscriptions'); - const messagesCollection = db.collections.get('messages'); + const subCollection = db.get('subscriptions'); + const messagesCollection = db.get('messages'); const subsIds = subscriptions.map(sub => sub.rid).concat(roomsResult.remove.map(room => room._id)); if (subsIds.length) { diff --git a/app/sagas/selectServer.js b/app/sagas/selectServer.js index c195f7123f..d367274a30 100644 --- a/app/sagas/selectServer.js +++ b/app/sagas/selectServer.js @@ -46,7 +46,7 @@ const getServerInfo = function* getServerInfo({ server, raiseError = true }) { } const serversDB = database.servers; - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); yield serversDB.action(async() => { try { const serverRecord = await serversCollection.find(server); @@ -78,7 +78,7 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch const serversDB = database.servers; yield UserPreferences.setStringAsync(RocketChat.CURRENT_SERVER, server); const userId = yield UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ server }`); - const userCollections = serversDB.collections.get('users'); + const userCollections = serversDB.get('users'); let user = null; if (userId) { try { @@ -152,7 +152,7 @@ const handleServerRequest = function* handleServerRequest({ server, username, fr const serverInfo = yield getServerInfo({ server }); const serversDB = database.servers; - const serversHistoryCollection = serversDB.collections.get('servers_history'); + const serversHistoryCollection = serversDB.get('servers_history'); if (serverInfo) { yield RocketChat.getLoginServices(server); diff --git a/app/utils/localAuthentication.js b/app/utils/localAuthentication.js index 2eb9c7d292..f6fd19da47 100644 --- a/app/utils/localAuthentication.js +++ b/app/utils/localAuthentication.js @@ -17,7 +17,7 @@ import { setLocalAuthenticated } from '../actions/login'; export const saveLastLocalAuthenticationSession = async(server, serverRecord) => { const serversDB = database.servers; - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); await serversDB.action(async() => { try { if (!serverRecord) { @@ -91,7 +91,7 @@ export const checkHasPasscode = async({ force = true, serverRecord }) => { export const localAuthenticate = async(server) => { const serversDB = database.servers; - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); let serverRecord; try { diff --git a/app/views/CreateDiscussionView/SelectUsers.js b/app/views/CreateDiscussionView/SelectUsers.js index a88773ab04..8500ee15c7 100644 --- a/app/views/CreateDiscussionView/SelectUsers.js +++ b/app/views/CreateDiscussionView/SelectUsers.js @@ -22,7 +22,7 @@ const SelectUsers = ({ const getUsers = debounce(async(keyword = '') => { try { const db = database.active; - const usersCollection = db.collections.get('users'); + const usersCollection = db.get('users'); const res = await RocketChat.search({ text: keyword, filterRooms: false }); let items = [...users.filter(u => selected.includes(u.name)), ...res.filter(r => !users.find(u => u.name === r.name))]; const records = await usersCollection.query(Q.where('username', Q.oneOf(items.map(u => u.name)))).fetch(); diff --git a/app/views/LanguageView/index.js b/app/views/LanguageView/index.js index 435762d216..b2e6e10791 100644 --- a/app/views/LanguageView/index.js +++ b/app/views/LanguageView/index.js @@ -94,7 +94,7 @@ class LanguageView extends React.Component { setUser({ language: params.language }); const serversDB = database.servers; - const usersCollection = serversDB.collections.get('users'); + const usersCollection = serversDB.get('users'); await serversDB.action(async() => { try { const userRecord = await usersCollection.find(user.id); diff --git a/app/views/NewServerView/index.js b/app/views/NewServerView/index.js index 5c005d8bca..27422dec81 100644 --- a/app/views/NewServerView/index.js +++ b/app/views/NewServerView/index.js @@ -132,7 +132,7 @@ class NewServerView extends React.Component { queryServerHistory = async(text) => { const db = database.servers; try { - const serversHistoryCollection = db.collections.get('servers_history'); + const serversHistoryCollection = db.get('servers_history'); let whereClause = [ Q.where('username', Q.notEq(null)), Q.experimentalSortBy('updated_at', Q.desc), diff --git a/app/views/RoomInfoEditView/index.js b/app/views/RoomInfoEditView/index.js index 6b0cf68e9e..04472c82ed 100644 --- a/app/views/RoomInfoEditView/index.js +++ b/app/views/RoomInfoEditView/index.js @@ -109,7 +109,7 @@ class RoomInfoEditView extends React.Component { } try { const db = database.active; - const sub = await db.collections.get('subscriptions').find(rid); + const sub = await db.get('subscriptions').find(rid); const observable = sub.observe(); this.querySubscription = observable.subscribe((data) => { diff --git a/app/views/RoomInfoView/index.js b/app/views/RoomInfoView/index.js index dac40ae7b2..a18476d340 100644 --- a/app/views/RoomInfoView/index.js +++ b/app/views/RoomInfoView/index.js @@ -136,7 +136,7 @@ class RoomInfoView extends React.Component { getRoleDescription = async(id) => { const db = database.active; try { - const rolesCollection = db.collections.get('roles'); + const rolesCollection = db.get('roles'); const role = await rolesCollection.find(id); if (role) { return role.description; diff --git a/app/views/RoomMembersView/index.js b/app/views/RoomMembersView/index.js index dd8170b289..5ea2560159 100644 --- a/app/views/RoomMembersView/index.js +++ b/app/views/RoomMembersView/index.js @@ -146,7 +146,7 @@ class RoomMembersView extends React.Component { navToDirectMessage = async(item) => { try { const db = database.active; - const subsCollection = db.collections.get('subscriptions'); + const subsCollection = db.get('subscriptions'); const query = await subsCollection.query(Q.where('name', item.username)).fetch(); if (query.length) { const [room] = query; diff --git a/app/views/RoomView/Header/RightButtons.js b/app/views/RoomView/Header/RightButtons.js index 0c5e6db9b6..37939b1e30 100644 --- a/app/views/RoomView/Header/RightButtons.js +++ b/app/views/RoomView/Header/RightButtons.js @@ -35,7 +35,7 @@ class RightButtonsContainer extends Component { const db = database.active; if (tmid) { try { - const threadRecord = await db.collections.get('messages').find(tmid); + const threadRecord = await db.get('messages').find(tmid); this.observeThread(threadRecord); } catch (e) { console.log('Can\'t find message to observe.'); @@ -43,7 +43,7 @@ class RightButtonsContainer extends Component { } if (rid) { try { - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); const subRecord = await subCollection.find(rid); this.observeSubscription(subRecord); } catch (e) { diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index 2119fb4a0d..2ee84ae252 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -251,7 +251,7 @@ class RoomView extends React.Component { let obj; if (this.tmid) { try { - const threadsCollection = db.collections.get('threads'); + const threadsCollection = db.get('threads'); obj = await threadsCollection.find(this.tmid); } catch (e) { // Do nothing @@ -400,7 +400,7 @@ class RoomView extends React.Component { const db = database.active; try { - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); const sub = await subCollection.find(this.rid); const { room } = await RocketChat.getRoomInfo(this.rid); @@ -475,7 +475,7 @@ class RoomView extends React.Component { findAndObserveRoom = async(rid) => { try { const db = database.active; - const subCollection = await db.collections.get('subscriptions'); + const subCollection = await db.get('subscriptions'); const room = await subCollection.find(rid); this.setState({ room }); if (!this.tmid) { @@ -750,8 +750,8 @@ class RoomView extends React.Component { fetchThreadName = async(tmid, messageId) => { try { const db = database.active; - const threadCollection = db.collections.get('threads'); - const messageCollection = db.collections.get('messages'); + const threadCollection = db.get('threads'); + const messageCollection = db.get('messages'); const messageRecord = await messageCollection.find(messageId); let threadRecord; try { diff --git a/app/views/RoomsListView/index.js b/app/views/RoomsListView/index.js index b71af2968d..6e40b78d1d 100644 --- a/app/views/RoomsListView/index.js +++ b/app/views/RoomsListView/index.js @@ -620,7 +620,7 @@ class RoomsListView extends React.Component { const db = database.active; const result = await RocketChat.toggleFavorite(rid, !favorite); if (result.success) { - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); await db.action(async() => { try { const subRecord = await subCollection.find(rid); @@ -644,7 +644,7 @@ class RoomsListView extends React.Component { const db = database.active; const result = await RocketChat.toggleRead(isRead, rid); if (result.success) { - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); await db.action(async() => { try { const subRecord = await subCollection.find(rid); @@ -668,7 +668,7 @@ class RoomsListView extends React.Component { const db = database.active; const result = await RocketChat.hideRoom(rid, type); if (result.success) { - const subCollection = db.collections.get('subscriptions'); + const subCollection = db.get('subscriptions'); await db.action(async() => { try { const subRecord = await subCollection.find(rid); diff --git a/app/views/ScreenLockConfigView.js b/app/views/ScreenLockConfigView.js index bf0f6a15c6..294a854a63 100644 --- a/app/views/ScreenLockConfigView.js +++ b/app/views/ScreenLockConfigView.js @@ -71,7 +71,7 @@ class ScreenLockConfigView extends React.Component { init = async() => { const { server } = this.props; const serversDB = database.servers; - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); try { this.serverRecord = await serversCollection.find(server); this.setState({ diff --git a/app/views/SearchMessagesView/index.js b/app/views/SearchMessagesView/index.js index 7fb5851658..e11a5b83d3 100644 --- a/app/views/SearchMessagesView/index.js +++ b/app/views/SearchMessagesView/index.js @@ -84,7 +84,7 @@ class SearchMessagesView extends React.Component { // If it's a encrypted, room we'll search only on the local stored messages if (this.encrypted) { const db = database.active; - const messagesCollection = db.collections.get('messages'); + const messagesCollection = db.get('messages'); const likeString = sanitizeLikeString(searchText); return messagesCollection .query( diff --git a/app/views/SelectServerView.js b/app/views/SelectServerView.js index e04c05247f..b3345c820c 100644 --- a/app/views/SelectServerView.js +++ b/app/views/SelectServerView.js @@ -29,7 +29,7 @@ class SelectServerView extends React.Component { async componentDidMount() { const serversDB = database.servers; - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); const servers = await serversCollection.query(Q.where('rooms_updated_at', Q.notEq(null))).fetch(); this.setState({ servers }); } diff --git a/app/views/SettingsView/index.js b/app/views/SettingsView/index.js index bc11da7b79..b67c7f1ea6 100644 --- a/app/views/SettingsView/index.js +++ b/app/views/SettingsView/index.js @@ -62,7 +62,7 @@ class SettingsView extends React.Component { checkCookiesAndLogout = async() => { const { logout, user } = this.props; const db = database.servers; - const usersCollection = db.collections.get('users'); + const usersCollection = db.get('users'); try { const userRecord = await usersCollection.find(user.id); if (!userRecord.loginEmailPassword) { diff --git a/app/views/ShareListView/index.js b/app/views/ShareListView/index.js index b6730876bd..38f3aff72c 100644 --- a/app/views/ShareListView/index.js +++ b/app/views/ShareListView/index.js @@ -206,7 +206,7 @@ class ShareListView extends React.Component { ) ); } - const data = await db.collections.get('subscriptions').query(...defaultWhereClause).fetch(); + const data = await db.get('subscriptions').query(...defaultWhereClause).fetch(); return data.map(item => ({ rid: item.rid, t: item.t, @@ -226,7 +226,7 @@ class ShareListView extends React.Component { if (server) { const chats = await this.query(); - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); const serversCount = await serversCollection.query(Q.where('rooms_updated_at', Q.notEq(null))).fetchCount(); let serverInfo = {}; try { diff --git a/app/views/ShareView/index.js b/app/views/ShareView/index.js index 36648a7919..7658600366 100644 --- a/app/views/ShareView/index.js +++ b/app/views/ShareView/index.js @@ -95,7 +95,7 @@ class ShareView extends Component { getServerInfo = async() => { const { server } = this.props; const serversDB = database.servers; - const serversCollection = serversDB.collections.get('servers'); + const serversCollection = serversDB.get('servers'); try { this.serverInfo = await serversCollection.find(server); } catch (error) { diff --git a/app/views/ThreadMessagesView/index.js b/app/views/ThreadMessagesView/index.js index bf51d594f7..417c103283 100644 --- a/app/views/ThreadMessagesView/index.js +++ b/app/views/ThreadMessagesView/index.js @@ -241,7 +241,7 @@ class ThreadMessagesView extends React.Component { try { const db = database.active; - const threadsCollection = db.collections.get('threads'); + const threadsCollection = db.get('threads'); const allThreadsRecords = await subscription.threads.fetch(); let threadsToCreate = []; let threadsToUpdate = [];