1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 00:05:16 +00:00

Get conversation message

This commit is contained in:
2019-04-25 08:56:16 +02:00
parent 1ec197202c
commit e2202a4794
8 changed files with 245 additions and 14 deletions

View 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;
}
}

View File

@ -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);
}