Search by

NativePHP Mobile plugin for Firstlight Chat: offline cache, sync, outbox and screen concerns for the Chat controls, with badges and notification replies.

Package info

github.com/firstlightui/chat

Homepage

Type:nativephp-plugin

pkg:composer/firstlightui/chat

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0-beta1 2026-11-28 16:46 UTC

This package is auto-updated.

Last update: 2026-11-28 20:13:42 UTC


README

The device side of Firstlight Chat. It keeps an offline cache of your conversations, sends messages through an outbox that survives being offline, syncs with a firstlightui/chat-server backend, and publishes everything into Firstlight's <firstlight:chat> and <firstlight:chat-composer> controls. The wire format is firstlightui/chat-protocol.

MIT licensed. Push is your own provider: this plugin registers the device token your app already gets from NativePHP; the server hands messages to a notifier you implement.

Install

composer require "firstlightui/chat:^1.0@beta"
php artisan native:plugin:register firstlightui/chat

Set CHAT_SERVER_URL to your backend. For real-time messages, receipts and typing, also configure Vibe (vibe.connection, vibe.auth.endpoint) and list its plugin in your NativeServiceProvider. Without Vibe, open chat screens sync every 5 seconds and the list every 10, and nobody sees typing. Then, once the user signs in:

use FirstlightUI\Chat\Facades\Chat;
use Native\Mobile\Facades\SecureStorage;

Chat::authenticateUsing(fn () => SecureStorage::get('api_token'));
Chat::identifyUsing(fn () => SecureStorage::get('user_id'));

On sign-out, call Chat::forget() to clear the device cache.

A conversation screen

use FirstlightUI\Chat\Concerns\ShowsChat;
use FirstlightUI\NativeComponent;

class Conversation extends NativeComponent
{
    use ShowsChat;

    public function mount(string $conversation): void
    {
        $this->openChat($conversation);
    }

    public function render()
    {
        return view('native.conversation');
    }
}
<native:column class="w-full flex-1">
    <firstlight:chat
        class="w-full flex-1"
        :messages="$chatMessages"
        me="{{ $chatMe }}"
        :typing="$chatTyping"
        :has-older="$chatHasOlder"
        @read="chatRead"
        @retry="chatRetry"
        @loadOlder="chatLoadOlder"
        @openAttachment="chatOpenAttachment"
        label="Chat with {{ $chatTitle }}"
    />

    <native:bottom-bar>
        <firstlight:chat-composer
            native:model.debounce.300ms="chatDraft"
            :attachments="$chatPending"
            attach="photos,camera,files"
            placeholder="Message"
            @send="chatSend"
            @attach="chatAttach"
            @removeAttachment="chatRemoveAttachment"
            @typing="chatTyped"
            label="Message to {{ $chatTitle }}"
        />
    </native:bottom-bar>
</native:column>

ListsConversations does the same for the conversation list: listConversations() in mount(), then render $chatConversations (id, title, avatar, unread, preview, muted) with List Item, and $chatTotalUnread for a tab badge.

How it works

  • Screens read only the device cache. Sending writes to the cache at once (sending), and every network call runs in a background AsyncTask.
  • Sync fetches each conversation's messages after the last seq it has, reports delivery, and syncs the list from a cursor. It runs when a screen opens, when the app comes back to the foreground, on any chat.* broadcast, after a reconnect, and when the device comes back online. Triggers that arrive while a sync runs are folded into it.
  • Outbox. Unsent messages go out in order. Network failures leave them sending to retry later; refusals (409, 422, 403, …) mark them failed, and Try again re-queues them. The outbox counts in Firstlight's connectivity status line (firstlight-chat.connectivity).
  • Receipts come from the other members' read and delivered cursors; reading moves your cursor on the device immediately.
  • Long chats open at the newest page; older history loads as the reader scrolls, up to the control's 500 messages.
  • Typing is a whisper on the conversation channel, shown for 6 seconds.

Badges and clearing a conversation's notifications use core NativePHP's setBadge() and removeDelivered() where your NativePHP version has them. Reply from a notification on iOS is planned.

Testing

composer test

The tests run this plugin against chat-server's real routes in one app.