Unverified Commit 98890df7 authored by Gung Wah's avatar Gung Wah Committed by GitHub
Browse files

[CHORE] Use shortcut syntax for get collections (#2932)



Co-authored-by: default avatarDiego Mello <diegolmello@gmail.com>
parent a1c9fdfd
......@@ -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 {
......
......@@ -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) {
......
......@@ -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;
......
......@@ -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 {
......
......@@ -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(
......
......@@ -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());
......
......@@ -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
......
......@@ -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);
......
......@@ -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
......
......@@ -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) => {
......
......@@ -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);
......
......@@ -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
......
......@@ -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
......
......@@ -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();
......
......@@ -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
......
......@@ -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);
......
......@@ -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();
......
......@@ -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) {
......
......@@ -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));
......
......@@ -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());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment