Module: Teems::Services::SyncChatDir

Included in:
SyncStore
Defined in:
lib/teems/services/sync_store.rb

Overview

Chat directory resolution for SyncStore

Instance Method Summary collapse

Instance Method Details

#chat_dir(chat_id, state: nil) ⇒ Object



89
90
91
92
93
# File 'lib/teems/services/sync_store.rb', line 89

def chat_dir(chat_id, state: nil)
  chat_entry = state&.dig('chats', chat_id)
  dir_name = chat_entry&.dig('dir_name') || sanitize_id(chat_id)
  File.join(sync_dir, SyncStore::CHATS_DIR, type_dir(chat_entry&.dig('chat_type')), dir_name)
end

#read_messages_json(chat_id, state: nil) ⇒ Object



95
96
97
# File 'lib/teems/services/sync_store.rb', line 95

def read_messages_json(chat_id, state: nil)
  load_json_or_default(File.join(chat_dir(chat_id, state: state), 'messages.json'), [])
end