Skip to content

Commit

Permalink
Merge branch 'develop' into fix/autotranslate-ignoring-enabled-setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipe Marins authored Aug 22, 2022
2 parents 9d7013f + 8a2899f commit e90d40f
Show file tree
Hide file tree
Showing 342 changed files with 11,247 additions and 4,746 deletions.
33 changes: 22 additions & 11 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -754,34 +754,45 @@ jobs:
username: ${{ secrets.CR_USER }}
password: ${{ secrets.CR_PAT }}

- name: Publish Docker images
- name: Get Docker image name
id: gh-docker
run: |
LOWERCASE_REPOSITORY=$(echo "${{ github.repository_owner }}" | tr "[:upper:]" "[:lower:]")
IMAGE_TAG="${{ needs.release-versions.outputs.gh-docker-tag }}"
GH_IMAGE_NAME="ghcr.io/${LOWERCASE_REPOSITORY}/${{ matrix.service }}-service:${IMAGE_TAG}"
GH_IMAGE_NAME="ghcr.io/${LOWERCASE_REPOSITORY}/${{ matrix.service }}-service:${{ needs.release-versions.outputs.gh-docker-tag }}"
echo "GH_IMAGE_NAME: $GH_IMAGE_NAME"
docker pull $GH_IMAGE_NAME
echo "::set-output name=gh-image-name::${GH_IMAGE_NAME}"
- name: Pull Docker image
run: docker pull ${{ steps.gh-docker.outputs.gh-image-name }}

- name: Publish Docker images
run: |
DH_IMAGE_NAME="rocketchat/${{ matrix.service }}-service"
# 'develop' or 'tag'
DOCKER_TAG=$GITHUB_REF_NAME
docker tag $GH_IMAGE_NAME rocketchat/${{ matrix.service }}-service:${IMAGE_TAG}
docker push rocketchat/${{ matrix.service }}-service:${IMAGE_TAG}
echo "DH_IMAGE_NAME: $DH_IMAGE_NAME"
echo "DOCKER_TAG: $DOCKER_TAG"
# tag and push the specific tag version
docker tag ${{ steps.gh-docker.outputs.gh-image-name }} $DH_IMAGE_NAME:$DOCKER_TAG
docker push $DH_IMAGE_NAME:$DOCKER_TAG
if [[ $GITHUB_REF == refs/tags/* ]]; then
RELEASE="${{ needs.release-versions.outputs.release }}"
echo "RELEASE: $RELEASE"
if [[ $RELEASE == 'latest' ]]; then
if [[ '${{ needs.release-versions.outputs.latest-release }}' == $GITHUB_REF_NAME ]]; then
docker tag rocketchat/${{ matrix.service }}-service:${IMAGE_TAG} rocketchat/${{ matrix.service }}-service:${RELEASE}
docker push rocketchat/${{ matrix.service }}-service:${RELEASE}
docker tag ${{ steps.gh-docker.outputs.gh-image-name }} $DH_IMAGE_NAME:$RELEASE
docker push $DH_IMAGE_NAME:$RELEASE
fi
else
docker tag rocketchat/${{ matrix.service }}-service:${IMAGE_TAG} rocketchat/${{ matrix.service }}-service:${RELEASE}
docker push rocketchat/${{ matrix.service }}-service:${RELEASE}
docker tag ${{ steps.gh-docker.outputs.gh-image-name }} $DH_IMAGE_NAME:$RELEASE
docker push $DH_IMAGE_NAME:$RELEASE
fi
fi
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/lib/getServerInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { hasPermissionAsync } from '../../../authorization/server/functions/hasP

type ServerInfo =
| {
info: Info;
info: typeof Info;
}
| {
version: string | undefined;
Expand Down
39 changes: 39 additions & 0 deletions apps/meteor/app/api/server/v1/webdav.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
import Ajv from 'ajv';

import { API } from '../api';
import { findWebdavAccountsByUserId } from '../lib/webdav';

// TO-DO: remove this AJV instance and import one from the core-typings
const ajv = new Ajv({ coerceTypes: true });

type POSTRemoveWebdavAccount = {
accountId: string;
};

const POSTRemoveWebdavAccountSchema = {
type: 'object',
properties: {
accountId: {
type: 'string',
},
},
required: ['accountId'],
additionalProperties: false,
};

export const isPOSTRemoveWebdavAccount = ajv.compile<POSTRemoveWebdavAccount>(POSTRemoveWebdavAccountSchema);

API.v1.addRoute(
'webdav.getMyAccounts',
{ authRequired: true },
Expand All @@ -12,3 +34,20 @@ API.v1.addRoute(
},
},
);

API.v1.addRoute(
'webdav.removeWebdavAccount',
{
authRequired: true,
validateParams: isPOSTRemoveWebdavAccount,
},
{
async post() {
const { accountId } = this.bodyParams;

const result = Meteor.call('removeWebdavAccount', accountId);

return API.v1.success({ result });
},
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Meteor.startup(function () {
imperativeModal.open({
component: CreateDiscussion,
props: {
defaultParentRoom: room.prid || room._id,
defaultParentRoom: room?.prid || room?._id,
onClose: imperativeModal.close,
parentMessageId: message._id,
nameSuggestion: message?.msg?.substr(0, 140),
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/app/emoji/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export const emoji = {
},
},
},
/** @type {Record<string, unknown>} */
list: {},
};
2 changes: 1 addition & 1 deletion apps/meteor/app/federation/server/endpoints/dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ const eventHandlers = {
processThreads(denormalizedMessage, room);

// Notify users
notifyUsersOnMessage(denormalizedMessage, room);
await notifyUsersOnMessage(denormalizedMessage, room);
sendAllNotifications(denormalizedMessage, room);
} catch (err) {
serverLogger.debug(`Error on creating message: ${message._id}`);
Expand Down
22 changes: 15 additions & 7 deletions apps/meteor/app/lib/server/lib/notifyUsersOnMessage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import moment from 'moment';
import { escapeRegExp } from '@rocket.chat/string-helpers';
import { Subscriptions as SubscriptionsRaw } from '@rocket.chat/models';

import { Rooms, Subscriptions } from '../../../models/server';
import { settings } from '../../../settings/server';
Expand Down Expand Up @@ -85,7 +86,7 @@ const getUserIdsFromHighlights = (rid, message) => {
.map(({ u: { _id: uid } }) => uid);
};

export function updateUsersSubscriptions(message, room) {
export async function updateUsersSubscriptions(message, room) {
// Don't increase unread counter on thread messages
if (room != null && !message.tmid) {
const { toAll, toHere, mentionIds } = getMentions(message);
Expand All @@ -106,15 +107,17 @@ export function updateUsersSubscriptions(message, room) {

// this shouldn't run only if has group mentions because it will already exclude mentioned users from the query
if (!toAll && !toHere && unreadCount === 'all_messages') {
Subscriptions.incUnreadForRoomIdExcludingUserIds(room._id, [...userIds, message.u._id]);
await SubscriptionsRaw.incUnreadForRoomIdExcludingUserIds(room._id, [...userIds, message.u._id]);
}
}

// Update all other subscriptions to alert their owners but without incrementing
// the unread counter, as it is only for mentions and direct messages
// We now set alert and open properties in two separate update commands. This proved to be more efficient on MongoDB - because it uses a more efficient index.
Subscriptions.setAlertForRoomIdExcludingUserId(message.rid, message.u._id);
Subscriptions.setOpenForRoomIdExcludingUserId(message.rid, message.u._id);
await Promise.all([
SubscriptionsRaw.setAlertForRoomIdExcludingUserId(message.rid, message.u._id),
SubscriptionsRaw.setOpenForRoomIdExcludingUserId(message.rid, message.u._id),
]);
}

export function updateThreadUsersSubscriptions(message, room, replies) {
Expand All @@ -131,7 +134,7 @@ export function updateThreadUsersSubscriptions(message, room, replies) {
Subscriptions.setLastReplyForRoomIdAndUserIds(message.rid, repliesPlusSender, new Date());
}

export function notifyUsersOnMessage(message, room) {
export async function notifyUsersOnMessage(message, room) {
// skips this callback if the message was edited and increments it if the edit was way in the past (aka imported)
if (message.editedAt) {
if (Math.abs(moment(message.editedAt).diff()) > 60000) {
Expand Down Expand Up @@ -166,9 +169,14 @@ export function notifyUsersOnMessage(message, room) {
// Update all the room activity tracker fields
Rooms.incMsgCountAndSetLastMessageById(message.rid, 1, message.ts, settings.get('Store_Last_Message') && message);

updateUsersSubscriptions(message, room);
await updateUsersSubscriptions(message, room);

return message;
}

callbacks.add('afterSaveMessage', notifyUsersOnMessage, callbacks.priority.LOW, 'notifyUsersOnMessage');
callbacks.add(
'afterSaveMessage',
(message, room) => Promise.await(notifyUsersOnMessage(message, room)),
callbacks.priority.LOW,
'notifyUsersOnMessage',
);
3 changes: 2 additions & 1 deletion apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,9 @@ export async function sendAllNotifications(message, room) {
}),
)
.then((users) => {
const subscriptions = Subscriptions.findByRoomIdAndUserIds(room._id, users);
users.forEach((userId) => {
const subscription = Subscriptions.findOneByRoomIdAndUserId(room._id, userId);
const subscription = subscriptions.find((subscription) => subscription.u._id === userId);

sendNotification({
subscription,
Expand Down
19 changes: 3 additions & 16 deletions apps/meteor/app/lib/server/methods/getMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { check } from 'meteor/check';
import type { IMessage } from '@rocket.chat/core-typings';

import { canAccessRoomId } from '../../../authorization/server';
import { Messages, Rooms } from '../../../models/server';
import { Messages } from '../../../models/server';

Meteor.methods({
getMessages(messages) {
Expand All @@ -16,22 +16,9 @@ Meteor.methods({

const msgs = Messages.findVisibleByIds(messages).fetch() as IMessage[];
const rids = [...new Set(msgs.map((m) => m.rid))];
const prids = [
...new Set(
rids.reduce<string[]>((prids, rid) => {
const room = Rooms.findOneById(rid);

if (room?.prid) {
prids.push(room.prid);
}

return prids;
}, []),
),
];

if (!rids.every((_id) => canAccessRoomId(_id, uid)) || !prids.every((_id) => canAccessRoomId(_id, uid))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', 'getSingleMessage');
if (!rids.every((_id) => canAccessRoomId(_id, uid))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getSingleMessage' });
}

return msgs;
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/app/livechat/client/views/admin.js

This file was deleted.

This file was deleted.

7 changes: 4 additions & 3 deletions apps/meteor/app/livechat/client/views/app/livechatReadOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { FlowRouter } from 'meteor/kadira:flow-router';
import { ChatRoom, CachedChatRoom } from '../../../../models/client';
import { callWithErrorHandling } from '../../../../../client/lib/utils/callWithErrorHandling';
import { APIClient } from '../../../../utils/client';
import { RoomManager } from '../../../../ui-utils/client/lib/RoomManager';
import { inquiryDataStream } from '../../lib/stream/inquiry';
import { dispatchToastMessage } from '../../../../../client/lib/toast';
import './livechatReadOnly.html';
Expand Down Expand Up @@ -91,6 +90,8 @@ Template.livechatReadOnly.onCreated(async function () {
this.inquiry.set(inquiry);
};

this.roomDataStream = new Meteor.Streamer('room-data');

Meteor.call('livechat:getRoutingConfig', (err, config) => {
if (config) {
this.routingConfig.set(config);
Expand All @@ -108,7 +109,7 @@ Template.livechatReadOnly.onCreated(async function () {
const { room } = await APIClient.get(`/v1/rooms.info`, { roomId });
this.room.set(room);
if (room && room._id) {
RoomManager.roomStream.on(roomId, (room) => this.room.set(room));
this.roomDataStream.on(roomId, (room) => this.room.set(room));
}

this.preparing.set(false);
Expand All @@ -124,5 +125,5 @@ Template.livechatReadOnly.onDestroyed(function () {
}

const { rid } = Template.currentData();
RoomManager.roomStream.removeListener(rid);
this.roomDataStream.removeListener(rid);
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { settings } from '../../../../../settings';
import { t } from '../../../../../utils';
import { hasRole, hasPermission, hasAtLeastOnePermission } from '../../../../../authorization';
import { APIClient } from '../../../../../utils/client';
import { RoomManager } from '../../../../../ui-utils/client';
import { getCustomFormTemplate } from '../customTemplates/register';
import { Markdown } from '../../../../../markdown/client';
import { formatDateAndTime } from '../../../../../../client/lib/utils/formatDateAndTime';
Expand Down Expand Up @@ -414,8 +413,10 @@ Template.visitorInfo.onCreated(function () {
this.updateRoom(room);
};

this.roomDataStream = new Meteor.Streamer('room-data');

if (rid) {
RoomManager.roomStream.on(rid, this.updateRoom);
this.roomDataStream.on(rid, this.updateRoom);
loadRoomData(rid);
}

Expand All @@ -436,5 +437,5 @@ Template.visitorInfo.onCreated(function () {

Template.visitorInfo.onDestroyed(function () {
const { rid } = Template.currentData();
RoomManager.roomStream.removeListener(rid, this.updateRoom);
this.roomDataStream.removeListener(rid, this.updateRoom);
});
5 changes: 5 additions & 0 deletions apps/meteor/app/livechat/server/hooks/leadCapture.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LivechatVisitors } from '@rocket.chat/models';
import { isOmnichannelRoom } from '@rocket.chat/core-typings';

import { callbacks } from '../../../../lib/callbacks';
import { settings } from '../../../settings/server';
Expand Down Expand Up @@ -30,6 +31,10 @@ function validateMessage(message, room) {
callbacks.add(
'afterSaveMessage',
function (message, room) {
if (!isOmnichannelRoom(room)) {
return message;
}

if (!validateMessage(message, room)) {
return message;
}
Expand Down
Loading

0 comments on commit e90d40f

Please sign in to comment.