Module: TurboChat::ParticipantIdentity

Defined in:
lib/turbo_chat/participant_identity.rb

Class Method Summary collapse

Class Method Details

.display_name(participant, unknown: "Unknown") ⇒ Object



5
6
7
8
9
# File 'lib/turbo_chat/participant_identity.rb', line 5

def display_name(participant, unknown: "Unknown")
  return unknown if participant.nil?

  username(participant) || name(participant) || email(participant) || participant.to_s
end

.email(participant) ⇒ Object



11
12
13
14
15
16
# File 'lib/turbo_chat/participant_identity.rb', line 11

def email(participant)
  return nil if participant.nil?
  return nil unless participant.respond_to?(:email)

  participant.email.to_s.presence
end

.mention_base_identifier(participant) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/turbo_chat/participant_identity.rb', line 18

def mention_base_identifier(participant)
  return username(participant) if username(participant).present?

  email_value = email(participant)
  return email_value.to_s.split("@").first if email_value.present?
  return name(participant) if name(participant).present?

  participant.to_s
end

.name(participant) ⇒ Object



35
36
37
38
39
40
# File 'lib/turbo_chat/participant_identity.rb', line 35

def name(participant)
  return nil if participant.nil?
  return nil unless participant.respond_to?(:name)

  participant.name.to_s.presence
end

.username(participant) ⇒ Object



28
29
30
31
32
33
# File 'lib/turbo_chat/participant_identity.rb', line 28

def username(participant)
  return nil if participant.nil?
  return nil unless participant.respond_to?(:username)

  participant.username.to_s.presence
end