RocketChat/Rocket.Chat

View on GitHub
apps/meteor/app/api/server/v1/chat.ts

Summary

Maintainability
F
6 days
Test Coverage

File chat.ts has 718 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Message } from '@rocket.chat/core-services';
import type { IMessage } from '@rocket.chat/core-typings';
import { Messages, Users, Rooms, Subscriptions } from '@rocket.chat/models';
import { isChatReportMessageProps, isChatGetURLPreviewProps } from '@rocket.chat/rest-typings';
import { escapeRegExp } from '@rocket.chat/string-helpers';
Severity: Major
Found in apps/meteor/app/api/server/v1/chat.ts - About 1 day to fix

    Function get has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            async get() {
                const { rid } = this.queryParams;
                const { query, fields, sort } = await this.parseJsonQuery();
                const { updatedSince } = this.queryParams;
                let updatedSinceDate;
    Severity: Minor
    Found in apps/meteor/app/api/server/v1/chat.ts - About 1 hr to fix

      Function get has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              async get() {
                  const { rid, type, text } = this.queryParams;
                  check(rid, String);
                  check(type, Match.Maybe(String));
                  check(text, Match.Maybe(String));
      Severity: Minor
      Found in apps/meteor/app/api/server/v1/chat.ts - About 1 hr to fix

        Function get has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                async get() {
                    const { tmid } = this.queryParams;
                    const { query, fields, sort } = await this.parseJsonQuery();
                    const { offset, count } = await getPaginationItems(this.queryParams);
        
        
        Severity: Minor
        Found in apps/meteor/app/api/server/v1/chat.ts - About 1 hr to fix

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

                  async post() {
                      check(
                          this.bodyParams,
                          Match.ObjectIncluding({
                              msgId: String,
          Severity: Minor
          Found in apps/meteor/app/api/server/v1/chat.ts - About 1 hr to fix

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

                    async get() {
                        const { tmid } = this.queryParams;
                        const { query, fields, sort } = await this.parseJsonQuery();
                        const { updatedSince } = this.queryParams;
                        let updatedSinceDate;
            Severity: Minor
            Found in apps/meteor/app/api/server/v1/chat.ts - About 1 hr to fix

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

                      async post() {
                          check(
                              this.bodyParams,
                              Match.ObjectIncluding({
                                  roomId: String,
              Severity: Minor
              Found in apps/meteor/app/api/server/v1/chat.ts - About 1 hr to fix

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

                        async get() {
                            const { roomId, since } = this.queryParams;
                            const { offset, count } = await getPaginationItems(this.queryParams);
                
                            if (!roomId) {
                Severity: Minor
                Found in apps/meteor/app/api/server/v1/chat.ts - About 1 hr to fix

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

                          async get() {
                              const { tmid } = this.queryParams;
                              const { query, fields, sort } = await this.parseJsonQuery();
                              const { updatedSince } = this.queryParams;
                              let updatedSinceDate;
                  Severity: Minor
                  Found in apps/meteor/app/api/server/v1/chat.ts - 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

                  Avoid too many return statements within this function.
                  Open

                              return API.v1.success({
                                  _id: msg._id,
                                  ts: Date.now().toString(),
                                  message: msg,
                              });
                  Severity: Major
                  Found in apps/meteor/app/api/server/v1/chat.ts - About 30 mins to fix

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

                            async post() {
                                check(
                                    this.bodyParams,
                                    Match.ObjectIncluding({
                                        msgId: String,
                    Severity: Minor
                    Found in apps/meteor/app/api/server/v1/chat.ts - About 25 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

                    Function get has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                            async get() {
                                const { rid } = this.queryParams;
                                const { query, fields, sort } = await this.parseJsonQuery();
                                const { updatedSince } = this.queryParams;
                                let updatedSinceDate;
                    Severity: Minor
                    Found in apps/meteor/app/api/server/v1/chat.ts - About 25 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

                    API.v1.addRoute(
                        'chat.unStarMessage',
                        { authRequired: true },
                        {
                            async post() {
                    Severity: Major
                    Found in apps/meteor/app/api/server/v1/chat.ts and 1 other location - About 6 hrs to fix
                    apps/meteor/app/api/server/v1/chat.ts on lines 235..259

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

                    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

                    API.v1.addRoute(
                        'chat.starMessage',
                        { authRequired: true },
                        {
                            async post() {
                    Severity: Major
                    Found in apps/meteor/app/api/server/v1/chat.ts and 1 other location - About 6 hrs to fix
                    apps/meteor/app/api/server/v1/chat.ts on lines 283..307

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

                    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

                    API.v1.addRoute(
                        'chat.followMessage',
                        { authRequired: true },
                        {
                            async post() {
                    Severity: Major
                    Found in apps/meteor/app/api/server/v1/chat.ts and 1 other location - About 3 hrs to fix
                    apps/meteor/app/api/server/v1/chat.ts on lines 712..728

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

                    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

                    API.v1.addRoute(
                        'chat.unfollowMessage',
                        { authRequired: true },
                        {
                            async post() {
                    Severity: Major
                    Found in apps/meteor/app/api/server/v1/chat.ts and 1 other location - About 3 hrs to fix
                    apps/meteor/app/api/server/v1/chat.ts on lines 694..710

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

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

                                const { cursor, totalCount } = await Messages.findPaginated(threadQuery, {
                                    sort: sort || { tlm: -1 },
                                    skip: offset,
                                    limit: count,
                                    projection: fields,
                    Severity: Major
                    Found in apps/meteor/app/api/server/v1/chat.ts and 3 other locations - About 1 hr to fix
                    apps/meteor/app/api/server/v1/channels.ts on lines 299..304
                    apps/meteor/app/api/server/v1/channels.ts on lines 1437..1442
                    apps/meteor/app/api/server/v1/groups.ts on lines 764..769

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

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

                                return API.v1.success({
                                    messages: await normalizeMessagesForUser(messages, this.userId),
                                    count: messages.length,
                                    offset,
                                    total,
                    Severity: Major
                    Found in apps/meteor/app/api/server/v1/chat.ts and 4 other locations - About 50 mins to fix
                    apps/meteor/app/api/server/v1/channels.ts on lines 308..313
                    apps/meteor/app/api/server/v1/chat.ts on lines 545..550
                    apps/meteor/app/api/server/v1/groups.ts on lines 773..778
                    apps/meteor/app/api/server/v1/im.ts on lines 386..391

                    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

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

                                return API.v1.success({
                                    threads: await normalizeMessagesForUser(threads, this.userId),
                                    count: threads.length,
                                    offset,
                                    total,
                    Severity: Major
                    Found in apps/meteor/app/api/server/v1/chat.ts and 4 other locations - About 50 mins to fix
                    apps/meteor/app/api/server/v1/channels.ts on lines 308..313
                    apps/meteor/app/api/server/v1/chat.ts on lines 495..500
                    apps/meteor/app/api/server/v1/groups.ts on lines 773..778
                    apps/meteor/app/api/server/v1/im.ts on lines 386..391

                    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

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

                                const messages = await findMentionedMessages({
                                    uid: this.userId,
                                    roomId,
                                    pagination: {
                                        offset,
                    Severity: Minor
                    Found in apps/meteor/app/api/server/v1/chat.ts and 1 other location - About 40 mins to fix
                    apps/meteor/app/api/server/v1/chat.ts on lines 768..776

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

                    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 messages = await findStarredMessages({
                                    uid: this.userId,
                                    roomId,
                                    pagination: {
                                        offset,
                    Severity: Minor
                    Found in apps/meteor/app/api/server/v1/chat.ts and 1 other location - About 40 mins to fix
                    apps/meteor/app/api/server/v1/chat.ts on lines 741..749

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

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

                                if (isNaN(Date.parse(updatedSince))) {
                                    throw new Meteor.Error('error-updatedSince-param-invalid', 'The "updatedSince" query parameter must be a valid date.');
                                } else {
                                    updatedSinceDate = new Date(updatedSince);
                                }
                    Severity: Minor
                    Found in apps/meteor/app/api/server/v1/chat.ts and 2 other locations - About 35 mins to fix
                    apps/meteor/app/api/server/v1/chat.ts on lines 573..577
                    apps/meteor/app/api/server/v1/rooms.ts on lines 126..130

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

                                if (isNaN(Date.parse(updatedSince))) {
                                    throw new Meteor.Error('error-updatedSince-param-invalid', 'The "updatedSince" query parameter must be a valid date.');
                                } else {
                                    updatedSinceDate = new Date(updatedSince);
                                }
                    Severity: Minor
                    Found in apps/meteor/app/api/server/v1/chat.ts and 2 other locations - About 35 mins to fix
                    apps/meteor/app/api/server/v1/chat.ts on lines 669..673
                    apps/meteor/app/api/server/v1/rooms.ts on lines 126..130

                    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