Module: Models::EmployeePhonePresence

Extended by:
ActiveSupport::Concern
Included in:
Employee
Defined in:
app/concerns/models/employee_phone_presence.rb

Overview

PBX presence, extension status, and work-from-home checks for Employee.
Reads go through the employee's EmployeePhoneStatus; #set_presence
updates it and syncs the switchboard (broadcast in development,
SyncPhoneStatusWorker otherwise).

Instance Method Summary collapse

Instance Method Details

#auto_away_afterString?

Auto-away time of day, formatted like "05:30 pm".

Returns:

  • (String, nil)


98
99
100
# File 'app/concerns/models/employee_phone_presence.rb', line 98

def auto_away_after
  employee_phone_status.try(:auto_away_after).try(:strftime, '%I:%M %P')
end

#pbx_didString?

The employee's direct-inward-dial number (contact point detail).

Returns:

  • (String, nil)


26
27
28
# File 'app/concerns/models/employee_phone_presence.rb', line 26

def pbx_did
  pbx_did_contact_point&.detail
end

#pbx_did_contact_pointContactPoint?

The DID contact point backing the employee's PBX line.

Returns:



19
20
21
# File 'app/concerns/models/employee_phone_presence.rb', line 19

def pbx_did_contact_point
  employee_phone_status&.contact_point
end

#pbx_extensionString?

The employee's PBX extension.

Returns:

  • (String, nil)


33
34
35
# File 'app/concerns/models/employee_phone_presence.rb', line 33

def pbx_extension
  employee_phone_status&.extension
end

#presenceSymbol

The employee's current primary presence as a Symbol, :unknown when none
is set.

Returns:

  • (Symbol)


77
78
79
# File 'app/concerns/models/employee_phone_presence.rb', line 77

def presence
  employee_phone_status.try(:presence).try(:to_sym) || :unknown
end

#presence_timestampInteger?

Unix timestamp of when the current presence was set.

Returns:

  • (Integer, nil)


91
92
93
# File 'app/concerns/models/employee_phone_presence.rb', line 91

def presence_timestamp
  employee_phone_status.try(:date_set).try(:to_i)
end

#set_presence(new_presence, sub_presence = nil) ⇒ String, ...

Updates the employee's PBX presence and synchronizes it with the phone system.

Parameters:

  • new_presence (String, Symbol)

    primary presence to assign

  • sub_presence (String, Symbol, nil) (defaults to: nil)

    optional secondary presence to assign

Returns:

  • (String, Boolean, nil)

    result of the development broadcast or worker enqueue



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/concerns/models/employee_phone_presence.rb', line 57

def set_presence(new_presence, sub_presence = nil)
  eps = employee_phone_status || build_employee_phone_status
  eps.presence = new_presence
  eps.sub_presence = sub_presence
  if eps.presence_changed? || eps.sub_presence_changed?
    eps.date_set = Time.current
    eps.last_alert = nil
    eps.save
  end
  if Rails.env.development?
    eps.broadcast_agent_status
  else
    SyncPhoneStatusWorker.perform_async(id)
  end
end

#sub_presenceSymbol?

The employee's current secondary presence.

Returns:

  • (Symbol, nil)


84
85
86
# File 'app/concerns/models/employee_phone_presence.rb', line 84

def sub_presence
  employee_phone_status.try(:sub_presence).try(:to_sym)
end

#working_from_home?Boolean? Also known as: is_working_from_home?

Whether the employee is currently flagged as working from home.

Returns:

  • (Boolean, nil)


40
41
42
# File 'app/concerns/models/employee_phone_presence.rb', line 40

def working_from_home?
  employee_phone_status.try(:working_from_home)
end

#working_from_home_numberString?

Phone number to reach the employee while working from home.

Returns:

  • (String, nil)


48
49
50
# File 'app/concerns/models/employee_phone_presence.rb', line 48

def working_from_home_number
  employee_phone_status.try(:working_from_home_number)
end