Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "usermodel.h"
UserModel::UserModel( QObject *parent ): QAbstractListModel( parent )
{
}
int UserModel::rowCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent );
int count = userMap.values( current ).count();
qDebug() << "count of current channel users" << count;
return count;
}
QVariant UserModel::data( const QModelIndex &index, int role ) const
{
auto userList = userMap.values( current );
if ( userList.count() < index.row() ) {
return QVariant();
}
auto user = userList.at( index.row() );
if ( role == UserRoles::UserName ) {
return user->getUserName();
};
return QVariant();
}
bool UserModel::insertUser( QString channelId, QSharedPointer<RocketChatUser> user )
{
if ( duplicateCheck.contains( user->getUserId() ) ) {
return false;
}
auto values = userMap.values( channelId );
int index = values.count();
if ( channelId == current ) {
beginInsertRows( QModelIndex(), index, index );
}
userMap.insert( channelId, user );
bool inserted = insertRow(index-1);
if(!inserted){
qDebug() << "row was not inserted";
}
if ( channelId == current ) {
endInsertRows();
emit countChanged();
}
return true;
}
QString UserModel::getCurrent() const
{
return current;
}
void UserModel::setCurrent( const QString &value )
{
current = value;
}
void UserModel::onCurrentChannelChanged( const QString &newText )
{
current = newText;
}
QHash<int, QByteArray> UserModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[UserName] = "username";
roles[UserId] = "userId";
return roles;
}