Skip to content

Commit

Permalink
Revert "Federation improvements (#15234)"
Browse files Browse the repository at this point in the history
This reverts commit f5b0a61.
  • Loading branch information
sampaiodiego committed Aug 28, 2019
1 parent d8d3e8a commit b389818
Show file tree
Hide file tree
Showing 27 changed files with 170 additions and 263 deletions.
4 changes: 4 additions & 0 deletions app/federation/client/admin/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ let templateInstance; // current template instance/context
const updateOverviewData = () => {
Meteor.call('federation:getOverviewData', (error, result) => {
if (error) {
console.log(error);

return;
}

Expand All @@ -30,6 +32,8 @@ const updateOverviewData = () => {
const updateServers = () => {
Meteor.call('federation:getServers', (error, result) => {
if (error) {
console.log(error);

return;
}

Expand Down
2 changes: 2 additions & 0 deletions app/federation/client/admin/visualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ let latestEventTimestamp = moment().startOf('week');
const loadContextEvents = () => {
Meteor.call('federation:loadContextEvents', latestEventTimestamp.toISOString(), (error, result) => {
if (error) {
console.log(error);

return;
}

Expand Down
20 changes: 9 additions & 11 deletions app/federation/server/_client/callbacks/afterAddedToRoom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { callbacks } from '../../../../callbacks';
import { logger } from '../../logger';
import { isFederated, getFederatedRoomData } from './helpers/federatedResources';
import getFederatedRoomData from './helpers/getFederatedRoomData';
import getFederatedUserData from './helpers/getFederatedUserData';
import { FederationRoomEvents, Subscriptions } from '../../../../models/server';
import { Federation } from '../../federation';
import { normalizers } from '../../normalizers';
Expand All @@ -8,12 +10,12 @@ import { doAfterCreateRoom } from './afterCreateRoom';
async function afterAddedToRoom(involvedUsers, room) {
const { user: addedUser } = involvedUsers;

if (!isFederated(room) && !isFederated(addedUser)) { return; }
// If there are not federated users on this room, ignore it
const { hasFederatedUser, users, subscriptions } = getFederatedRoomData(room);

logger.client.debug(() => `afterAddedToRoom => involvedUsers=${ JSON.stringify(involvedUsers, null, 2) } room=${ JSON.stringify(room, null, 2) }`);
if (!hasFederatedUser && !getFederatedUserData(addedUser).isFederated) { return; }

// If there are not federated users on this room, ignore it
const { users, subscriptions } = getFederatedRoomData(room);
logger.client.debug(`afterAddedToRoom => involvedUsers=${ JSON.stringify(involvedUsers, null, 2) } room=${ JSON.stringify(room, null, 2) }`);

// Load the subscription
const subscription = Promise.await(Subscriptions.findOneByRoomIdAndUserId(room._id, addedUser._id));
Expand Down Expand Up @@ -52,14 +54,10 @@ async function afterAddedToRoom(involvedUsers, room) {
// Remove the user subscription from the room
Promise.await(Subscriptions.remove({ _id: subscription._id }));

logger.client.error(() => `afterAddedToRoom => involvedUsers=${ JSON.stringify(involvedUsers, null, 2) } => Could not add user: ${ err }`);
logger.client.error(`afterAddedToRoom => involvedUsers=${ JSON.stringify(involvedUsers, null, 2) } => Could not add user: ${ err }`);
}

return involvedUsers;
}

export const definition = {
hook: 'afterAddedToRoom',
callback: (roomOwner, room) => Promise.await(afterAddedToRoom(roomOwner, room)),
id: 'federation-after-added-to-room',
};
callbacks.add('afterAddedToRoom', (roomOwner, room) => Promise.await(afterAddedToRoom(roomOwner, room)), callbacks.priority.LOW, 'federation-after-added-to-room');
11 changes: 4 additions & 7 deletions app/federation/server/_client/callbacks/afterCreateDirectRoom.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { callbacks } from '../../../../callbacks';
import { logger } from '../../logger';
import { FederationRoomEvents, Subscriptions } from '../../../../models/server';
import { Federation } from '../../federation';
import { normalizers } from '../../normalizers';
import { deleteRoom } from '../../../../lib/server/functions';

async function afterCreateDirectRoom(room, extras) {
logger.client.debug(() => `afterCreateDirectRoom => room=${ JSON.stringify(room, null, 2) } extras=${ JSON.stringify(extras, null, 2) }`);
logger.client.debug(`afterCreateDirectRoom => room=${ JSON.stringify(room, null, 2) } extras=${ JSON.stringify(extras, null, 2) }`);

// If the room is federated, ignore
if (room.federation) { return; }
Expand Down Expand Up @@ -60,14 +61,10 @@ async function afterCreateDirectRoom(room, extras) {
} catch (err) {
Promise.await(deleteRoom(room._id));

logger.client.error(() => `afterCreateDirectRoom => room=${ JSON.stringify(room, null, 2) } => Could not create federated room: ${ err }`);
logger.client.error(`afterCreateDirectRoom => room=${ JSON.stringify(room, null, 2) } => Could not create federated room: ${ err }`);
}

return room;
}

export const definition = {
hook: 'afterCreateDirectRoom',
callback: (room, extras) => Promise.await(afterCreateDirectRoom(room, extras)),
id: 'federation-after-create-direct-room',
};
callbacks.add('afterCreateDirectRoom', (room, extras) => Promise.await(afterCreateDirectRoom(room, extras)), callbacks.priority.LOW, 'federation-after-create-direct-room');
19 changes: 9 additions & 10 deletions app/federation/server/_client/callbacks/afterCreateRoom.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { callbacks } from '../../../../callbacks';
import { logger } from '../../logger';
import { FederationRoomEvents, Subscriptions, Users } from '../../../../models/server';
import { Federation } from '../../federation';
import { normalizers } from '../../normalizers';
import { deleteRoom } from '../../../../lib/server/functions';

export async function doAfterCreateRoom(room, users, subscriptions) {
async function run(room, users, subscriptions) {
//
// Genesis
//
Expand Down Expand Up @@ -63,21 +64,19 @@ async function afterCreateRoom(roomOwner, room) {
// If there are not federated users on this room, ignore it
if (!hasFederatedUser) { return; }

logger.client.debug(() => `afterCreateRoom => roomOwner=${ JSON.stringify(roomOwner, null, 2) } room=${ JSON.stringify(room, null, 2) }`);
logger.client.debug(`afterCreateRoom => roomOwner=${ JSON.stringify(roomOwner, null, 2) } room=${ JSON.stringify(room, null, 2) }`);

try {
await doAfterCreateRoom(room, users, subscriptions);
await run(room, users, subscriptions);
} catch (err) {
deleteRoom(room._id);
Promise.await(deleteRoom(room._id));

logger.client.error(() => `afterCreateRoom => room=${ JSON.stringify(room, null, 2) } => Could not create federated room: ${ err }`);
logger.client.error(`afterCreateRoom => room=${ JSON.stringify(room, null, 2) } => Could not create federated room: ${ err }`);
}

return room;
}

export const definition = {
hook: 'afterCreateRoom',
callback: (roomOwner, room) => Promise.await(afterCreateRoom(roomOwner, room)),
id: 'federation-after-create-room',
};
export const doAfterCreateRoom = run;

callbacks.add('afterCreateRoom', (roomOwner, room) => Promise.await(afterCreateRoom(roomOwner, room)), callbacks.priority.LOW, 'federation-after-create-room');
13 changes: 5 additions & 8 deletions app/federation/server/_client/callbacks/afterDeleteMessage.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { FederationRoomEvents, Rooms } from '../../../../models/server';
import { callbacks } from '../../../../callbacks';
import { logger } from '../../logger';
import { Federation } from '../../federation';
import { isFederated } from './helpers/federatedResources';
import getFederatedRoomData from './helpers/getFederatedRoomData';

async function afterDeleteMessage(message) {
const room = Rooms.findOneById(message.rid);

// If there are not federated users on this room, ignore it
if (!isFederated(room)) { return; }
if (!getFederatedRoomData(room).hasFederatedUser) { return; }

logger.client.debug(() => `afterDeleteMessage => message=${ JSON.stringify(message, null, 2) } room=${ JSON.stringify(room, null, 2) }`);
logger.client.debug(`afterDeleteMessage => message=${ JSON.stringify(message, null, 2) } room=${ JSON.stringify(room, null, 2) }`);

// Create the delete message event
const event = await FederationRoomEvents.createDeleteMessageEvent(Federation.domain, room._id, message._id);
Expand All @@ -20,8 +21,4 @@ async function afterDeleteMessage(message) {
return message;
}

export const definition = {
hook: 'afterDeleteMessage',
callback: (message) => Promise.await(afterDeleteMessage(message)),
id: 'federation-after-delete-message',
};
callbacks.add('afterDeleteMessage', (message) => Promise.await(afterDeleteMessage(message)), callbacks.priority.LOW, 'federation-after-delete-message');
13 changes: 5 additions & 8 deletions app/federation/server/_client/callbacks/afterMuteUser.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { FederationRoomEvents } from '../../../../models/server';
import { callbacks } from '../../../../callbacks';
import { logger } from '../../logger';
import { Federation } from '../../federation';
import { normalizers } from '../../normalizers';
import { isFederated } from './helpers/federatedResources';
import getFederatedRoomData from './helpers/getFederatedRoomData';

async function afterMuteUser(involvedUsers, room) {
// If there are not federated users on this room, ignore it
if (!isFederated(room)) { return; }
if (!getFederatedRoomData(room).hasFederatedUser) { return; }

logger.client.debug(() => `afterMuteUser => involvedUsers=${ JSON.stringify(involvedUsers, null, 2) } room=${ JSON.stringify(room, null, 2) }`);
logger.client.debug(`afterMuteUser => involvedUsers=${ JSON.stringify(involvedUsers, null, 2) } room=${ JSON.stringify(room, null, 2) }`);

const { mutedUser } = involvedUsers;

Expand All @@ -21,8 +22,4 @@ async function afterMuteUser(involvedUsers, room) {
return involvedUsers;
}

export const definition = {
hook: 'afterMuteUser',
callback: (involvedUsers, room) => Promise.await(afterMuteUser(involvedUsers, room)),
id: 'federation-after-mute-user',
};
callbacks.add('afterMuteUser', (involvedUsers, room) => Promise.await(afterMuteUser(involvedUsers, room)), callbacks.priority.LOW, 'federation-after-mute-user');
20 changes: 9 additions & 11 deletions app/federation/server/_client/callbacks/afterRemoveFromRoom.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { callbacks } from '../../../../callbacks';
import { FederationRoomEvents } from '../../../../models/server';
import { isFederated, getFederatedRoomData } from './helpers/federatedResources';
import getFederatedRoomData from './helpers/getFederatedRoomData';
import getFederatedUserData from './helpers/getFederatedUserData';
import { logger } from '../../logger';
import { normalizers } from '../../normalizers';
import { Federation } from '../../federation';

async function afterRemoveFromRoom(involvedUsers, room) {
const { removedUser } = involvedUsers;

// If there are not federated users on this room, ignore it
if (!isFederated(room) && !isFederated(removedUser)) { return; }
const { hasFederatedUser, users } = getFederatedRoomData(room);

logger.client.debug(() => `afterRemoveFromRoom => involvedUsers=${ JSON.stringify(involvedUsers, null, 2) } room=${ JSON.stringify(room, null, 2) }`);
// If there are not federated users on this room, ignore it
if (!hasFederatedUser && !getFederatedUserData(removedUser).isFederated) { return; }

const { users } = getFederatedRoomData(room);
logger.client.debug(`afterRemoveFromRoom => involvedUsers=${ JSON.stringify(involvedUsers, null, 2) } room=${ JSON.stringify(room, null, 2) }`);

try {
// Get the domains after removal
Expand All @@ -37,16 +39,12 @@ async function afterRemoveFromRoom(involvedUsers, room) {
// Dispatch the events
Federation.client.dispatchEvent(domainsBeforeRemoval, removeUserEvent);
} catch (err) {
logger.client.error(() => `afterRemoveFromRoom => involvedUsers=${ JSON.stringify(involvedUsers, null, 2) } => Could not add user: ${ err }`);
logger.client.error(`afterRemoveFromRoom => involvedUsers=${ JSON.stringify(involvedUsers, null, 2) } => Could not add user: ${ err }`);

throw err;
}

return involvedUsers;
}

export const definition = {
hook: 'afterRemoveFromRoom',
callback: (roomOwner, room) => Promise.await(afterRemoveFromRoom(roomOwner, room)),
id: 'federation-after-remove-from-room',
};
callbacks.add('afterRemoveFromRoom', (roomOwner, room) => Promise.await(afterRemoveFromRoom(roomOwner, room)), callbacks.priority.LOW, 'federation-after-remove-from-room');
13 changes: 5 additions & 8 deletions app/federation/server/_client/callbacks/afterSaveMessage.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { callbacks } from '../../../../callbacks';
import { logger } from '../../logger';
import { FederationRoomEvents } from '../../../../models/server';
import { Federation } from '../../federation';
import { normalizers } from '../../normalizers';
import { isFederated } from './helpers/federatedResources';
import getFederatedRoomData from './helpers/getFederatedRoomData';

async function afterSaveMessage(message, room) {
// If there are not federated users on this room, ignore it
if (!isFederated(room)) { return; }
if (!getFederatedRoomData(room).hasFederatedUser) { return; }

logger.client.debug(() => `afterSaveMessage => message=${ JSON.stringify(message, null, 2) } room=${ JSON.stringify(room, null, 2) }`);
logger.client.debug(`afterSaveMessage => message=${ JSON.stringify(message, null, 2) } room=${ JSON.stringify(room, null, 2) }`);

let event;

Expand All @@ -27,8 +28,4 @@ async function afterSaveMessage(message, room) {
return message;
}

export const definition = {
hook: 'afterSaveMessage',
callback: (message, room) => Promise.await(afterSaveMessage(message, room)),
id: 'federation-after-save-message',
};
callbacks.add('afterSaveMessage', (message, room) => Promise.await(afterSaveMessage(message, room)), callbacks.priority.LOW, 'federation-after-save-message');
15 changes: 6 additions & 9 deletions app/federation/server/_client/callbacks/afterSetReaction.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import _ from 'underscore';

import { FederationRoomEvents, Rooms } from '../../../../models/server';
import { callbacks } from '../../../../callbacks';
import { logger } from '../../logger';
import { Federation } from '../../federation';
import { isFederated } from './helpers/federatedResources';
import getFederatedRoomData from './helpers/getFederatedRoomData';

async function afterSetReaction(message, { user, reaction }) {
const room = Rooms.findOneById(message.rid, { fields: { _id: 1, federation: 1 } });
const room = Rooms.findOneById(message.rid);

// If there are not federated users on this room, ignore it
if (!isFederated(room)) { return; }
if (!getFederatedRoomData(room).hasFederatedUser) { return; }

logger.client.debug(() => `afterSetReaction => message=${ JSON.stringify(_.pick(message, '_id', 'msg'), null, 2) } room=${ JSON.stringify(_.pick(room, '_id'), null, 2) } user=${ JSON.stringify(_.pick(user, 'username'), null, 2) } reaction=${ reaction }`);
logger.client.debug(`afterSetReaction => message=${ JSON.stringify(_.pick(message, '_id', 'msg'), null, 2) } room=${ JSON.stringify(_.pick(room, '_id'), null, 2) } user=${ JSON.stringify(_.pick(user, 'username'), null, 2) } reaction=${ reaction }`);

// Create the event
const event = await FederationRoomEvents.createSetMessageReactionEvent(Federation.domain, room._id, message._id, user.username, reaction);
Expand All @@ -22,8 +23,4 @@ async function afterSetReaction(message, { user, reaction }) {
return message;
}

export const definition = {
hook: 'afterSetReaction',
callback: (message, extras) => Promise.await(afterSetReaction(message, extras)),
id: 'federation-after-set-reaction',
};
callbacks.add('afterSetReaction', (message, extras) => Promise.await(afterSetReaction(message, extras)), callbacks.priority.LOW, 'federation-after-set-reaction');
13 changes: 5 additions & 8 deletions app/federation/server/_client/callbacks/afterUnmuteUser.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { FederationRoomEvents } from '../../../../models/server';
import { callbacks } from '../../../../callbacks';
import { logger } from '../../logger';
import { Federation } from '../../federation';
import { normalizers } from '../../normalizers';
import { isFederated } from './helpers/federatedResources';
import getFederatedRoomData from './helpers/getFederatedRoomData';

async function afterUnmuteUser(involvedUsers, room) {
// If there are not federated users on this room, ignore it
if (!isFederated(room)) { return; }
if (!getFederatedRoomData(room).hasFederatedUser) { return; }

logger.client.debug(() => `afterUnmuteUser => involvedUsers=${ JSON.stringify(involvedUsers, null, 2) } room=${ JSON.stringify(room, null, 2) }`);
logger.client.debug(`afterUnmuteUser => involvedUsers=${ JSON.stringify(involvedUsers, null, 2) } room=${ JSON.stringify(room, null, 2) }`);

const { unmutedUser } = involvedUsers;

Expand All @@ -21,8 +22,4 @@ async function afterUnmuteUser(involvedUsers, room) {
return involvedUsers;
}

export const definition = {
hook: 'afterUnmuteUser',
callback: (involvedUsers, room) => Promise.await(afterUnmuteUser(involvedUsers, room)),
id: 'federation-after-unmute-user',
};
callbacks.add('afterUnmuteUser', (involvedUsers, room) => Promise.await(afterUnmuteUser(involvedUsers, room)), callbacks.priority.LOW, 'federation-after-unmute-user');
15 changes: 6 additions & 9 deletions app/federation/server/_client/callbacks/afterUnsetReaction.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import _ from 'underscore';

import { FederationRoomEvents, Rooms } from '../../../../models/server';
import { callbacks } from '../../../../callbacks';
import { logger } from '../../logger';
import { Federation } from '../../federation';
import { isFederated } from './helpers/federatedResources';
import getFederatedRoomData from './helpers/getFederatedRoomData';

async function afterUnsetReaction(message, { user, reaction }) {
const room = Rooms.findOneById(message.rid, { fields: { _id: 1, federation: 1 } });
const room = Rooms.findOneById(message.rid);

// If there are not federated users on this room, ignore it
if (!isFederated(room)) { return; }
if (!getFederatedRoomData(room).hasFederatedUser) { return; }

logger.client.debug(() => `afterUnsetReaction => message=${ JSON.stringify(_.pick(message, '_id', 'msg'), null, 2) } room=${ JSON.stringify(_.pick(room, '_id'), null, 2) } user=${ JSON.stringify(_.pick(user, 'username'), null, 2) } reaction=${ reaction }`);
logger.client.debug(`afterUnsetReaction => message=${ JSON.stringify(_.pick(message, '_id', 'msg'), null, 2) } room=${ JSON.stringify(_.pick(room, '_id'), null, 2) } user=${ JSON.stringify(_.pick(user, 'username'), null, 2) } reaction=${ reaction }`);

// Create the event
const event = await FederationRoomEvents.createUnsetMessageReactionEvent(Federation.domain, room._id, message._id, user.username, reaction);
Expand All @@ -22,8 +23,4 @@ async function afterUnsetReaction(message, { user, reaction }) {
return message;
}

export const definition = {
hook: 'afterUnsetReaction',
callback: (message, extras) => Promise.await(afterUnsetReaction(message, extras)),
id: 'federation-after-unset-reaction',
};
callbacks.add('afterUnsetReaction', (message, extras) => Promise.await(afterUnsetReaction(message, extras)), callbacks.priority.LOW, 'federation-after-unset-reaction');
Loading

0 comments on commit b389818

Please sign in to comment.