Skip to content

Commit d1b72c7

Browse files
authored
v1.4.0 (#19)
## [1.4.0] - 2024-11-21 #### [@rickypid](https://github.com/rickypid) ⚠️⚠️ **Need schema migration** ⚠️⚠️ ### Improvements * Now when we get the rooms the `rooms_l` view is used so that we can get all the information without having to do multiple queries ### Fixed * Fixed #20 Chat creator role is null instead of admin * Fixed online user status realtime subscription
1 parent 05cb266 commit d1b72c7

File tree

12 files changed

+223
-127
lines changed

12 files changed

+223
-127
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## [1.4.0] - 2024-11-21
2+
#### [@rickypid](https://github.com/rickypid)
3+
4+
⚠️⚠️ **Need schema migration** ⚠️⚠️
5+
6+
### Improvements
7+
8+
* Now when we get the rooms the `rooms_l` view is used so that we can get all the information without having to do multiple queries
9+
10+
### Fixed
11+
12+
* Fixed #20 Chat creator role is null instead of admin
13+
* Fixed online user status realtime subscription
14+
115
## [1.3.2] - 2024-11-13
216
#### [@rickypid](https://github.com/rickypid)
317

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,4 @@ Below are some activities to complete to have a more complete and optimized proj
279279
4. Chat room channels
280280
5. Sending audio messages
281281
6. Improve documentation
282-
7. Use rooms view for improvement user parsing performance
282+

doc/docs/guides/supabse-views.md

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,69 @@ title: Database Views
55

66
## Rooms view
77

8-
This is a view of `rooms` table, this view allows you to obtain the name of the sender of the message dynamically in direct rooms, based on the logged-in user the name of the correspondent is displayed.
8+
This is a view of `rooms` table, this view allows you to obtain the name of the sender of the message dynamically in direct rooms, based on the logged-in user the name of the correspondent is displayed, it is also included the list of uses member objects.
99

1010
```sql
11-
DROP VIEW IF EXISTS chats.rooms_l;
12-
create view chats.rooms_l
13-
WITH (security_invoker='on') as
14-
select
15-
r.id,
16-
r."imageUrl",
17-
r.metadata,
18-
case
19-
when r.type = 'direct' and auth.uid() is not null then
20-
(select coalesce(u."firstName", '') || ' ' || coalesce(u."lastName", '')
21-
from chats.users u
22-
where u.id = any(r."userIds") and u.id <> auth.uid()
23-
limit 1)
24-
else
25-
r.name
26-
end as name,
27-
r.type,
28-
r."userIds",
29-
r."lastMessages",
30-
r."userRoles",
31-
r."createdAt",
32-
r."updatedAt"
11+
create or replace view chats.rooms_l
12+
with (security_invoker='on') as
13+
select r.id,
14+
r."imageUrl",
15+
r.metadata,
16+
case
17+
when r.type = 'direct' and auth.uid() is not null then
18+
(select coalesce(u."firstName", '') || ' ' || coalesce(u."lastName", '')
19+
from chats.users u
20+
where u.id = any (r."userIds")
21+
and u.id <> auth.uid()
22+
limit 1)
23+
else
24+
r.name
25+
end as name,
26+
r.type,
27+
r."userIds",
28+
r."lastMessages",
29+
r."userRoles",
30+
r."createdAt",
31+
r."updatedAt",
32+
(select jsonb_agg(to_jsonb(u))
33+
from chats.users u
34+
where u.id = any (r."userIds")) as users
3335
from chats.rooms r;
3436
```
37+
38+
39+
## Messages view
40+
41+
This is a view of `messages` table, this view allows you to obtain the author user object and room object.
42+
43+
```sql
44+
create or replace view chats.messages_l
45+
with (security_invoker='on') as
46+
select m.id,
47+
m."createdAt",
48+
m.metadata,
49+
m.duration,
50+
m."mimeType",
51+
m.name,
52+
m."remoteId",
53+
m."repliedMessage",
54+
m."roomId",
55+
m."showStatus",
56+
m.size,
57+
m.status,
58+
m.type,
59+
m."updatedAt",
60+
m.uri,
61+
m."waveForm",
62+
m."isLoading",
63+
m.height,
64+
m.width,
65+
m."previewData",
66+
m."authorId",
67+
m.text,
68+
to_jsonb(u) as author,
69+
to_jsonb(r) as room
70+
from chats.messages m
71+
left join chats.users u on u.id = m."authorId"
72+
left join chats.rooms_l r on r.id = m."roomId";
73+
```

doc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flutter-supabase-chat-core",
3-
"version": "1.3.2",
3+
"version": "1.4.0",
44
"private": true,
55
"scripts": {
66
"docusaurus": "docusaurus",

example/lib/src/pages/auth.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:flutter_login/flutter_login.dart';
55
import 'package:flutter_supabase_chat_core/flutter_supabase_chat_core.dart';
66
import 'package:supabase_flutter/supabase_flutter.dart';
77

8-
import 'rooms.dart';
8+
import 'home.dart';
99

1010
class AuthScreen extends StatefulWidget {
1111
const AuthScreen({
@@ -83,7 +83,7 @@ class _AuthScreenState extends State<AuthScreen> {
8383
onSubmitAnimationCompleted: () {
8484
Navigator.of(context).pushReplacement(
8585
MaterialPageRoute(
86-
builder: (context) => const RoomsPage(),
86+
builder: (context) => const HomePage(),
8787
),
8888
);
8989
},

example/pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: example
22
description: A new Flutter project.
33
publish_to: 'none'
44

5-
version: 1.3.2
5+
version: 1.4.0
66

77
environment:
88
sdk: '>=3.4.0 <4.0.0'
@@ -11,7 +11,7 @@ dependencies:
1111
cupertino_icons: ^1.0.8
1212
dio: ^5.7.0
1313
faker: ^2.2.0
14-
file_picker: ^8.1.3
14+
file_picker: ^8.1.4
1515
file_saver: ^0.2.14
1616
flutter:
1717
sdk: flutter
@@ -20,13 +20,13 @@ dependencies:
2020
flutter_login: ^5.0.0
2121
flutter_supabase_chat_core:
2222
path: ../
23-
flutter_svg: ^2.0.10+1
23+
flutter_svg: ^2.0.14
2424
http: ^1.2.2
2525
image_picker: ^1.1.2
26-
infinite_scroll_pagination: ^4.0.0
26+
infinite_scroll_pagination: ^4.1.0
2727
open_filex: ^4.5.0
28-
path_provider: ^2.1.4
29-
supabase_flutter: ^2.8.0
28+
path_provider: ^2.1.5
29+
supabase_flutter: ^2.8.1
3030
timeago: ^3.7.0
3131

3232

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,59 @@
1+
DROP VIEW IF EXISTS chats.messages_l;
12
DROP VIEW IF EXISTS chats.rooms_l;
2-
create view chats.rooms_l
3-
WITH (security_invoker='on') as
4-
select
5-
r.id,
6-
r."imageUrl",
7-
r.metadata,
8-
case
9-
when r.type = 'direct' and auth.uid() is not null then
10-
(select coalesce(u."firstName", '') || ' ' || coalesce(u."lastName", '')
11-
from chats.users u
12-
where u.id = any(r."userIds") and u.id <> auth.uid()
13-
limit 1)
14-
else
15-
r.name
16-
end as name,
17-
r.type,
18-
r."userIds",
19-
r."lastMessages",
20-
r."userRoles",
21-
r."createdAt",
22-
r."updatedAt"
23-
from chats.rooms r;
3+
4+
create or replace view chats.rooms_l
5+
with (security_invoker='on') as
6+
select r.id,
7+
r."imageUrl",
8+
r.metadata,
9+
case
10+
when r.type = 'direct' and auth.uid() is not null then
11+
(select coalesce(u."firstName", '') || ' ' || coalesce(u."lastName", '')
12+
from chats.users u
13+
where u.id = any (r."userIds")
14+
and u.id <> auth.uid()
15+
limit 1)
16+
else
17+
r.name
18+
end as name,
19+
r.type,
20+
r."userIds",
21+
r."lastMessages",
22+
r."userRoles",
23+
r."createdAt",
24+
r."updatedAt",
25+
(select jsonb_agg(to_jsonb(u))
26+
from chats.users u
27+
where u.id = any (r."userIds")) as users
28+
from chats.rooms r;
29+
30+
31+
create or replace view chats.messages_l
32+
with (security_invoker='on') as
33+
select m.id,
34+
m."createdAt",
35+
m.metadata,
36+
m.duration,
37+
m."mimeType",
38+
m.name,
39+
m."remoteId",
40+
m."repliedMessage",
41+
m."roomId",
42+
m."showStatus",
43+
m.size,
44+
m.status,
45+
m.type,
46+
m."updatedAt",
47+
m.uri,
48+
m."waveForm",
49+
m."isLoading",
50+
m.height,
51+
m.width,
52+
m."previewData",
53+
m."authorId",
54+
m.text,
55+
to_jsonb(u) as author,
56+
to_jsonb(r) as room
57+
from chats.messages m
58+
left join chats.users u on u.id = m."authorId"
59+
left join chats.rooms_l r on r.id = m."roomId";

lib/src/class/supabase_chat_controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class SupabaseChatController {
6969

7070
PostgrestTransformBuilder _messagesQuery() => _client
7171
.schema(_config.schema)
72-
.from(_config.messagesTableName)
72+
.from(_config.messagesViewName)
7373
.select()
7474
.eq('roomId', int.parse(_room.id))
7575
.order('createdAt', ascending: false)

0 commit comments

Comments
 (0)