Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into release-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Apr 3, 2020
2 parents f960d33 + 8e634be commit 18bdefa
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 75 deletions.
1 change: 1 addition & 0 deletions app/api/server/lib/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export async function findAdminRooms({ uid, filter, types = [], pagination: { of
unmuted: 1,
ro: 1,
default: 1,
featured: 1,
topic: 1,
msgs: 1,
archived: 1,
Expand Down
2 changes: 1 addition & 1 deletion app/livechat/server/api/lib/inquiries.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ export async function findOneInquiryByRoomId({ userId, roomId }) {
}

return {
inquiry: await LivechatInquiry.findOneQueuedByRoomId(roomId),
inquiry: await LivechatInquiry.findOneByRoomId(roomId),
};
}
6 changes: 5 additions & 1 deletion app/metrics/server/lib/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import connect from 'connect';
import _ from 'underscore';
import { Meteor } from 'meteor/meteor';

import { Info } from '../../../utils';
import { Info, getOplogInfo } from '../../../utils/server';
import { Migrations } from '../../../migrations';
import { settings } from '../../../settings';
import { Statistics } from '../../../models';
Expand Down Expand Up @@ -57,6 +57,7 @@ metrics.version = new client.Gauge({ name: 'rocketchat_version', labelNames: ['v
metrics.migration = new client.Gauge({ name: 'rocketchat_migration', help: 'migration versoin' });
metrics.instanceCount = new client.Gauge({ name: 'rocketchat_instance_count', help: 'instances running' });
metrics.oplogEnabled = new client.Gauge({ name: 'rocketchat_oplog_enabled', labelNames: ['enabled'], help: 'oplog enabled' });
metrics.oplogQueue = new client.Gauge({ name: 'rocketchat_oplog_queue', labelNames: ['queue'], help: 'oplog queue' });
metrics.oplog = new client.Counter({
name: 'rocketchat_oplog',
help: 'summary of oplog operations',
Expand Down Expand Up @@ -134,6 +135,9 @@ const setPrometheusData = async () => {
metrics.totalPrivateGroupMessages.set(statistics.totalPrivateGroupMessages, date);
metrics.totalDirectMessages.set(statistics.totalDirectMessages, date);
metrics.totalLivechatMessages.set(statistics.totalLivechatMessages, date);

const oplogQueue = getOplogInfo().mongo._oplogHandle?._entryQueue?.length || 0;
metrics.oplogQueue.set(oplogQueue, date);
};

const app = connect();
Expand Down
17 changes: 12 additions & 5 deletions app/models/server/models/_BaseDb.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { EventEmitter } from 'events';

import { Match } from 'meteor/check';
import { Mongo, MongoInternals } from 'meteor/mongo';
import { Mongo } from 'meteor/mongo';
import _ from 'underscore';

import { getMongoInfo } from '../../../utils/server/functions/getMongoInfo';

const baseName = 'rocketchat_';

const trash = new Mongo.Collection(`${ baseName }_trash`);
Expand Down Expand Up @@ -35,6 +37,8 @@ export class BaseDb extends EventEmitter {

this.wrapModel();

const { oplogEnabled, mongo } = getMongoInfo();

// When someone start listening for changes we start oplog if available
const handleListener = (event /* , listener*/) => {
if (event !== 'change') {
Expand All @@ -47,26 +51,29 @@ export class BaseDb extends EventEmitter {
collection: this.collectionName,
};

if (!MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle) {
if (!mongo._oplogHandle) {
throw new Error(`Error: Unable to find Mongodb Oplog. You must run the server with oplog enabled. Try the following:\n
1. Start your mongodb in a replicaset mode: mongod --smallfiles --oplogSize 128 --replSet rs0\n
2. Start the replicaset via mongodb shell: mongo mongo/meteor --eval "rs.initiate({ _id: ''rs0'', members: [ { _id: 0, host: ''localhost:27017'' } ]})"\n
3. Start your instance with OPLOG configuration: export MONGO_OPLOG_URL=mongodb://localhost:27017/local MONGO_URL=mongodb://localhost:27017/meteor node main.js
`);
}

MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle.onOplogEntry(
mongo._oplogHandle.onOplogEntry(
query,
this.processOplogRecord.bind(this),
);
// Meteor will handle if we have a value https://github.com/meteor/meteor/blob/5dcd0b2eb9c8bf881ffbee98bc4cb7631772c4da/packages/mongo/oplog_tailing.js#L5
if (process.env.METEOR_OPLOG_TOO_FAR_BEHIND == null) {
MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle._defineTooFarBehind(
mongo._oplogHandle._defineTooFarBehind(
Number.MAX_SAFE_INTEGER,
);
}
};
this.on('newListener', handleListener);

if (oplogEnabled) {
this.on('newListener', handleListener);
}

this.tryEnsureIndex({ _updatedAt: 1 }, options._updatedAtIndexOptions);
}
Expand Down
7 changes: 7 additions & 0 deletions app/models/server/raw/LivechatInquiry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ export class LivechatInquiryRaw extends BaseRaw {
};
return this.findOne(query);
}

findOneByRoomId(rid) {
const query = {
rid,
};
return this.findOne(query);
}
}
6 changes: 4 additions & 2 deletions app/ui-admin/client/rooms/adminRooms.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
<th width="20%"><div class="table-fake-th">{{_ "Type"}}</div></th>
<th width="20%"><div class="table-fake-th">{{_ "Users"}}</div></th>
<th width="10%"><div class="table-fake-th">{{_ "Msgs"}}</div></th>
<th width="20%"><div class="table-fake-th">{{_ "Default"}}</div></th>
<th width="10%"><div class="table-fake-th">{{_ "Default"}}</div></th>
<th width="10%"><div class="table-fake-th">{{_ "Featured"}}</div></th>
</tr>
</thead>
<tbody>
Expand All @@ -51,7 +52,8 @@
<td width="20%"><div class="rc-table-wrapper">{{type}}</div></td>
<td width="20%"><div class="rc-table-wrapper">{{usersCount}}</div></td>
<td width="10%"><div class="rc-table-wrapper">{{msgs}}</div></td>
<td width="20%"><div class="rc-table-wrapper">{{default}}</div></td>
<td width="10%"><div class="rc-table-wrapper">{{default}}</div></td>
<td width="10%"><div class="rc-table-wrapper">{{#if featured}}True{{else}}False{{/if}}</div></td>
</tr>
{{else}} {{# with searchText}}
<tr class="table-no-click">
Expand Down
37 changes: 17 additions & 20 deletions app/ui/client/views/app/components/Directory/ChannelsTab.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import React, { useMemo, useState, useCallback } from 'react';
import { Box, Margins, Table, Flex, Avatar, Tag } from '@rocket.chat/fuselage';
import { Box, Margins, Table, Avatar, Tag, Icon } from '@rocket.chat/fuselage';
import { useMediaQuery } from '@rocket.chat/fuselage-hooks';

import { useEndpointData } from '../../../../../../../ee/app/engagement-dashboard/client/hooks/useEndpointData';
import { DirectoryTable, Th } from './DirectoryTable';
import { DirectoryTable, Th, Markdown } from './DirectoryTable';
import { useTranslation } from '../../../../../../../client/contexts/TranslationContext';
import { useRoute } from '../../../../../../../client/contexts/RouterContext';
import { useQuery, useFormatDate } from '../hooks';
import { roomTypes } from '../../../../../../utils/client';

const style = { whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden' };

function RoomTags({ room }) {
const t = useTranslation();
return <Margins inline='x2'>
{room.default && <Tag variant='primary'>{t('default')}</Tag>}
{room.featured && <Tag variant='primary'>{t('featured')}</Tag>}
</Margins>;
return <Box mi='x4' alignItems='center' display='flex'>
<Margins inline='x2'>
{room.default && <Tag variant='primary'>{t('default')}</Tag>}
{room.featured && <Tag variant='primary'>{t('featured')}</Tag>}
</Margins>
</Box>;
}

export function ChannelsTab() {
Expand Down Expand Up @@ -57,21 +60,15 @@ export function ChannelsTab() {
const formatDate = useFormatDate();
const renderRow = useCallback(({ _id, ts, name, fname, description, usersCount, lastMessage, topic, ...room }) => <Table.Row key={_id} onKeyDown={onClick(name)} onClick={onClick(name)} tabIndex={0} role='link' action>
<Table.Cell>
<Flex.Container>
<Box>
<Flex.Item>
<Avatar size='x40' title={fname || name} url={`%40${ fname || name }`} />
</Flex.Item>
<Margins inline='x8'>
<Flex.Item grow={1}>
<Box>
<Box textStyle='p2'>{fname || name} <RoomTags room={room} style={style} /></Box>
{topic && <Box textStyle='p1' textColor='hint' style={style}>{topic}</Box> }
</Box>
</Flex.Item>
</Margins>
<Box display='flex'>
<Avatar size='x40' title={fname || name} url={`%40${ fname || name }`} flexGrow={0} />
<Box grow={1} mi='x8' style={style}>
<Box display='flex' alignItems='center'>
<Icon name={roomTypes.getIcon(room)} textColor='hint' /> <Box textStyle='p2' textColor='default' mi='x4'>{fname || name}</Box><RoomTags room={room} style={style} />
</Box>
{topic && <Markdown textStyle='p1' textColor='hint' style={style}>{topic}</Markdown> }
</Box>
</Flex.Container>
</Box>
</Table.Cell>
<Table.Cell textStyle='p1' textColor='hint' style={style}>
{usersCount}
Expand Down
29 changes: 15 additions & 14 deletions app/ui/client/views/app/components/Directory/DirectoryTable.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useMemo, useState, useEffect, useCallback } from 'react';
import { Box, Icon, Margins, Pagination, Skeleton, Table, Flex, TextInput, Tile } from '@rocket.chat/fuselage';
import { Box, Icon, Pagination, Skeleton, Table, Flex, TextInput, Tile } from '@rocket.chat/fuselage';

import { useTranslation } from '../../../../../../../client/contexts/TranslationContext';
import { useDebounce } from '../hooks';
import { Markdown as mrkd } from '../../../../../../markdown/client';

function SortIcon({ direction }) {
return <Box is='svg' width='x16' height='x16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'>
Expand All @@ -14,27 +15,27 @@ function SortIcon({ direction }) {
export function Th({ children, active, direction, sort, onClick, align, ...props }) {
const fn = useMemo(() => () => onClick && onClick(sort), [sort, onClick]);
return <Table.Cell clickable={!!sort} onClick={fn} { ...props }>
<Flex.Container alignItems='center' wrap='no-wrap'>
<Box>{children}{sort && <SortIcon mod-active={active} direction={active && direction} />}</Box>
</Flex.Container>
<Box display='flex' alignItems='center' wrap='no-wrap'>{children}{sort && <SortIcon mod-active={active} direction={active && direction} />}</Box>
</Table.Cell>;
}

export function Markdown({ children, ...props }) {
return React.Children.map(children, function(text, index) {
return <Box { ...props } key={index} dangerouslySetInnerHTML={{ __html: mrkd.parse(text) }}/>;
});
}

const LoadingRow = ({ cols }) => <Table.Row>
<Table.Cell>
<Flex.Container>
<Box>
<Flex.Item>
<Skeleton variant='rect' height={40} width={40} />
</Flex.Item>
<Margins inline='x8'>
<Flex.Item grow={1}>
<Box>
<Skeleton width='100%' />
<Skeleton width='100%' />
</Box>
</Flex.Item>
</Margins>
<Box mi='x8' grow={1}>
<Skeleton width='100%' />
<Skeleton width='100%' />
</Box>
</Box>
</Flex.Container>
</Table.Cell>
Expand Down Expand Up @@ -78,9 +79,9 @@ export function DirectoryTable({
return <>
<Flex.Container direction='column'>
<Box>
<Margins block='x16'>
<Box mb='x16' display='flex'>
<TextInput placeholder={searchPlaceholder} addon={<Icon name='magnifier' size='x20'/>} onChange={handleChange} value={text} />
</Margins>
</Box>
{channels && !channels.length
? <Tile textStyle='p1' elevation='0' textColor='info' style={{ textAlign: 'center' }}>
{t('No_data_found')}
Expand Down
23 changes: 7 additions & 16 deletions app/ui/client/views/app/components/Directory/UserTab.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo, useState, useCallback } from 'react';
import { Box, Margins, Table, Flex, Avatar } from '@rocket.chat/fuselage';
import { Box, Table, Flex, Avatar } from '@rocket.chat/fuselage';
import { useMediaQuery } from '@rocket.chat/fuselage-hooks';

import { useEndpointData } from '../../../../../../../ee/app/engagement-dashboard/client/hooks/useEndpointData';
Expand Down Expand Up @@ -34,11 +34,9 @@ export function UserTab({
}
setSort([id, 'asc']);
};
const bioStyle = useMemo(() => ({ ...style, width: '200px' }), [mediaQuery]);

const header = useMemo(() => [
<Th key={'name'} direction={sort[1]} active={sort[0] === 'name'} onClick={onHeaderClick} sort='name'>{t('Name')}</Th>,
<Th key={'bio'} direction={sort[1]} active={sort[0] === 'bio'} onClick={onHeaderClick} sort='bio' style={bioStyle}>{t('Bio')}</Th>,
mediaQuery && canViewFullOtherUserInfo && <Th key={'email'} direction={sort[1]} active={sort[0] === 'email'} onClick={onHeaderClick} sort='email' style={{ width: '200px' }} >{t('Email')}</Th>,
federation && <Th key={'origin'} direction={sort[1]} active={sort[0] === 'origin'} onClick={onHeaderClick} sort='origin' style={{ width: '200px' }} >{t('Domain')}</Th>,
mediaQuery && <Th key={'createdAt'} direction={sort[1]} active={sort[0] === 'createdAt'} onClick={onHeaderClick} sort='createdAt' style={{ width: '200px' }}>{t('Joined_at')}</Th>,
Expand All @@ -64,22 +62,15 @@ export function UserTab({
<Flex.Item>
<Avatar size='x40' title={username} url={username} />
</Flex.Item>
<Margins inline='x8'>
<Flex.Item grow={1}>
<Box style={style}>
<Box textStyle='p2' style={style}>{name || username}</Box>
<Box textStyle='p1' textColor='hint' style={style}>{name && username}</Box>
</Box>
</Flex.Item>
</Margins>
<Box style={style} grow={1} mi='x8'>
<Box display='flex'>
<Box textStyle='p2' style={style} textColor='default'>{name || username}</Box> <Box mi='x4'/> <Box textStyle='p1' textColor='hint' style={style}>{username}</Box>
</Box>
<Box textStyle='p1' textColor='hint' style={style}> {bio} </Box>
</Box>
</Box>
</Flex.Container>
</Table.Cell>
<Table.Cell textStyle='p1' textColor='hint' style={ bioStyle }>
<Box is='div' style={ style }>
{bio}
</Box>
</Table.Cell>
{mediaQuery && canViewFullOtherUserInfo
&& <Table.Cell style={style} >
{emails && emails[0].address}
Expand Down
20 changes: 12 additions & 8 deletions app/utils/server/functions/getMongoInfo.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { MongoInternals } from 'meteor/mongo';

export function getOplogInfo() {
const { mongo } = MongoInternals.defaultRemoteCollectionDriver();

const oplogEnabled = Boolean(mongo._oplogHandle && mongo._oplogHandle.onOplogEntry);

return { oplogEnabled, mongo };
}

function fallbackMongoInfo() {
let mongoVersion;
let mongoStorageEngine;

const { mongo } = MongoInternals.defaultRemoteCollectionDriver();

const oplogEnabled = Boolean(mongo._oplogHandle && mongo._oplogHandle.onOplogEntry);
const { oplogEnabled, mongo } = getOplogInfo();

try {
const { version } = Promise.await(mongo.db.command({ buildinfo: 1 }));
Expand All @@ -27,16 +33,14 @@ function fallbackMongoInfo() {
console.error('==================================');
}

return { oplogEnabled, mongoVersion, mongoStorageEngine };
return { oplogEnabled, mongoVersion, mongoStorageEngine, mongo };
}

export function getMongoInfo() {
let mongoVersion;
let mongoStorageEngine;

const { mongo } = MongoInternals.defaultRemoteCollectionDriver();

const oplogEnabled = Boolean(mongo._oplogHandle && mongo._oplogHandle.onOplogEntry);
const { oplogEnabled, mongo } = getOplogInfo();

try {
const { version, storageEngine } = Promise.await(mongo.db.command({ serverStatus: 1 }));
Expand All @@ -47,5 +51,5 @@ export function getMongoInfo() {
return fallbackMongoInfo();
}

return { oplogEnabled, mongoVersion, mongoStorageEngine };
return { oplogEnabled, mongoVersion, mongoStorageEngine, mongo };
}
2 changes: 1 addition & 1 deletion app/utils/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export { roomTypes } from './lib/roomTypes';
export { RoomTypeRouteConfig, RoomTypeConfig, RoomSettingsEnum, RoomMemberActions, UiTextContext } from '../lib/RoomTypeConfig';
export { RoomTypesCommon } from '../lib/RoomTypesCommon';
export { isDocker } from './functions/isDocker';
export { getMongoInfo } from './functions/getMongoInfo';
export { getMongoInfo, getOplogInfo } from './functions/getMongoInfo';
export { getUserAvatarURL } from '../lib/getUserAvatarURL';
export { slashCommands } from '../lib/slashCommand';
export { getUserNotificationPreference } from '../lib/getUserNotificationPreference';
Expand Down
10 changes: 5 additions & 5 deletions server/methods/browseChannels.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Meteor.methods({
...sort,
},
fields: {
t: 1,
description: 1,
topic: 1,
name: 1,
Expand All @@ -95,6 +96,7 @@ Meteor.methods({
default: 1,
featured: 1,
usersCount: 1,
prid: 1,
},
});

Expand All @@ -114,8 +116,6 @@ Meteor.methods({
return;
}

const exceptions = [user.username];

const forcedSearchFields = workspace === 'all' && ['username', 'name', 'emails.address'];

const options = {
Expand All @@ -133,11 +133,11 @@ Meteor.methods({

let result;
if (workspace === 'all') {
result = Users.findByActiveUsersExcept(text, exceptions, options, forcedSearchFields);
result = Users.findByActiveUsersExcept(text, [], options, forcedSearchFields);
} else if (workspace === 'external') {
result = Users.findByActiveExternalUsersExcept(text, exceptions, options, forcedSearchFields, getFederationDomain());
result = Users.findByActiveExternalUsersExcept(text, [], options, forcedSearchFields, getFederationDomain());
} else {
result = Users.findByActiveLocalUsersExcept(text, exceptions, options, forcedSearchFields, getFederationDomain());
result = Users.findByActiveLocalUsersExcept(text, [], options, forcedSearchFields, getFederationDomain());
}

const total = result.count(); // count ignores the `skip` and `limit` options
Expand Down
Loading

0 comments on commit 18bdefa

Please sign in to comment.