[CHORE] Use shortcut syntax for get collections (#2932)
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
a1c9fdfdb9
commit
98890df773
|
@ -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());
|
||||
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 = [];
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
Loading…
Reference in New Issue