mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-03 20:48:07 +00:00 
			
		
		
		
	* Adds typing indicator for widget * typing indicator for agents in dashboard Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
		
			
				
	
	
		
			29 lines
		
	
	
		
			635 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			635 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
/* eslint no-console: 0 */
 | 
						|
/* eslint no-param-reassign: 0 */
 | 
						|
export default () => {
 | 
						|
  if (!Array.prototype.last) {
 | 
						|
    Object.assign(Array.prototype, {
 | 
						|
      last() {
 | 
						|
        return this[this.length - 1];
 | 
						|
      },
 | 
						|
    });
 | 
						|
  }
 | 
						|
};
 | 
						|
 | 
						|
export const getTypingUsersText = (users = []) => {
 | 
						|
  const count = users.length;
 | 
						|
  if (count === 1) {
 | 
						|
    const [user] = users;
 | 
						|
    return `${user.name} is typing`;
 | 
						|
  }
 | 
						|
 | 
						|
  if (count === 2) {
 | 
						|
    const [first, second] = users;
 | 
						|
    return `${first.name} and ${second.name} are typing`;
 | 
						|
  }
 | 
						|
 | 
						|
  const [user] = users;
 | 
						|
  const rest = users.length - 1;
 | 
						|
  return `${user.name} and ${rest} others are typing`;
 | 
						|
};
 |