chatwoot/enterprise/app/models
Sojan Jose 1d2f3e86dd
feat(companies): track company last activity (#14435)
Tracks company recency from linked contact activity so the Companies
list and detail page can show/sort by real customer engagement instead
of generic record updates.

## Closes

None.

## Why

Company recency should reflect activity from people associated with the
company. This keeps the signal tied to persisted contact activity,
without treating passive online presence or widget heartbeat pings as
company activity.

## What Changed

- Adds a company helper to record `last_activity_at` from linked contact
activity.
- Rolls up `Contact#last_activity_at` changes to the associated company.
- Initializes company activity when an already-active contact is
associated with a company, including the business-email auto-association
path.
- Throttles company activity rollups to once every 5 minutes per company
to avoid unnecessary writes during active conversations.
- Treats company activity as monotonic: unlinking, moving, or deleting
contacts does not move a company's activity timestamp backwards.
- Leaves historical backfill, online presence tracking, widget visit
tracking, and richer activity attribution out of scope.

## How to Test

1. Open an account with Companies enabled and visit the Companies list.
2. Trigger activity for a contact that belongs to a company, for example
by receiving or sending a message in that contact's conversation.
3. Confirm the linked company shows a recent activity timestamp in the
Companies list/detail page after the contact activity updates.
4. Associate an already-active contact with a company and confirm the
company receives that contact's existing activity timestamp.
5. Confirm repeated contact activity within a short window does not
continuously rewrite the company timestamp.

---------

Co-authored-by: Sony Mathew <2040199+sony-mathew@users.noreply.github.com>
2026-05-18 15:01:05 +05:30
..
captain feat: UI changes for document auto sync [AI-153] (#14258) 2026-05-11 20:13:29 +05:30
concerns feat: captain custom tools v1 (#13890) 2026-04-02 12:40:11 +05:30
enterprise feat(companies): track company last activity (#14435) 2026-05-18 15:01:05 +05:30
account_saml_settings.rb feat: update users on SAML setup and destroy [CW-2958][CW-5612] (#12346) 2025-09-15 21:20:22 +05:30
agent_capacity_policy.rb feat: Add agent capacity controllers (#12200) 2025-08-26 19:12:58 -07:00
applied_sla.rb chore: Add dependant destroy_async for sla events (#12774) 2025-10-31 09:19:56 +05:30
article_embedding.rb feat: legacy features to ruby llm (#12994) 2025-12-11 14:17:28 +05:30
call.rb feat(voice): add WhatsApp inbound call webhook pipeline [3] (#14315) 2026-05-12 11:23:57 +05:30
captain_inbox.rb feat(ee): Add Captain features (#10665) 2025-01-14 16:15:47 -08:00
company.rb feat(companies): track company last activity (#14435) 2026-05-18 15:01:05 +05:30
copilot_message.rb feat: Update UI for Copilot (#11561) 2025-06-02 22:02:03 -05:00
copilot_thread.rb feat: Add support for more tool, standardize copilot chat service (#11560) 2025-05-23 01:07:07 -07:00
custom_role.rb feat: Add APIs to manage custom roles in Chatwoot (#9995) 2024-08-23 17:18:28 +05:30
inbox_capacity_limit.rb feat: allow zero conversation limit capacity policy (#13964) 2026-04-06 11:39:14 +05:30
sla_event.rb feat: Conversation API to return applied_sla and sla_events (#9174) 2024-04-01 23:30:07 +05:30
sla_policy.rb fix: Prevent SLA deletion timeouts by moving to async job (#12944) 2025-12-10 12:28:47 +05:30