Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHORE] Use shortcut syntax for get collections #2932

Merged
merged 3 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/containers/Avatar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions app/containers/EmojiPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion app/containers/MessageActions/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/containers/MessageActions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions app/containers/MessageBox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 }%`))
Expand All @@ -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 }%`))
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions app/containers/MessageErrorActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
12 changes: 6 additions & 6 deletions app/lib/encryption/encryption.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/lib/encryption/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/canOpenRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/lib/methods/enterpriseModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions app/lib/methods/getCustomEmojis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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] = {
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions app/lib/methods/getPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/getRoles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/lib/methods/getSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/getSlashCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/getUsersPresence.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/helpers/findSubscriptionsRooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/loadMissedMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/loadThreadMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions app/lib/methods/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/readMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/sendFileMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions app/lib/methods/sendMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 = [];

Expand Down
12 changes: 6 additions & 6 deletions app/lib/methods/subscriptions/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading