
Chat Module (Telegram-style) - Full Package
==========================================

Contents
--------
- install.php                 -> Web installer (creates tables + config.php)
- config.php                  -> Placeholder; real config generated by installer
- sql/create_chat_tables.sql  -> SQL used by installer (you can run manually if you want)
- api/chat/*.php              -> JSON APIs for chat
- public/chat_list_demo.php   -> Demo UI page
- assets/css/chat.css         -> UI styles
- assets/js/chat.js           -> Front-end logic

Quick Install (cPanel / FileZilla)
----------------------------------
1. Upload the entire `chat_module` folder into your web root, e.g.:

   /home/USER/public_html/chat_module

2. In your browser, open:

   https://YOUR-DOMAIN/chat_module/install.php

3. Enter your MySQL details:

   - DB Host  (usually `localhost`)
   - DB Name  (from cPanel -> MySQL Databases)
   - DB User
   - DB Password

   Use the same database where your users table lives.

4. Click "Install".

   - This will:
     - Create `conversations`, `messages`, `user_presence` tables if they do not exist.
     - Generate `config.php` with your DB settings and `chat_db()` function.

5. After success:

   - For security, you may delete `install.php`.
   - Log in to your site so that `$_SESSION['user_id']` is set for a test user.
   - Open:

     https://YOUR-DOMAIN/chat_module/public/chat_list_demo.php

   - If there are conversations in DB, you will see them with Telegram-style UI.
     Otherwise you can manually insert some test data or integrate `get_or_create_conversation.php`
     with your existing "start chat" logic.

Integration
-----------
- All APIs expect a logged-in user and use `$_SESSION['user_id']`.
- `chat_list.php` assumes you have a `users` table with at least:
    id (INT PK),
    name (VARCHAR),
    avatar (optional, VARCHAR URL or path).

  If your user table/columns are different, we can adjust `chat_list.php` to match.

Security
--------
- Do not expose install.php after installation (delete or rename it).
- Keep config.php outside of public repositories (it has DB credentials).
