Skip to content

Commit

Permalink
Merge branch 'develop' into feat/react-root
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan authored Mar 28, 2020
2 parents 6b7e60d + 7f7a551 commit d4e4073
Show file tree
Hide file tree
Showing 24 changed files with 131 additions and 59 deletions.
7 changes: 3 additions & 4 deletions app/apps/client/gameCenter/gameCenter.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import toastr from 'toastr';
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';

import { modal } from '../../../ui-utils/client';
import { APIClient, t } from '../../../utils/client';
import { APIClient, t, handleError } from '../../../utils/client';

const getExternalComponents = async (instance) => {
try {
const { externalComponents } = await APIClient.get('apps/externalComponents');
instance.games.set(externalComponents);
} catch (e) {
toastr.error((e.xhr.responseJSON && e.xhr.responseJSON.error) || e.message);
handleError(e);
}

instance.isLoading.set(false);
Expand Down Expand Up @@ -98,7 +97,7 @@ Template.GameCenter.events({
'click .js-invite'(event) {
event.stopPropagation();
modal.open({
title: t('Invite You Friends to Join'),
title: t('Apps_Game_Center_Invite_Friends'),
content: 'InvitePlayers',
data: this,
confirmOnEnter: false,
Expand Down
2 changes: 1 addition & 1 deletion app/apps/client/gameCenter/gameContainer.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{{#if showBackButton}}
<button
class="rc-button rc-button--nude contextual-bar__header-back-btn js-back"
title="{{_ 'Back_to_Game_Center'}}"
title="{{_ 'Apps_Game_Center_Back'}}"
>
<i class="icon-angle-left"></i>
</button>
Expand Down
22 changes: 16 additions & 6 deletions app/apps/client/gameCenter/invitePlayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { Blaze } from 'meteor/blaze';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { Tracker } from 'meteor/tracker';
import { Session } from 'meteor/session';

import { AutoComplete } from '../../../meteor-autocomplete/client';
import { roomTypes } from '../../../utils/client';
Expand Down Expand Up @@ -79,15 +81,23 @@ Template.InvitePlayers.events({

roomTypes.openRouteLink(result.t, result);

// setTimeout ensures the message is only sent after the
// This ensures the message is only sent after the
// user has been redirected to the new room, preventing a
// weird bug that made the message appear as unsent until
// the screen gets refreshed
setTimeout(() => call('sendMessage', {
_id: Random.id(),
rid: result.rid,
msg: TAPi18n.__('Game_Center_Play_Game_Together', { name }),
}), 100);
Tracker.autorun((c) => {
if (Session.get('openedRoom') !== result.rid) {
return;
}

call('sendMessage', {
_id: Random.id(),
rid: result.rid,
msg: TAPi18n.__('Apps_Game_Center_Play_Game_Together', { name }),
});

c.stop();
});

modal.close();
} catch (err) {
Expand Down
8 changes: 2 additions & 6 deletions app/apps/client/gameCenter/tabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,27 @@ import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';

import { APIClient } from '../../../utils/client';
import { TabBar, TABBAR_DEFAULT_VISIBLE_ICON_COUNT } from '../../../ui-utils/client';
import { TabBar } from '../../../ui-utils/client';
import { settings } from '../../../settings/client';

import './gameCenter.html';

Meteor.startup(function() {
Tracker.autorun(async function() {
if (!settings.get('Apps_Game_Center_enabled')) {
TabBar.size = TABBAR_DEFAULT_VISIBLE_ICON_COUNT;
return TabBar.removeButton('gameCenter');
}

const { externalComponents } = await APIClient.get('apps/externalComponents');

if (!externalComponents.length) {
TabBar.size = TABBAR_DEFAULT_VISIBLE_ICON_COUNT;
return TabBar.removeButton('gameCenter');
}

TabBar.size = TABBAR_DEFAULT_VISIBLE_ICON_COUNT + 1;

TabBar.addButton({
groups: ['channel', 'group', 'direct'],
id: 'gameCenter',
i18nTitle: 'Game_Center',
i18nTitle: 'Apps_Game_Center',
icon: 'game',
template: 'GameCenter',
order: -1,
Expand Down
8 changes: 7 additions & 1 deletion app/invites/server/functions/findOrCreateInvite.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { Random } from 'meteor/random';

import { hasPermission } from '../../../authorization';
import { Notifications } from '../../../notifications';
import { Invites, Subscriptions } from '../../../models';
import { Invites, Subscriptions, Rooms } from '../../../models/server';
import { settings } from '../../../settings';
import { getURL } from '../../../utils/lib/getURL';
import { roomTypes, RoomMemberActions } from '../../../utils/server';

function getInviteUrl(invite) {
const { _id } = invite;
Expand Down Expand Up @@ -40,6 +41,11 @@ export const findOrCreateInvite = (userId, invite) => {
throw new Meteor.Error('error-invalid-room', 'The rid field is invalid', { method: 'findOrCreateInvite', field: 'rid' });
}

const room = Rooms.findOneById(invite.rid);
if (!roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.INVITE)) {
throw new Meteor.Error('error-room-type-not-allowed', 'Cannot create invite links for this room type', { method: 'findOrCreateInvite' });
}

let { days, maxUses } = invite;

if (!possibleDays.includes(days)) {
Expand Down
5 changes: 5 additions & 0 deletions app/invites/server/functions/useInviteToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Meteor } from 'meteor/meteor';
import { Invites, Users, Subscriptions } from '../../../models/server';
import { validateInviteToken } from './validateInviteToken';
import { addUserToRoom } from '../../../lib/server/functions/addUserToRoom';
import { roomTypes, RoomMemberActions } from '../../../utils/server';

export const useInviteToken = (userId, token) => {
if (!userId) {
Expand All @@ -15,6 +16,10 @@ export const useInviteToken = (userId, token) => {

const { inviteData, room } = validateInviteToken(token);

if (!roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.INVITE)) {
throw new Meteor.Error('error-room-type-not-allowed', 'Can\'t join room of this type via invite', { method: 'useInviteToken', field: 'token' });
}

const user = Users.findOneById(userId);
Users.updateInviteToken(user._id, token);

Expand Down
13 changes: 10 additions & 3 deletions app/lib/lib/roomTypes/direct.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,17 @@ export class DirectMessageRoomType extends RoomTypeConfig {
return {};
}

const title = settings.get('UI_Use_Real_Name') ? user.name : `@${ user.username }`;
const text = notificationMessage;
if (this.isGroupChat(room)) {
return {
title: this.roomName(room),
text: `${ (settings.get('UI_Use_Real_Name') && user.name) || user.username }: ${ notificationMessage }`,
};
}

return { title, text };
return {
title: (settings.get('UI_Use_Real_Name') && user.name) || user.username,
text: notificationMessage,
};
}

getAvatarPath(roomData, subData) {
Expand Down
6 changes: 6 additions & 0 deletions app/lib/server/functions/addUserToRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import { Meteor } from 'meteor/meteor';

import { Rooms, Subscriptions, Messages } from '../../../models';
import { callbacks } from '../../../callbacks';
import { roomTypes, RoomMemberActions } from '../../../utils/server';

export const addUserToRoom = function(rid, user, inviter, silenced) {
const now = new Date();
const room = Rooms.findOneById(rid);

const roomConfig = roomTypes.getConfig(room.t);
if (!roomConfig.allowMemberAction(room, RoomMemberActions.JOIN) && !roomConfig.allowMemberAction(room, RoomMemberActions.INVITE)) {
return;
}

// Check if user is already in room
const subscription = Subscriptions.findOneByRoomIdAndUserId(rid, user._id);
if (subscription) {
Expand Down
29 changes: 19 additions & 10 deletions app/lib/server/functions/deleteUser.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';

import { FileUpload } from '../../../file-upload';
import { FileUpload } from '../../../file-upload/server';
import { Users, Subscriptions, Messages, Rooms, Integrations, FederationServers } from '../../../models/server';
import { hasRole, getUsersInRole } from '../../../authorization/server';
import { settings } from '../../../settings/server';
import { Notifications } from '../../../notifications/server';
import { updateGroupDMsName } from './updateGroupDMsName';

const bulkRoomCleanUp = (rids) => {
// no bulk deletion for files
rids.forEach((rid) => FileUpload.removeFilesByRoomId(rid));

return Promise.await(Promise.all([
Subscriptions.removeByRoomIds(rids),
Messages.removeByRoomIds(rids),
Rooms.removeByIds(rids),
]));
};

export const deleteUser = function(userId) {
const user = Users.findOneById(userId, {
fields: { username: 1, avatarOrigin: 1, federation: 1 },
Expand Down Expand Up @@ -83,21 +94,19 @@ export const deleteUser = function(userId) {
break;
}

roomCache.forEach((roomData) => {
const roomIds = roomCache.filter((roomData) => {
if (roomData.subscribers === null && roomData.t !== 'd' && roomData.t !== 'c') {
roomData.subscribers = Subscriptions.findByRoomId(roomData.rid).count();
}

// Remove non-channel rooms with only 1 user (the one being deleted)
if (roomData.t !== 'c' && roomData.subscribers === 1) {
Subscriptions.removeByRoomId(roomData.rid);
FileUpload.removeFilesByRoomId(roomData.rid);
Messages.removeByRoomId(roomData.rid);
Rooms.removeById(roomData.rid);
}
});
return roomData.t !== 'c' && roomData.subscribers === 1;
}).map(({ _id }) => _id);

Rooms.find1On1ByUserId(user._id, { fields: { _id: 1 } }).forEach(({ _id }) => roomIds.push(_id));

bulkRoomCleanUp(roomIds);

// TODO: do not remove group DMs
Rooms.updateGroupDMsRemovingUsernamesByUsername(user.username); // Remove direct rooms with the user
Rooms.removeDirectRoomContainingUsername(user.username); // Remove direct rooms with the user

Expand Down
8 changes: 5 additions & 3 deletions app/lib/server/functions/notifications/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ function getEmailContent({ message, user, room }) {
const roomName = s.escapeHTML(`#${ roomTypes.getRoomName(room.t, room) }`);
const userName = s.escapeHTML(settings.get('UI_Use_Real_Name') ? message.u.name || message.u.username : message.u.username);

const header = TAPi18n.__(room.t === 'd' ? 'User_sent_a_message_to_you' : 'User_sent_a_message_on_channel', {
const roomType = roomTypes.getConfig(room.t);

const header = TAPi18n.__(!roomType.isGroupChat(room) ? 'User_sent_a_message_to_you' : 'User_sent_a_message_on_channel', {
username: userName,
channel: roomName,
lng,
Expand Down Expand Up @@ -54,7 +56,7 @@ function getEmailContent({ message, user, room }) {
}

if (message.file) {
const fileHeader = TAPi18n.__(room.t === 'd' ? 'User_uploaded_a_file_to_you' : 'User_uploaded_a_file_on_channel', {
const fileHeader = TAPi18n.__(!roomType.isGroupChat(room) ? 'User_uploaded_a_file_to_you' : 'User_uploaded_a_file_on_channel', {
username: userName,
channel: roomName,
lng,
Expand Down Expand Up @@ -112,7 +114,7 @@ export function sendEmail({ message, user, subscription, room, emailAddress, has
const username = settings.get('UI_Use_Real_Name') ? message.u.name || message.u.username : message.u.username;
let subjectKey = 'Offline_Mention_All_Email';

if (room.t === 'd') {
if (!roomTypes.getConfig(room.t).isGroupChat(room)) {
subjectKey = 'Offline_DM_Email';
} else if (hasMentionToUser) {
subjectKey = 'Offline_Mention_Email';
Expand Down
2 changes: 1 addition & 1 deletion app/lib/server/functions/notifications/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function sendSinglePush({ room, message, userId, receiverUsername,
messageType: message.t,
messageId: message._id,
},
roomName: settings.get('Push_show_username_room') && room.t !== 'd' ? `#${ roomTypes.getRoomName(room.t, room) }` : '',
roomName: settings.get('Push_show_username_room') && roomTypes.getConfig(room.t).isGroupChat(room) ? `#${ roomTypes.getRoomName(room.t, room) }` : '',
username,
message: settings.get('Push_show_message') ? notificationMessage : ' ',
badge: await getBadgeCount(userId),
Expand Down
8 changes: 6 additions & 2 deletions app/livestream/client/tabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ Meteor.startup(function() {
Tracker.autorun(function() {
TabBar.removeButton('livestream');
if (settings.get('Livestream_enabled')) {
const live = Rooms.findOne({ _id: Session.get('openedRoom'), 'streamingOptions.type': 'livestream', 'streamingOptions.id': { $exists: 1 } }, { fields: { streamingOptions: 1 } });
TabBar.size = live ? 5 : 4;
const live = Rooms.findOne({
_id: Session.get('openedRoom'),
'streamingOptions.type': 'livestream',
'streamingOptions.id': { $exists: 1 },
}, { fields: { streamingOptions: 1 } });

return TabBar.addButton({
groups: ['channel', 'group'],
id: 'livestream',
Expand Down
4 changes: 4 additions & 0 deletions app/models/server/models/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,10 @@ export class Messages extends Base {
return this.remove(query);
}

removeByRoomIds(rids) {
return this.remove({ rid: { $in: rids } });
}

removeByIdPinnedTimestampLimitAndUsers(rid, pinned, ignoreDiscussion = true, ts, limit, users = []) {
const query = {
rid,
Expand Down
16 changes: 9 additions & 7 deletions app/models/server/models/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,13 @@ export class Rooms extends Base {
}, options);
}

find1On1ByUserId(userId, options) {
return this.find({
uids: userId,
usersCount: 2,
}, options);
}

// UPDATE
addImportIds(_id, importIds) {
importIds = [].concat(importIds);
Expand Down Expand Up @@ -1025,13 +1032,8 @@ export class Rooms extends Base {
return this.remove(query);
}

remove1on1ById(_id) {
const query = {
_id,
usersCount: { $lte: 2 },
};

return this.remove(query);
removeByIds(ids) {
return this.remove({ _id: { $in: ids } });
}

removeDirectRoomContainingUsername(username) {
Expand Down
4 changes: 4 additions & 0 deletions app/models/server/models/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,10 @@ export class Subscriptions extends Base {
return result;
}

removeByRoomIds(rids) {
return this.remove({ rid: { $in: rids } });
}

// //////////////////////////////////////////////////////////////////
// threads

Expand Down
6 changes: 3 additions & 3 deletions app/ui-flextab/client/tabs/membersList.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<div class="rc-button__group rc-button__group--stretch">
{{#if canAddUser}}
<button class="rc-button rc-button--primary js-add">{{> icon block="rc-input__icon-svg" icon="plus"}}{{_ "Add_users"}}</button>
{{/if}}

{{#if canInviteUser}}
<button class="rc-button rc-button--primary js-invite">{{> icon block="rc-input__icon-svg" icon="user-plus"}}{{_ "Invite_Users"}}</button>
{{#if canInviteUser}}
<button class="rc-button rc-button--primary js-invite">{{> icon block="rc-input__icon-svg" icon="user-plus"}}{{_ "Invite_Users"}}</button>
{{/if}}
{{/if}}
</div>

Expand Down
3 changes: 2 additions & 1 deletion app/ui-sidenav/client/chatRoomItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ Template.chatRoomItem.helpers({
const roomData = {
...this,
icon: icon !== 'at' && icon,
avatar: roomTypes.getConfig(this.t).getAvatarPath(room, this),
avatar: roomTypes.getConfig(this.t).getAvatarPath(room || this),
username: this.name,
route: roomTypes.getRouteLink(this.t, this),
name: roomType.roomName(this),
unread,
active: false,
archivedClass,
status: this.t === 'd' || this.t === 'l',
isGroupChat: roomType.isGroupChat(room),
};
roomData.username = roomData.username || roomData.name;

Expand Down
2 changes: 1 addition & 1 deletion app/ui-sidenav/client/sidebarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Template.sidebarItem.onCreated(function() {
const renderedMessage = renderMessageBody(currentData.lastMessage).replace(/<br\s?\\?>/g, ' ');
const sender = this.user && this.user._id === currentData.lastMessage.u._id ? t('You') : otherUser;

if (currentData.t === 'd' && Meteor.userId() !== currentData.lastMessage.u._id) {
if (!currentData.isGroupChat && Meteor.userId() !== currentData.lastMessage.u._id) {
this.renderedMessage = currentData.lastMessage.msg === '' ? t('Sent_an_attachment') : renderedMessage;
} else {
this.renderedMessage = currentData.lastMessage.msg === '' ? t('user_sent_an_attachment', { user: sender }) : `${ sender }: ${ renderedMessage }`;
Expand Down
Loading

0 comments on commit d4e4073

Please sign in to comment.