-
Notifications
You must be signed in to change notification settings - Fork 291
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
feat: Add stopping to federate (WPB-203) #15583
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #15583 +/- ##
==========================================
- Coverage 43.51% 43.37% -0.15%
==========================================
Files 651 653 +2
Lines 22189 22280 +91
Branches 5080 5096 +16
==========================================
+ Hits 9656 9664 +8
- Misses 11294 11377 +83
Partials 1239 1239 |
if (type === FEDERATION_EVENT.FEDERATION_DELETE) { | ||
const {domain: deletedDomain} = data; | ||
|
||
await this.onFederationDelete(deletedDomain); | ||
} | ||
|
||
if (type === FEDERATION_EVENT.FEDERATION_CONNECTION_REMOVED) { | ||
const {domains: deletedDomains} = data; | ||
await this.onFederationConnectionRemove(deletedDomains); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's convert that into a switch in case we will need to handle more events of this type in the future.
Also we could early return in case the type has been matched
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 76d1df0
case ClientEvent.CONVERSATION.FEDERATION_STOP: { | ||
messageEntity = this._mapEventFederationStop(event); | ||
break; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we need to handle the connectionRemove event (and display it) as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the event that we are creating on the client side for the system message, connection removed is handled here:
https://github.com/wireapp/wire-webapp/pull/15583/files#diff-8424911ba55dc95ddd7ee35e77e651a8894faa0c33cd485cbbf62f6537fe3d24R327-R329
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but there is no system message for connectionRemoved event?
case EVENT_TYPE.CALL: | ||
amplify.publish(WebAppEvents.CALL.EVENT_FROM_BACKEND, event, source); | ||
break; | ||
case EVENT_TYPE.FEDERATION: | ||
amplify.publish(WebAppEvents.FEDERATION.EVENT_FROM_BACKEND, event, source); | ||
break; | ||
case EVENT_TYPE.CONVERSATION: | ||
amplify.publish(WebAppEvents.CONVERSATION.EVENT_FROM_BACKEND, event, source); | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note for the future, I'd like the EventRepo to not really filter the type of events.
It should just send all the events in a single event and all the repos subscribing to it will make the work of filtering depending on the event type. :)
const allConversations = this.conversationState.conversations(); | ||
|
||
allConversations | ||
.filter(conversation => conversation.domain === domainOne) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two blocks are almost identical except domain type. We can create a function and call it twice with each domain.
const handleFederationUsers = async (domainToFilter: string, userDomainToDelete: string) => {
allConversations
.filter(conversation => conversation.domain === domainToFilter)
.forEach(async conversation => {
const usersToDelete = conversation.allUserEntities().filter(user => user.domain === userDomainToDelete);
if (usersToDelete.length > 0) {
await this.removeDeletedFederationUsers(conversation, usersToDelete);
await this.insertFederationStopSystemMessage(conversation, [domainOne, domainTwo]);
}
});
};
await handleFederationUsers(domainOne, domainTwo);
await handleFederationUsers(domainTwo, domainOne);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's is a good suggestion, indeed. But without unit tests to back it, it's also risky.
I'd recommend writing tests first (I can help with that), make sure that we are compliant with the specs and then refactoring to a cleaner/more performant code.
This pull request implements a set of client-side actions to handle events related to federated communication termination. The specification outlines the steps for two types of events:
federation.delete
andfederation.connectionRemoved
. The main focus is on cleaning up local state after receiving these events and inserting a system message to explain what happened to the user.For the
federation.delete
event: (Backend A has stopped federating with us)For the
federation.connectionRemoved
event: (Backend A & B stopped federating, user is on C)