File conversations.js
has 302 lines of code (exceeds 250 allowed). Consider refactoring. Open
//
// Copyright 2014 Ilkka Oksanen <iao@iki.fi>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Function findOrCreate1on1
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
exports.findOrCreate1on1 = async function findOrCreate1on1(user, peerUserGId, network) {
assert(user && peerUserGId && network);
let conversation = null;
const userMembers = await ConversationMember.find({ userGId: user.gIdString });
Function deleteConversationMember
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
async function deleteConversationMember(conversation, member, options) {
log.info(`User: ${member.get('userGId')} removed from conversation: ${conversation.id}`);
if (!options.silent && conversation.get('type') === 'group') {
await broadcastAddMessage(conversation, {
Function broadcast
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
async function broadcast(conversation, ntf, excludeSession, options = {}) {
const members = await ConversationMember.find({ conversationId: conversation.id });
for (const member of members) {
const userGId = UserGId.create(member.get('userGId'));
- Read upRead up
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 deleteConversationMember
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
async function deleteConversationMember(conversation, member, options) {
log.info(`User: ${member.get('userGId')} removed from conversation: ${conversation.id}`);
if (!options.silent && conversation.get('type') === 'group') {
await broadcastAddMessage(conversation, {
- Read upRead up
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 findOrCreate1on1
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
exports.findOrCreate1on1 = async function findOrCreate1on1(user, peerUserGId, network) {
assert(user && peerUserGId && network);
let conversation = null;
const userMembers = await ConversationMember.find({ userGId: user.gIdString });
- Read upRead up
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 setGroupMembers
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
exports.setGroupMembers = async function setGroupMembers(conversation, newMembersHash) {
const oldMembers = await ConversationMember.find({ conversationId: conversation.id });
for (const oldMember of oldMembers) {
if (!Object.keys(newMembersHash).some(newMember => newMember === oldMember.gIdString)) {
- Read upRead up
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"