package chat.vojo.app;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

/**
 * Fires when the user swipes a per-room MessagingStyle notification away.
 *
 * Without this hook, RoomMessageCache would still hold the prior messages
 * for that room — and the next push would append onto that history and
 * re-surface the messages the user just dismissed. With it, swipe clears
 * the cache so the next push starts a fresh conversation for the room.
 *
 * NOTE: this only fires for user-driven dismissals — programmatic
 * nm.cancel calls (mark-as-read, receipt-driven dismiss, channel migration)
 * already call RoomMessageCache.clear themselves and do NOT fire the
 * delete intent. There's no double-clear risk.
 */
public class NotificationDismissReceiver extends BroadcastReceiver {

    public static final String ACTION_NOTIFICATION_DISMISSED =
        "chat.vojo.app.NOTIFICATION_DISMISSED";
    public static final String EXTRA_ROOM_ID = "room_id";

    private static final String TAG = "DismissRcvr";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent == null) return;
        String roomId = intent.getStringExtra(EXTRA_ROOM_ID);
        if (roomId == null || roomId.isEmpty()) return;
        if (BuildConfig.DEBUG) Log.d(TAG, "swipe clear cache room=" + roomId);
        RoomMessageCache.clear(roomId);
    }
}
