Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[NEW] Matrix Federation UX improvements #25847

Merged
merged 45 commits into from
Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6de70b3
[NEW] Rename slash command from bridge to federation (#25846)
MarcosSpessatto Jun 13, 2022
68cd4be
fix: fix broken build
MarcosSpessatto Jun 13, 2022
63da4b9
fix: fix build
MarcosSpessatto Jun 13, 2022
0fcca93
fix: fix lint
MarcosSpessatto Jun 13, 2022
62561c2
fix: fix broken setting and undefined ID
MarcosSpessatto Jun 21, 2022
a054272
Merge branch 'develop' into feat/federation-ux
MarcosSpessatto Jun 21, 2022
1c165c0
fix: prevent federated rooms to be deleted (#25955)
MarcosSpessatto Jun 22, 2022
23d1fe0
[NEW] remove user from matrix room (#25905)
carlosrodrigues94 Jun 22, 2022
d7d2e6a
[NEW] Hide message actions when the room is federated (#25778)
MarcosSpessatto Jun 22, 2022
86476bb
Merge branch 'develop' into feat/federation-ux
MarcosSpessatto Jun 22, 2022
a6bec19
chore: fix lint
MarcosSpessatto Jun 22, 2022
a3d6d89
fix: fix bad check
MarcosSpessatto Jun 22, 2022
273fcc3
Merge branch 'develop' into feat/federation-ux
MarcosSpessatto Jun 24, 2022
1c73df7
fix: fix lint
MarcosSpessatto Jun 24, 2022
391bb25
Merge branch 'develop' into feat/federation-ux
MarcosSpessatto Jun 27, 2022
c01cd10
port 3300 is the default one, even if one is not determined
alansikora Jun 27, 2022
248309d
[NEW] Feat/federation channel (#25926)
MarcosSpessatto Jun 27, 2022
98f6f27
fix: trying to fix stuck server
MarcosSpessatto Jun 27, 2022
889ddeb
fix: fix server stuck
MarcosSpessatto Jun 27, 2022
96f4228
fix: trying to fix dms
MarcosSpessatto Jun 27, 2022
f9bdef2
fix: final tweaks
MarcosSpessatto Jun 27, 2022
b5c939b
Merge branch 'develop' into feat/federation-ux
MarcosSpessatto Jun 27, 2022
3829053
fix: really final tweaks
MarcosSpessatto Jun 28, 2022
0bdeb72
fix: really really final tweaks
MarcosSpessatto Jun 28, 2022
bd62a0a
Merge branch 'develop' into feat/federation-ux
MarcosSpessatto Jun 28, 2022
d57acab
fix: fix typings
MarcosSpessatto Jun 28, 2022
5fef883
fix: circular dep
MarcosSpessatto Jun 29, 2022
554f910
fix: add missing validation
MarcosSpessatto Jun 29, 2022
327fa8f
fix: wrong factory was being used
MarcosSpessatto Jun 29, 2022
36318cb
fix: do not import stuff directly from the lib
MarcosSpessatto Jun 29, 2022
9bd4855
Merge branch 'develop' into feat/federation-ux
MarcosSpessatto Jun 29, 2022
f3bd649
fix: fixing tests
MarcosSpessatto Jun 29, 2022
0378044
fix: fix lint
MarcosSpessatto Jun 29, 2022
03ddaf9
Merge branch 'develop' into feat/federation-ux
MarcosSpessatto Jun 30, 2022
7408b6e
fix: updating according to review
MarcosSpessatto Jul 1, 2022
d75cb06
Merge branch 'develop' into feat/federation-ux
MarcosSpessatto Jul 1, 2022
e5cc72c
fix: apply suggestion from review
MarcosSpessatto Jul 1, 2022
4a89511
Merge branch 'develop' into feat/federation-ux
MarcosSpessatto Jul 1, 2022
f7cd418
Merge branch 'develop' into feat/federation-ux
MarcosSpessatto Jul 1, 2022
7fb8945
fix: suggestion from backend review
MarcosSpessatto Jul 1, 2022
92ce58f
fix: fix lint
MarcosSpessatto Jul 1, 2022
9239afc
give typecheck only 6GB
sampaiodiego Jul 1, 2022
b951114
fix: trying to fix tests
MarcosSpessatto Jul 1, 2022
230e951
Merge branch 'feat/federation-ux' of github.com:RocketChat/Rocket.Cha…
MarcosSpessatto Jul 1, 2022
67f80ee
Merge branch 'develop' into feat/federation-ux
MarcosSpessatto Jul 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/meteor/.mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = {
exit: true,
spec: [
'ee/tests/**/*.tests.ts',
'ee/tests/**/*.spec.ts',
'tests/unit/app/**/*.spec.ts',
'tests/unit/app/**/*.tests.js',
'tests/unit/app/**/*.tests.ts',
Expand Down
22 changes: 13 additions & 9 deletions apps/meteor/app/discussion/client/tabBar.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { useMemo, lazy } from 'react';
import { useSetting } from '@rocket.chat/ui-contexts';
import { isIRoomFederated } from '@rocket.chat/core-typings';

import { addAction } from '../../../client/views/room/lib/Toolbox';

const template = lazy(() => import('../../../client/views/room/contextualBar/Discussions'));

addAction('discussions', ({ room: { prid } }) => {
addAction('discussions', ({ room }) => {
const discussionEnabled = useSetting('Discussion_enabled');
const federated = isIRoomFederated(room);

return useMemo(
() =>
discussionEnabled && !prid
discussionEnabled && !room.prid
? {
groups: ['channel', 'group', 'direct', 'direct_multiple', 'team'],
id: 'discussions',
title: 'Discussions',
icon: 'discussion',
'groups': ['channel', 'group', 'direct', 'direct_multiple', 'team'],
'id': 'discussions',
'title': 'Discussions',
'icon': 'discussion',
template,
full: true,
order: 3,
'full': true,
'disabled': federated,
'data-tooltip': 'Discussions_unavailable_for_federation',
'order': 3,
}
: null,
[discussionEnabled, prid],
[discussionEnabled, room.prid, federated],
);
});
16 changes: 16 additions & 0 deletions apps/meteor/app/federation-v2/client/Federation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ValueOf } from '@rocket.chat/core-typings';

import { RoomMemberActions } from '../../../definition/IRoomTypeConfig';

const allowedActionsInFederatedRooms: ValueOf<typeof RoomMemberActions>[] = [
RoomMemberActions.REMOVE_USER,
RoomMemberActions.INVITE,
RoomMemberActions.JOIN,
RoomMemberActions.LEAVE,
];

export class Federation {
public static federationActionAllowed(action: ValueOf<typeof RoomMemberActions>): boolean {
return allowedActionsInFederatedRooms.includes(action);
}
}
MarcosSpessatto marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions apps/meteor/app/federation-v2/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './slash-commands';
20 changes: 20 additions & 0 deletions apps/meteor/app/federation-v2/client/slash-commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { slashCommands } from '../../../utils/lib/slashCommand';

const callback = undefined;
const result = undefined;
const providesPreview = false;
const previewer = undefined;
const previewCallback = undefined;

slashCommands.add({
command: 'federation',
callback,
options: {
description: 'Federation_slash_commands',
params: '#command (dm) #user',
},
result,
providesPreview,
previewer,
previewCallback,
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ import {
FederationRoomCreateInputDto,
FederationRoomChangeMembershipDto,
FederationRoomSendInternalMessageDto,
FederationRoomChangeJoinRulesDto,
FederationRoomChangeNameDto,
FederationRoomChangeTopicDto,
} from './input/RoomReceiverDto';

export class FederationRoomServiceReceiver {
constructor(
private rocketRoomAdapter: RocketChatRoomAdapter,
private rocketUserAdapter: RocketChatUserAdapter,
private rocketMessageAdapter: RocketChatMessageAdapter,
private rocketSettingsAdapter: RocketChatSettingsAdapter,
private bridge: IFederationBridge,
protected rocketRoomAdapter: RocketChatRoomAdapter,
protected rocketUserAdapter: RocketChatUserAdapter,
protected rocketMessageAdapter: RocketChatMessageAdapter,
protected rocketSettingsAdapter: RocketChatSettingsAdapter,
protected bridge: IFederationBridge,
) {} // eslint-disable-line no-empty-function

public async createRoom(roomCreateInput: FederationRoomCreateInputDto): Promise<void> {
Expand Down Expand Up @@ -78,14 +75,15 @@ export class FederationRoomServiceReceiver {
leave,
} = roomChangeMembershipInput;
const affectedFederatedRoom = await this.rocketRoomAdapter.getFederatedRoomByExternalId(externalRoomId);

if (!affectedFederatedRoom && eventOrigin === EVENT_ORIGIN.LOCAL) {
throw new Error(`Could not find room with external room id: ${externalRoomId}`);
}
const isInviterFromTheSameHomeServer = await this.bridge.isUserIdFromTheSameHomeserver(
const isInviterFromTheSameHomeServer = this.bridge.isUserIdFromTheSameHomeserver(
externalInviterId,
this.rocketSettingsAdapter.getHomeServerDomain(),
);
const isInviteeFromTheSameHomeServer = await this.bridge.isUserIdFromTheSameHomeserver(
const isInviteeFromTheSameHomeServer = this.bridge.isUserIdFromTheSameHomeserver(
externalInviteeId,
this.rocketSettingsAdapter.getHomeServerDomain(),
);
Expand Down Expand Up @@ -118,9 +116,8 @@ export class FederationRoomServiceReceiver {

const federatedInviteeUser = await this.rocketUserAdapter.getFederatedUserByExternalId(externalInviteeId);
const federatedInviterUser = await this.rocketUserAdapter.getFederatedUserByExternalId(externalInviterId);

if (!affectedFederatedRoom && eventOrigin === EVENT_ORIGIN.REMOTE) {
const members = [federatedInviterUser, federatedInviteeUser] as any[];
const members = [federatedInviterUser, federatedInviteeUser] as FederatedUser[];
const newFederatedRoom = FederatedRoom.createInstance(
externalRoomId,
normalizedRoomId,
Expand All @@ -134,14 +131,42 @@ export class FederationRoomServiceReceiver {
await this.bridge.joinRoom(externalRoomId, externalInviteeId);
}
const federatedRoom = affectedFederatedRoom || (await this.rocketRoomAdapter.getFederatedRoomByExternalId(externalRoomId));

if (leave) {
if (
!(await this.rocketRoomAdapter.isUserAlreadyJoined(
federatedRoom?.internalReference?._id as string,
federatedInviteeUser?.internalReference._id as string,
))
) {
return;
}

return this.rocketRoomAdapter.removeUserFromRoom(
federatedRoom as FederatedRoom,
federatedInviteeUser as FederatedUser,
federatedInviterUser as FederatedUser,
);
}
if (affectedFederatedRoom?.isDirectMessage() && eventOrigin === EVENT_ORIGIN.REMOTE) {
const membersUsernames = [
...(affectedFederatedRoom.internalReference?.usernames || []),
federatedInviteeUser?.internalReference.username as string,
];
const newFederatedRoom = FederatedRoom.createInstance(
externalRoomId,
normalizedRoomId,
federatedInviterUser as FederatedUser,
RoomType.DIRECT_MESSAGE,
externalRoomName,
);
if (affectedFederatedRoom.internalReference?.usernames?.includes(federatedInviteeUser?.internalReference.username || '')) {
return;
}
await this.rocketRoomAdapter.removeDirectMessageRoom(affectedFederatedRoom);
await this.rocketRoomAdapter.createFederatedRoomForDirectMessage(newFederatedRoom, membersUsernames);
return;
}

await this.rocketRoomAdapter.addUserToRoom(
federatedRoom as FederatedRoom,
federatedInviteeUser as FederatedUser,
Expand All @@ -164,54 +189,4 @@ export class FederationRoomServiceReceiver {

await this.rocketMessageAdapter.sendMessage(senderUser, text, federatedRoom);
}

public async changeJoinRules(roomJoinRulesChangeInput: FederationRoomChangeJoinRulesDto): Promise<void> {
const { externalRoomId, roomType } = roomJoinRulesChangeInput;

const federatedRoom = await this.rocketRoomAdapter.getFederatedRoomByExternalId(externalRoomId);
if (!federatedRoom) {
return;
}

if (federatedRoom.isDirectMessage()) {
return;
}

federatedRoom.setRoomType(roomType);
await this.rocketRoomAdapter.updateRoomType(federatedRoom);
}

public async changeRoomName(roomChangeNameInput: FederationRoomChangeNameDto): Promise<void> {
const { externalRoomId, normalizedRoomName } = roomChangeNameInput;

const federatedRoom = await this.rocketRoomAdapter.getFederatedRoomByExternalId(externalRoomId);
if (!federatedRoom) {
return;
}

if (federatedRoom.isDirectMessage()) {
return;
}

federatedRoom.changeRoomName(normalizedRoomName);

await this.rocketRoomAdapter.updateRoomName(federatedRoom);
}

public async changeRoomTopic(roomChangeTopicInput: FederationRoomChangeTopicDto): Promise<void> {
const { externalRoomId, roomTopic } = roomChangeTopicInput;

const federatedRoom = await this.rocketRoomAdapter.getFederatedRoomByExternalId(externalRoomId);
if (!federatedRoom) {
return;
}

if (federatedRoom.isDirectMessage()) {
return;
}

federatedRoom.changeRoomTopic(roomTopic);

await this.rocketRoomAdapter.updateRoomTopic(federatedRoom);
}
}
Loading