streamline the convertNameAndTopic function
This commit is contained in:
		
							parent
							
								
									bd32fe6c6d
								
							
						
					
					
						commit
						9569fda168
					
				
					 1 changed files with 10 additions and 18 deletions
				
			
		| 
						 | 
					@ -37,25 +37,17 @@ function applyKStateDiffToRoom(roomID, kstate) {
 | 
				
			||||||
 * @param {string?} customName
 | 
					 * @param {string?} customName
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function convertNameAndTopic(channel, guild, customName) {
 | 
					function convertNameAndTopic(channel, guild, customName) {
 | 
				
			||||||
	// TODO: Improve nasty nested ifs
 | 
						const convertedName = customName || channel.name;
 | 
				
			||||||
	let convertedName, convertedTopic
 | 
						const maybeTopicWithPipe = channel.topic ? ` | ${channel.topic}` : '';
 | 
				
			||||||
	if (customName) {
 | 
						const maybeTopicWithNewlines = channel.topic ? `${channel.topic}\n\n` : '';
 | 
				
			||||||
		convertedName = customName
 | 
						const channelIDPart = `Channel ID: ${channel.id}`;
 | 
				
			||||||
		if (channel.topic) {
 | 
						const guildIDPart = `Guild ID: ${guild.id}`;
 | 
				
			||||||
			convertedTopic = `#${channel.name} | ${channel.topic}\n\nChannel ID: ${channel.id}\nGuild ID: ${guild.id}`
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			convertedTopic = `#${channel.name}\n\nChannel ID: ${channel.id}\nGuild ID: ${guild.id}`
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		convertedName = channel.name
 | 
					 | 
				
			||||||
		if (channel.topic) {
 | 
					 | 
				
			||||||
			convertedTopic = `${channel.topic}\n\nChannel ID: ${channel.id}\nGuild ID: ${guild.id}`
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			convertedTopic = `Channel ID: ${channel.id}\nGuild ID: ${guild.id}`
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return [convertedName, convertedTopic]
 | 
						const convertedTopic = customName
 | 
				
			||||||
 | 
							 ? `#${channel.name}${maybeTopicWithPipe}\n\n${channelIDPart}\n${guildIDPart}`
 | 
				
			||||||
 | 
							 : `${maybeTopicWithNewlines}${channelIDPart}\n${guildIDPart}`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return [convertedName, convertedTopic];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue