2019-04-25 06:56:16 +00:00
|
|
|
import 'dart:collection';
|
|
|
|
|
|
|
|
import 'package:comunic/models/conversation_message.dart';
|
|
|
|
|
|
|
|
/// Conversations messages list
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
|
|
|
class ConversationMessagesList extends ListBase<ConversationMessage> {
|
|
|
|
final List<ConversationMessage> _list = List();
|
|
|
|
|
|
|
|
set length(int v) => _list.length = v;
|
|
|
|
|
|
|
|
int get length => _list.length;
|
|
|
|
|
|
|
|
@override
|
|
|
|
ConversationMessage operator [](int index) {
|
|
|
|
return _list[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void operator []=(int index, ConversationMessage value) {
|
|
|
|
_list[index] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the list of the users ID who own a message in this list
|
|
|
|
List<int> getUsersID() {
|
|
|
|
final List<int> users = List();
|
|
|
|
|
|
|
|
for (ConversationMessage message in this)
|
|
|
|
if (!users.contains(message.userID)) users.add(message.userID);
|
|
|
|
|
|
|
|
return users;
|
|
|
|
}
|
2019-04-27 06:51:58 +00:00
|
|
|
|
|
|
|
/// Get the ID of the last message present in this list
|
|
|
|
int get lastMessageID {
|
|
|
|
int lastMessageID = 0;
|
|
|
|
for (ConversationMessage message in this)
|
|
|
|
if (message.id > lastMessageID) lastMessageID = message.id;
|
|
|
|
return lastMessageID;
|
|
|
|
}
|
2019-04-27 16:29:30 +00:00
|
|
|
|
|
|
|
/// Get the ID of the first message present in this list
|
|
|
|
int get firstMessageID {
|
|
|
|
int firstMessageID = this[0].id;
|
|
|
|
for (ConversationMessage message in this)
|
|
|
|
if (message.id < firstMessageID) firstMessageID = message.id;
|
|
|
|
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
|
|
|
|
void removeMsg(int id) => removeWhere((f) => f.id == id);
|
2019-04-25 06:56:16 +00:00
|
|
|
}
|