2022-03-10 18:39:57 +00:00
|
|
|
import 'package:comunic/lists/abstract_list.dart';
|
2019-04-25 06:56:16 +00:00
|
|
|
import 'package:comunic/models/conversation_message.dart';
|
|
|
|
|
|
|
|
/// Conversations messages list
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
class ConversationMessagesList extends AbstractList<ConversationMessage> {
|
2019-04-25 06:56:16 +00:00
|
|
|
/// Get the list of the users ID who own a message in this list
|
2022-03-10 18:39:57 +00:00
|
|
|
Set<int?> getUsersID() {
|
|
|
|
final Set<int?> users = Set();
|
2019-04-25 06:56:16 +00:00
|
|
|
|
2021-03-10 18:08:18 +00:00
|
|
|
for (ConversationMessage message in this) users.addAll(message.usersID);
|
2019-04-25 06:56:16 +00:00
|
|
|
|
|
|
|
return users;
|
|
|
|
}
|
2019-04-27 06:51:58 +00:00
|
|
|
|
|
|
|
/// Get the ID of the last message present in this list
|
2022-03-10 18:39:57 +00:00
|
|
|
int? get lastMessageID {
|
|
|
|
int? lastMessageID = 0;
|
2019-04-27 06:51:58 +00:00
|
|
|
for (ConversationMessage message in this)
|
2022-03-10 18:39:57 +00:00
|
|
|
if (message.id! > lastMessageID!) lastMessageID = message.id;
|
2019-04-27 06:51:58 +00:00
|
|
|
return lastMessageID;
|
|
|
|
}
|
2019-04-27 16:29:30 +00:00
|
|
|
|
|
|
|
/// Get the ID of the first message present in this list
|
2022-03-10 18:39:57 +00:00
|
|
|
int? get firstMessageID {
|
|
|
|
int? firstMessageID = this[0].id;
|
2019-04-27 16:29:30 +00:00
|
|
|
for (ConversationMessage message in this)
|
2022-03-10 18:39:57 +00:00
|
|
|
if (message.id! < firstMessageID!) firstMessageID = message.id;
|
2019-04-27 16:29:30 +00:00
|
|
|
return firstMessageID;
|
|
|
|
}
|
2020-04-19 12:16:35 +00:00
|
|
|
|
|
|
|
/// Replace a message by another one (if any)
|
|
|
|
void replace(ConversationMessage msg) {
|
|
|
|
final index = this.indexWhere((t) => t.id == msg.id);
|
|
|
|
if (index >= 0) this[index] = msg;
|
|
|
|
}
|
2020-04-19 12:29:01 +00:00
|
|
|
|
|
|
|
/// Remove a message from this list
|
2022-03-10 18:39:57 +00:00
|
|
|
void removeMsg(int? id) => removeWhere((f) => f.id == id);
|
2019-04-25 06:56:16 +00:00
|
|
|
}
|