Cowofi/cowofi

In-app Chat and notifications

Opened this issue · 5 comments

Description

According to the Database, we need an In-app chat, the dynamic is simply, only the users can start a chat with the coworkers owners.

  • Need to create a chats page
  • Add Chat button in spaces
    • Added the space owner information in space details
  • Added bell to show notifications into the main header (desktop version)
    • Added read properties read_for_from_user and read_for_to_user to the chat entity
    • Add functionality to the notifications
    • Add notifications of schedules
  • Mobile
  • #54

Any others features are welcome.

@chakrihacker I have a request for you 😃 When you have time, please add properties to chat entity to make chat read by users read_for_from_user and read_for_to_user

image

Added bell icon

I added a table notification, function, and trigger on Supabase

Table

-- public.notification definition

-- Drop table

-- DROP TABLE public.notification;

CREATE TABLE public.notification (
	id int8 NOT NULL GENERATED BY DEFAULT AS IDENTITY,
	created_at timestamptz NULL DEFAULT now(),
	"read" bool NOT NULL DEFAULT false,
	"type" text NOT NULL,
	meta json NULL DEFAULT '{}'::json,
	to_user uuid NULL,
	CONSTRAINT notification_pkey PRIMARY KEY (id),
	CONSTRAINT notification_to_user_fkey FOREIGN KEY (to_user) REFERENCES auth.users(id)
);

Function

image

begin
  insert into public.notification(type, to_user, meta)
  values(
    'message',
    new.to_user,
    format('{"chat_id":"%s", "from_user":"%s"}', new.chat_id, (select from_user from public.chats where id = new.chat_id))::jsonb
  );

  return new;
end;

Trigger

image

Created function and trigger to handle the notifications of the schedules

Function

image

begin
  insert into public.notification(type, to_user, meta)
  values(
    'schedule',
    (select space.userid 
from public.spaces space
inner join public.users on public.users.id = space.userid 
where space.id = new.space_id),
    format('{"space_id":"%s", "schedule_id":"%s"}', new.space_id, new.id)::jsonb
  );

  return new;
end;

Trigger

image

The schedule notification uses a combination of schedule_id query parameter and in-code highlight, when the user clicked any notification, is redirected to the profile and the app automatic scroll down to the schedule and add a background color

image