Save Bookmark with Bookmark overview in channel menu, and bookmark-filter in channel and contact.
This commit is contained in:
1 parent
c0702806de
commit
f32300797e
39 files changed
+1556
-25
No files matched your search
@@ -0,0 +1,110 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'channel_message.dart';
|
||||
import 'message.dart';
|
||||
|
||||
enum BookmarkSourceType { contact, channel }
|
||||
|
||||
@immutable
|
||||
class BookmarkedMessage {
|
||||
final BookmarkSourceType sourceType;
|
||||
final String sourceId;
|
||||
final String sourceName;
|
||||
final String messageId;
|
||||
final String senderName;
|
||||
final String text;
|
||||
final String? translatedText;
|
||||
final DateTime timestamp;
|
||||
final DateTime receivedAt;
|
||||
final bool isOutgoing;
|
||||
|
||||
const BookmarkedMessage({
|
||||
required this.sourceType,
|
||||
required this.sourceId,
|
||||
required this.sourceName,
|
||||
required this.messageId,
|
||||
required this.senderName,
|
||||
required this.text,
|
||||
required this.timestamp,
|
||||
required this.receivedAt,
|
||||
required this.isOutgoing,
|
||||
this.translatedText,
|
||||
});
|
||||
|
||||
factory BookmarkedMessage.fromContact({
|
||||
required Message message,
|
||||
required String contactKey,
|
||||
required String contactName,
|
||||
required String senderName,
|
||||
}) => BookmarkedMessage(
|
||||
sourceType: BookmarkSourceType.contact,
|
||||
sourceId: contactKey,
|
||||
sourceName: contactName,
|
||||
messageId: message.messageId,
|
||||
senderName: senderName,
|
||||
text: message.text,
|
||||
translatedText: message.translatedText,
|
||||
timestamp: message.timestamp,
|
||||
receivedAt: message.receivedAt,
|
||||
isOutgoing: message.isOutgoing,
|
||||
);
|
||||
|
||||
factory BookmarkedMessage.fromChannel({
|
||||
required ChannelMessage message,
|
||||
required String channelId,
|
||||
required String channelName,
|
||||
required String senderName,
|
||||
}) => BookmarkedMessage(
|
||||
sourceType: BookmarkSourceType.channel,
|
||||
sourceId: channelId,
|
||||
sourceName: channelName,
|
||||
messageId: message.messageId,
|
||||
senderName: senderName,
|
||||
text: message.text,
|
||||
translatedText: message.translatedText,
|
||||
timestamp: message.timestamp,
|
||||
receivedAt: message.receivedAt,
|
||||
isOutgoing: message.isOutgoing,
|
||||
);
|
||||
|
||||
String get storageId => storageIdFor(sourceType, sourceId, messageId);
|
||||
|
||||
static String storageIdFor(
|
||||
BookmarkSourceType sourceType,
|
||||
String sourceId,
|
||||
String messageId,
|
||||
) => '${sourceType.name}:$sourceId:$messageId';
|
||||
|
||||
Map<String, Object?> toJson() => {
|
||||
'sourceType': sourceType.name,
|
||||
'sourceId': sourceId,
|
||||
'sourceName': sourceName,
|
||||
'messageId': messageId,
|
||||
'senderName': senderName,
|
||||
'text': text,
|
||||
'translatedText': translatedText,
|
||||
'timestamp': timestamp.millisecondsSinceEpoch,
|
||||
'receivedAt': receivedAt.millisecondsSinceEpoch,
|
||||
'isOutgoing': isOutgoing,
|
||||
};
|
||||
|
||||
factory BookmarkedMessage.fromJson(Map<String, dynamic> json) {
|
||||
final type = BookmarkSourceType.values.firstWhere(
|
||||
(value) => value.name == json['sourceType'],
|
||||
);
|
||||
return BookmarkedMessage(
|
||||
sourceType: type,
|
||||
sourceId: json['sourceId'] as String,
|
||||
sourceName: json['sourceName'] as String,
|
||||
messageId: json['messageId'] as String,
|
||||
senderName: json['senderName'] as String,
|
||||
text: json['text'] as String,
|
||||
translatedText: json['translatedText'] as String?,
|
||||
timestamp: DateTime.fromMillisecondsSinceEpoch(json['timestamp'] as int),
|
||||
receivedAt: DateTime.fromMillisecondsSinceEpoch(
|
||||
json['receivedAt'] as int? ?? json['timestamp'] as int,
|
||||
),
|
||||
isOutgoing: json['isOutgoing'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ class ChannelMessage {
|
||||
/// to the bottom; [timestamp] stays the sender's identity time.
|
||||
final DateTime receivedAt;
|
||||
final bool isOutgoing;
|
||||
final bool isBookmarked;
|
||||
final ChannelMessageStatus status;
|
||||
final List<Repeat> repeats;
|
||||
final int repeatCount;
|
||||
@@ -77,6 +78,7 @@ class ChannelMessage {
|
||||
required this.timestamp,
|
||||
DateTime? receivedAt,
|
||||
required this.isOutgoing,
|
||||
this.isBookmarked = false,
|
||||
this.status = ChannelMessageStatus.pending,
|
||||
this.repeats = const [],
|
||||
this.repeatCount = 0,
|
||||
@@ -117,6 +119,7 @@ class ChannelMessage {
|
||||
|
||||
ChannelMessage copyWith({
|
||||
ChannelMessageStatus? status,
|
||||
bool? isBookmarked,
|
||||
List<Repeat>? repeats,
|
||||
int? repeatCount,
|
||||
int? pathLength,
|
||||
@@ -159,6 +162,7 @@ class ChannelMessage {
|
||||
timestamp: timestamp,
|
||||
receivedAt: receivedAt,
|
||||
isOutgoing: isOutgoing,
|
||||
isBookmarked: isBookmarked ?? this.isBookmarked,
|
||||
status: status ?? this.status,
|
||||
repeats: repeats ?? this.repeats,
|
||||
repeatCount: repeatCount ?? this.repeatCount,
|
||||
|
||||
@@ -34,6 +34,7 @@ class Message {
|
||||
/// to the bottom; [timestamp] stays the sender's identity time.
|
||||
final DateTime receivedAt;
|
||||
final bool isOutgoing;
|
||||
final bool isBookmarked;
|
||||
final bool isCli;
|
||||
final MessageStatus status;
|
||||
final String? originalText;
|
||||
@@ -62,6 +63,7 @@ class Message {
|
||||
required this.timestamp,
|
||||
DateTime? receivedAt,
|
||||
required this.isOutgoing,
|
||||
this.isBookmarked = false,
|
||||
this.isCli = false,
|
||||
this.status = MessageStatus.pending,
|
||||
String? messageId,
|
||||
@@ -108,6 +110,7 @@ class Message {
|
||||
int? pathLength,
|
||||
Uint8List? pathBytes,
|
||||
bool? isCli,
|
||||
bool? isBookmarked,
|
||||
Object? originalText = _unset,
|
||||
Object? translatedText = _unset,
|
||||
Object? translatedLanguageCode = _unset,
|
||||
@@ -123,6 +126,7 @@ class Message {
|
||||
timestamp: timestamp,
|
||||
receivedAt: receivedAt,
|
||||
isOutgoing: isOutgoing,
|
||||
isBookmarked: isBookmarked ?? this.isBookmarked,
|
||||
isCli: isCli ?? this.isCli,
|
||||
status: status ?? this.status,
|
||||
messageId: messageId,
|
||||
|
||||
Reference in new issue
Block a user