Class: Slk::Services::ActivityEnricher
- Inherits:
-
Object
- Object
- Slk::Services::ActivityEnricher
- Defined in:
- lib/slk/services/activity_enricher.rb
Overview
Enriches activity feed items with resolved user/channel names
Instance Method Summary collapse
- #dispatch_enrich(type, item, workspace) ⇒ Object
-
#enrich_all(items, workspace) ⇒ Object
Enrich a list of activity items.
-
#enrich_item(item, workspace) ⇒ Object
Enrich a single activity item based on its type.
-
#initialize(cache_store:, conversations_api:, on_debug: nil) ⇒ ActivityEnricher
constructor
A new instance of ActivityEnricher.
-
#resolve_channel(workspace, channel_id, with_hash: true) ⇒ Object
Resolve channel ID to name (with API fallback).
-
#resolve_user(workspace, user_id) ⇒ Object
Resolve user ID to name (cache-only).
Constructor Details
#initialize(cache_store:, conversations_api:, on_debug: nil) ⇒ ActivityEnricher
Returns a new instance of ActivityEnricher.
7 8 9 10 11 |
# File 'lib/slk/services/activity_enricher.rb', line 7 def initialize(cache_store:, conversations_api:, on_debug: nil) @cache = cache_store @conversations_api = conversations_api @on_debug = on_debug end |
Instance Method Details
#dispatch_enrich(type, item, workspace) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/slk/services/activity_enricher.rb', line 28 def dispatch_enrich(type, item, workspace) case type when 'message_reaction' then enrich_reaction(item, workspace) when 'at_user', 'at_user_group', 'at_channel', 'at_everyone' then enrich_mention(item, workspace) when 'thread_v2' then enrich_thread(item, workspace) when 'bot_dm_bundle' then enrich_bot_dm(item, workspace) else @on_debug&.call("Unknown activity type: #{type.inspect}") if type end end |
#enrich_all(items, workspace) ⇒ Object
Enrich a list of activity items
14 15 16 17 18 19 20 |
# File 'lib/slk/services/activity_enricher.rb', line 14 def enrich_all(items, workspace) items.map do |item| enriched = item.dup enrich_item(enriched, workspace) enriched end end |
#enrich_item(item, workspace) ⇒ Object
Enrich a single activity item based on its type
23 24 25 26 |
# File 'lib/slk/services/activity_enricher.rb', line 23 def enrich_item(item, workspace) type = item.dig('item', 'type') dispatch_enrich(type, item, workspace) end |
#resolve_channel(workspace, channel_id, with_hash: true) ⇒ Object
Resolve channel ID to name (with API fallback)
44 45 46 47 48 49 50 51 52 |
# File 'lib/slk/services/activity_enricher.rb', line 44 def resolve_channel(workspace, channel_id, with_hash: true) return 'DM' if channel_id.start_with?('D') return 'Group DM' if channel_id.start_with?('G') name = fetch_channel_name(workspace, channel_id) return channel_id unless name with_hash ? "##{name}" : name end |
#resolve_user(workspace, user_id) ⇒ Object
Resolve user ID to name (cache-only)
39 40 41 |
# File 'lib/slk/services/activity_enricher.rb', line 39 def resolve_user(workspace, user_id) @cache.get_user(workspace.name, user_id) || user_id end |