RocketChat/Rocket.Chat

View on GitHub
apps/meteor/app/federation/server/endpoints/dispatch.js

Summary

Maintainability
F
5 days
Test Coverage

File dispatch.js has 352 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { api } from '@rocket.chat/core-services';
import { eventTypes } from '@rocket.chat/core-typings';
import { FederationServers, FederationRoomEvents, Rooms, Messages, Subscriptions, Users, ReadReceipts } from '@rocket.chat/models';
import EJSON from 'ejson';

Severity: Minor
Found in apps/meteor/app/federation/server/endpoints/dispatch.js - About 4 hrs to fix

    Function eventTypes.ROOM_MESSAGE has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        async [eventTypes.ROOM_MESSAGE](event) {
            const eventResult = await FederationRoomEvents.addEvent(event.context, event);
    
            // If the event was successfully added, handle the event locally
            if (eventResult.success) {
    Severity: Minor
    Found in apps/meteor/app/federation/server/endpoints/dispatch.js - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function eventTypes.ROOM_MESSAGE has 60 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        async [eventTypes.ROOM_MESSAGE](event) {
            const eventResult = await FederationRoomEvents.addEvent(event.context, event);
    
            // If the event was successfully added, handle the event locally
            if (eventResult.success) {
    Severity: Major
    Found in apps/meteor/app/federation/server/endpoints/dispatch.js - About 2 hrs to fix

      Function eventTypes.ROOM_ADD_USER has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          async [eventTypes.ROOM_ADD_USER](event) {
              const eventResult = await FederationRoomEvents.addEvent(event.context, event);
      
              // We only want to refresh the server list and update the room federation array if something changed
              let federationAltered = false;
      Severity: Minor
      Found in apps/meteor/app/federation/server/endpoints/dispatch.js - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function eventTypes.ROOM_ADD_USER has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          async [eventTypes.ROOM_ADD_USER](event) {
              const eventResult = await FederationRoomEvents.addEvent(event.context, event);
      
              // We only want to refresh the server list and update the room federation array if something changed
              let federationAltered = false;
      Severity: Minor
      Found in apps/meteor/app/federation/server/endpoints/dispatch.js - About 1 hr to fix

        Function post has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                async post() {
                    if (!isFederationEnabled()) {
                        return API.v1.failure('Federation not enabled');
                    }
        
        
        Severity: Minor
        Found in apps/meteor/app/federation/server/endpoints/dispatch.js - About 1 hr to fix

          Function eventTypes.ROOM_UNSET_MESSAGE_REACTION has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async [eventTypes.ROOM_UNSET_MESSAGE_REACTION](event) {
                  const eventResult = await FederationRoomEvents.addEvent(event.context, event);
          
                  // If the event was successfully added, handle the event locally
                  if (eventResult.success) {
          Severity: Minor
          Found in apps/meteor/app/federation/server/endpoints/dispatch.js - About 1 hr to fix

            Function eventTypes.ROOM_SET_MESSAGE_REACTION has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                async [eventTypes.ROOM_SET_MESSAGE_REACTION](event) {
                    const eventResult = await FederationRoomEvents.addEvent(event.context, event);
            
                    // If the event was successfully added, handle the event locally
                    if (eventResult.success) {
            Severity: Minor
            Found in apps/meteor/app/federation/server/endpoints/dispatch.js - About 1 hr to fix

              Function post has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                      async post() {
                          if (!isFederationEnabled()) {
                              return API.v1.failure('Federation not enabled');
                          }
              
              
              Severity: Minor
              Found in apps/meteor/app/federation/server/endpoints/dispatch.js - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function eventTypes.ROOM_UNSET_MESSAGE_REACTION has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  async [eventTypes.ROOM_UNSET_MESSAGE_REACTION](event) {
                      const eventResult = await FederationRoomEvents.addEvent(event.context, event);
              
                      // If the event was successfully added, handle the event locally
                      if (eventResult.success) {
              Severity: Minor
              Found in apps/meteor/app/federation/server/endpoints/dispatch.js - About 55 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Avoid deeply nested control flow statements.
              Open

                                      if (/^image\/.+/.test(denormalizedMessage.file.type)) {
                                          attachment.image_url = attachment.image_url.replace(oldUploadId, upload._id);
                                      } else if (/^audio\/.+/.test(denormalizedMessage.file.type)) {
                                          attachment.audio_url = attachment.audio_url.replace(oldUploadId, upload._id);
                                      } else if (/^video\/.+/.test(denormalizedMessage.file.type)) {
              Severity: Major
              Found in apps/meteor/app/federation/server/endpoints/dispatch.js - About 45 mins to fix

                Function eventTypes.GENESIS has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    async [eventTypes.GENESIS](event) {
                        switch (event.data.contextType) {
                            case contextDefinitions.ROOM.type:
                                const eventResult = await FederationRoomEvents.addEvent(event.context, event);
                
                
                Severity: Minor
                Found in apps/meteor/app/federation/server/endpoints/dispatch.js - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    async [eventTypes.ROOM_USER_LEFT](event) {
                        const eventResult = await FederationRoomEvents.addEvent(event.context, event);
                
                        // If the event was successfully added, handle the event locally
                        if (eventResult.success) {
                Severity: Major
                Found in apps/meteor/app/federation/server/endpoints/dispatch.js and 1 other location - About 6 hrs to fix
                apps/meteor/app/federation/server/endpoints/dispatch.js on lines 157..177

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 160.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    async [eventTypes.ROOM_REMOVE_USER](event) {
                        const eventResult = await FederationRoomEvents.addEvent(event.context, event);
                
                        // If the event was successfully added, handle the event locally
                        if (eventResult.success) {
                Severity: Major
                Found in apps/meteor/app/federation/server/endpoints/dispatch.js and 1 other location - About 6 hrs to fix
                apps/meteor/app/federation/server/endpoints/dispatch.js on lines 182..202

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 160.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    async [eventTypes.ROOM_MUTE_USER](event) {
                        const eventResult = await FederationRoomEvents.addEvent(event.context, event);
                
                        // If the event was successfully added, handle the event locally
                        if (eventResult.success) {
                Severity: Major
                Found in apps/meteor/app/federation/server/endpoints/dispatch.js and 1 other location - About 4 hrs to fix
                apps/meteor/app/federation/server/endpoints/dispatch.js on lines 486..503

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 122.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    async [eventTypes.ROOM_UNMUTE_USER](event) {
                        const eventResult = await FederationRoomEvents.addEvent(event.context, event);
                
                        // If the event was successfully added, handle the event locally
                        if (eventResult.success) {
                Severity: Major
                Found in apps/meteor/app/federation/server/endpoints/dispatch.js and 1 other location - About 4 hrs to fix
                apps/meteor/app/federation/server/endpoints/dispatch.js on lines 464..481

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 122.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                            if (persistedUser) {
                                // Update the federation, if its not already set (if it's set, this is likely an event being reprocessed)
                                if (!persistedUser.federation) {
                                    await Users.updateOne({ _id: persistedUser._id }, { $set: { federation: user.federation } });
                                    federationAltered = true;
                Severity: Major
                Found in apps/meteor/app/federation/server/endpoints/dispatch.js and 1 other location - About 1 hr to fix
                apps/meteor/app/federation/server/endpoints/dispatch.js on lines 124..137

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 66.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                                if (persistedSubscription) {
                                    // Update the federation, if its not already set (if it's set, this is likely an event being reprocessed
                                    if (!persistedSubscription.federation) {
                                        await Subscriptions.updateOne({ _id: persistedSubscription._id }, { $set: { federation: subscription.federation } });
                                        federationAltered = true;
                Severity: Major
                Found in apps/meteor/app/federation/server/endpoints/dispatch.js and 1 other location - About 1 hr to fix
                apps/meteor/app/federation/server/endpoints/dispatch.js on lines 105..118

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 66.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                                await Messages.updateOne({ _id: persistedMessage._id }, { $set: { msg: message.msg, federation: message.federation } });
                Severity: Minor
                Found in apps/meteor/app/federation/server/endpoints/dispatch.js and 1 other location - About 50 mins to fix
                apps/meteor/app/federation/server/normalizers/user.js on lines 66..66

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 51.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                            void broadcastMessageFromData({
                                id: persistedMessage._id,
                                data: {
                                    ...persistedMessage,
                                    reactions: {
                Severity: Minor
                Found in apps/meteor/app/federation/server/endpoints/dispatch.js and 1 other location - About 35 mins to fix
                apps/meteor/app/federation/server/endpoints/dispatch.js on lines 388..397

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 46.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                            void broadcastMessageFromData({
                                id: persistedMessage._id,
                                data: {
                                    ...persistedMessage,
                                    reactions: {
                Severity: Minor
                Found in apps/meteor/app/federation/server/endpoints/dispatch.js and 1 other location - About 35 mins to fix
                apps/meteor/app/federation/server/endpoints/dispatch.js on lines 446..455

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 46.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                There are no issues that match your filters.

                Category
                Status