Offline Support
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import 'package:brick_offline_first_with_supabase/brick_offline_first_with_supabase.dart';
|
||||
import 'package:brick_sqlite/brick_sqlite.dart';
|
||||
import 'package:brick_supabase/brick_supabase.dart';
|
||||
|
||||
import '../utils/app_time.dart';
|
||||
|
||||
// Supabase table is 'notifications' (not 'notification_items').
|
||||
@ConnectOfflineFirstWithSupabase(
|
||||
supabaseConfig: SupabaseSerializable(tableName: 'notifications'),
|
||||
)
|
||||
class NotificationItem extends OfflineFirstWithSupabaseModel {
|
||||
final String id;
|
||||
final String userId;
|
||||
final String? actorId;
|
||||
final String? ticketId;
|
||||
final String? taskId;
|
||||
final String? leaveId;
|
||||
final String? passSlipId;
|
||||
final String? itServiceRequestId;
|
||||
final String? announcementId;
|
||||
final int? messageId;
|
||||
final String type;
|
||||
final DateTime createdAt;
|
||||
final DateTime? readAt;
|
||||
|
||||
@Supabase(ignore: true)
|
||||
@Sqlite(ignore: true)
|
||||
bool get isUnread => readAt == null;
|
||||
|
||||
NotificationItem({
|
||||
required this.id,
|
||||
required this.userId,
|
||||
required this.actorId,
|
||||
required this.ticketId,
|
||||
required this.taskId,
|
||||
this.leaveId,
|
||||
this.passSlipId,
|
||||
required this.itServiceRequestId,
|
||||
this.announcementId,
|
||||
required this.messageId,
|
||||
required this.type,
|
||||
required this.createdAt,
|
||||
required this.readAt,
|
||||
});
|
||||
|
||||
factory NotificationItem.fromMap(Map<String, dynamic> map) {
|
||||
return NotificationItem(
|
||||
id: map['id'] as String,
|
||||
userId: map['user_id'] as String,
|
||||
actorId: map['actor_id'] as String?,
|
||||
ticketId: map['ticket_id'] as String?,
|
||||
taskId: map['task_id'] as String?,
|
||||
leaveId: map['leave_id'] as String?,
|
||||
passSlipId: map['pass_slip_id'] as String?,
|
||||
itServiceRequestId: map['it_service_request_id'] as String?,
|
||||
announcementId: map['announcement_id'] as String?,
|
||||
messageId: map['message_id'] as int?,
|
||||
type: map['type'] as String? ?? 'mention',
|
||||
createdAt: AppTime.parse(map['created_at'] as String),
|
||||
readAt: map['read_at'] == null
|
||||
? null
|
||||
: AppTime.parse(map['read_at'] as String),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user