mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 00:05:16 +00:00
Get conversation message
This commit is contained in:
35
lib/lists/conversation_messages_list.dart
Normal file
35
lib/lists/conversation_messages_list.dart
Normal file
@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -7,10 +7,10 @@ import 'package:comunic/models/user.dart';
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
class UsersList extends ListBase<User> {
|
||||
|
||||
List<User> _list = List();
|
||||
|
||||
int get length => _list.length;
|
||||
|
||||
set length(l) => _list.length = l;
|
||||
|
||||
@override
|
||||
@ -24,11 +24,13 @@ class UsersList extends ListBase<User> {
|
||||
}
|
||||
|
||||
/// Find a user with a specific ID
|
||||
User getUser(int userID){
|
||||
for(int i = 0; i < this.length; i++)
|
||||
if(this[i].id == userID)
|
||||
return this[i];
|
||||
User getUser(int userID) {
|
||||
for (int i = 0; i < this.length; i++)
|
||||
if (this[i].id == userID) return this[i];
|
||||
|
||||
throw "User not found in the list!";
|
||||
throw "User not found in the list!";
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the list of users ID present in this list
|
||||
List<int> get usersID => List.generate(length, (i) => this[i].id);
|
||||
}
|
||||
|
Reference in New Issue
Block a user