RocketChat/Rocket.Chat

View on GitHub
ee/packages/omnichannel-services/src/OmnichannelTranscript.ts

Summary

Maintainability
F
3 days
Test Coverage

Function getMessagesData has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

    private async getMessagesData(messages: IMessage[]): Promise<MessageData[]> {
        const messagesData: MessageData[] = [];
        for await (const message of messages) {
            if (!message.attachments?.length) {
                // If there's no attachment and no message, what was sent? lol
Severity: Minor
Found in ee/packages/omnichannel-services/src/OmnichannelTranscript.ts - About 4 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

File OmnichannelTranscript.ts has 331 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import type { Readable } from 'stream';

import {
    ServiceClass,
    Upload as uploadService,
Severity: Minor
Found in ee/packages/omnichannel-services/src/OmnichannelTranscript.ts - About 3 hrs to fix

    Function getMessagesData has 71 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private async getMessagesData(messages: IMessage[]): Promise<MessageData[]> {
            const messagesData: MessageData[] = [];
            for await (const message of messages) {
                if (!message.attachments?.length) {
                    // If there's no attachment and no message, what was sent? lol
    Severity: Major
    Found in ee/packages/omnichannel-services/src/OmnichannelTranscript.ts - About 2 hrs to fix

      Function workOnPdf has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          async workOnPdf({ details }: { details: WorkDetailsWithSource }): Promise<void> {
              this.log.info(`Processing transcript for room ${details.rid} by user ${details.userId} - Received from queue`);
              if (this.maxNumberOfConcurrentJobs <= this.currentJobNumber) {
                  this.log.error(`Processing transcript for room ${details.rid} by user ${details.userId} - Too many concurrent jobs, queuing again`);
                  throw new Error('retry');
      Severity: Minor
      Found in ee/packages/omnichannel-services/src/OmnichannelTranscript.ts - About 1 hr to fix

        Function pdfComplete has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private async pdfComplete({ details, file }: { details: WorkDetailsWithSource; file: IUpload }): Promise<void> {
                this.log.info(`Transcript for room ${details.rid} by user ${details.userId} - Complete`);
                const user = await Users.findOneById(details.userId);
                if (!user) {
                    return;
        Severity: Minor
        Found in ee/packages/omnichannel-services/src/OmnichannelTranscript.ts - About 1 hr to fix

          Function requestTranscript has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async requestTranscript({ details }: { details: WorkDetails }): Promise<void> {
                  this.log.info(`Requesting transcript for room ${details.rid} by user ${details.userId}`);
                  const room = await LivechatRooms.findOneById<Pick<IOmnichannelRoom, '_id' | 'open' | 'v' | 'pdfTranscriptRequested'>>(details.rid, {
                      projection: { _id: 1, open: 1, v: 1, pdfTranscriptRequested: 1 },
                  });
          Severity: Minor
          Found in ee/packages/omnichannel-services/src/OmnichannelTranscript.ts - About 1 hr to fix

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

                private getQuotesFromMessage(message: IMessage): Quote[] {
                    const quotes: Quote[] = [];
            
                    if (!message.attachments) {
                        return quotes;
            Severity: Minor
            Found in ee/packages/omnichannel-services/src/OmnichannelTranscript.ts - 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

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

                            if (!this.worker.isMimeTypeValid(attachment.image_type)) {
                                this.log.error(`Invalid mime type ${attachment.image_type} for file ${attachment.title} in room ${message.rid}!`);
                                // ignore invalid mime types
                                files.push({ name: attachment.title, buffer: null });
                                continue;
            ee/packages/omnichannel-services/src/OmnichannelTranscript.ts on lines 192..197

            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 79.

            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 (!isFileImageAttachment(attachment)) {
                                this.log.error(`Invalid attachment type ${attachment.type} for file ${attachment.title} in room ${message.rid}!`);
                                // ignore other types of attachments
                                files.push({ name: attachment.title, buffer: null });
                                continue;
            ee/packages/omnichannel-services/src/OmnichannelTranscript.ts on lines 199..204

            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 79.

            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 3 locations. Consider refactoring.
            Open

                            if (!uploadedFile) {
                                this.log.error(`Uploaded file ${file._id} not found in room ${message.rid}!`);
                                // ignore attachments without file
                                files.push({ name: file.name, buffer: null });
                                continue;
            ee/packages/omnichannel-services/src/OmnichannelTranscript.ts on lines 211..216
            ee/packages/omnichannel-services/src/OmnichannelTranscript.ts on lines 220..225

            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 76.

            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 3 locations. Consider refactoring.
            Open

                                if (!fileId) {
                                    this.log.error(`File ${attachment.title} not found in room ${message.rid}!`);
                                    // ignore attachments without file
                                    files.push({ name: attachment.title, buffer: null });
                                    continue;
            ee/packages/omnichannel-services/src/OmnichannelTranscript.ts on lines 220..225
            ee/packages/omnichannel-services/src/OmnichannelTranscript.ts on lines 228..233

            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 76.

            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 3 locations. Consider refactoring.
            Open

                            if (!file) {
                                this.log.warn(`File ${attachment.title} not found in room ${message.rid}!`);
                                // ignore attachments without file
                                files.push({ name: attachment.title, buffer: null });
                                continue;
            ee/packages/omnichannel-services/src/OmnichannelTranscript.ts on lines 211..216
            ee/packages/omnichannel-services/src/OmnichannelTranscript.ts on lines 228..233

            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 76.

            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

                        const visitor =
                            room.v &&
                            (await LivechatVisitors.findOneEnabledById(room.v._id, { projection: { _id: 1, name: 1, username: 1, visitorEmails: 1 } }));
            ee/packages/omnichannel-services/src/OmnichannelTranscript.ts on lines 287..288

            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 61.

            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

                        const agent =
                            room.servedBy && (await Users.findOneAgentById(room.servedBy._id, { projection: { _id: 1, name: 1, username: 1, utcOffset: 1 } }));
            ee/packages/omnichannel-services/src/OmnichannelTranscript.ts on lines 284..286

            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 61.

            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

                        projection: { _id: 1, msg: 1, u: 1, t: 1, ts: 1, attachments: 1, files: 1, md: 1 },
            Severity: Minor
            Found in ee/packages/omnichannel-services/src/OmnichannelTranscript.ts and 1 other location - About 35 mins to fix
            apps/meteor/app/api/server/v1/moderation.ts on lines 179..188

            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