Skip to content

Commit 389e07d

Browse files
Wahid NasriWahid Nasri
Wahid Nasri
authored and
Wahid Nasri
committed
add presence column to db and attribute to contactchat
1 parent 11bba86 commit 389e07d

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

lib/abstraction/models/ContactChat.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
import 'dart:convert';
22

3+
import 'package:flutter/foundation.dart';
4+
import 'package:flutter_mqtt/abstraction/models/enums/PresenceType.dart';
5+
36
class ContactChat {
47
String firstName;
58
String lastName;
69
String id;
710
String? avatar;
811
String roomId;
12+
PresenceType? presence;
913
bool? isGroup;
1014
ContactChat(
1115
{required this.firstName,
1216
required this.lastName,
1317
required this.id,
1418
required this.avatar,
1519
required this.roomId,
16-
required this.isGroup});
20+
required this.isGroup,
21+
this.presence});
1722

1823
Map<String, dynamic> toMap() {
1924
return {
2025
'firstName': firstName,
21-
'lastName':lastName,
26+
'lastName': lastName,
2227
'id': id,
2328
'avatar': avatar,
2429
'roomId': roomId,
2530
'isGroup': isGroup,
31+
'presence': presence,
2632
};
2733
}
2834

@@ -33,6 +39,9 @@ class ContactChat {
3339
id: map['id'],
3440
avatar: map['avatar'],
3541
roomId: map['roomId'],
42+
presence: map['presence'] == null ? null : PresenceType.values
43+
.where((e) => describeEnum(e) == map['presence'])
44+
.first,
3645
isGroup: map['isGroup'] != null && map['isGroup'] == true,
3746
);
3847
}

lib/db/dao/message_dao.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class MessageDao extends DatabaseAccessor<MyDatabase> with _$MessageDaoMixin {
8181
// then, in the database class:
8282
Stream<List<ExtendedDbContact>> getConversations() {
8383
return customSelect(
84-
'SELECT c.id, c.first_name, c.last_name, c.avatar, c.room_id, c.is_group, m.mtype as message_type, m.mid as message_id, m.text as message_text, m.moriginality as message_originality, m.send_time '
84+
'SELECT c.id, c.first_name, c.last_name, c.avatar, c.room_id, c.is_group, c.presence presence, m.mtype as message_type, m.mid as message_id, m.text as message_text, m.moriginality as message_originality, m.send_time '
8585
'FROM (select id as mid, type as mtype, from_id as mfrom_id, originality as moriginality, room_id as mroom_id, text, send_time from messages order by send_time desc) m JOIN contacts c on c.room_id = m.mroom_id '
8686
'GROUP BY room_id ORDER BY send_time DESC',
8787
readsFrom: {

lib/db/tables/ContactTable.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Contacts extends Table {
99
//TextColumn get isGroup => text()();
1010
TextColumn get avatar => text().nullable()();
1111
BoolColumn get isGroup => boolean().named("is_group")();
12+
TextColumn get presence => text().nullable()();
1213
@override
1314
Set<Column> get primaryKey => {id};
1415
}

lib/db/tables/ExtendedDbContact.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import 'package:flutter/foundation.dart';
2+
import 'package:flutter_mqtt/abstraction/models/enums/PresenceType.dart';
3+
14
class ExtendedDbContact {
25
final String id;
36
final String first_name;
47
final String last_name;
58
final String? avatar;
69
final String room_id;
10+
final PresenceType? presence;
711
final String message_type;
812
final String message_id;
913
final String message_text;
@@ -22,7 +26,8 @@ class ExtendedDbContact {
2226
required this.message_text,
2327
required this.message_originality,
2428
required this.send_time,
25-
required this.is_group});
29+
required this.is_group,
30+
this.presence});
2631

2732
factory ExtendedDbContact.fromJson(Map<String, dynamic> json) {
2833
return ExtendedDbContact(
@@ -37,6 +42,9 @@ class ExtendedDbContact {
3742
message_originality: json["message_originality"],
3843
send_time: int.parse(json["send_time"].toString()),
3944
is_group: json["is_group"] == 1,
45+
presence: json['presence'] == null ? null : PresenceType.values
46+
.where((e) => describeEnum(e) == json['presence'])
47+
.first,
4048
);
4149
}
4250

@@ -53,6 +61,7 @@ class ExtendedDbContact {
5361
"message_originality": this.message_originality,
5462
"send_time": this.send_time,
5563
"is_group": this.is_group,
64+
"presence": this.presence
5665
};
5766
}
5867
//

0 commit comments

Comments
 (0)