Newer
Older
/********************************************************************************************
* *
* Copyright (C) 2017 Armin Felder, Dennis Beier *
* This file is part of RocketChatMobileEngine <https://git.fairkom.net/chat/fairchat>. *
* *
* RocketChatMobileEngine is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* RocketChatMobileEngine is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with RocketChatMobileEngine. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************************/
// connect(&timer,&QTimer::timeout,this,&ChannelModel::sortChanged);
int ChannelModel::rowCount( const QModelIndex &parent ) const
Q_UNUSED( parent )
int count = channelList.count();
QVariant ChannelModel::data( const QModelIndex &index, int role ) const
if ( channelList.isEmpty() || row > channelList.count() ) {
auto currentChannel = channelList.at( row );
if ( role == name ) {
if ( role == roomId ) {
if ( role == lastMessageText ) {
auto channel = channelList.at( row );
if ( message.isNull() ) {
}
if ( message->getMessageType() == "file" || message->getMessageType() == "image" || message->getMessageType() == "audio" ) {
return tr( "file upload" );
}
if ( role == channelType ) {
if ( role == unreadMessages ) {
if ( role == readonly ) {
return currentChannel->getReadOnly() || currentChannel->getArchived();
}
if ( role == archived ) {
bool ChannelModel::addChannel( const QSharedPointer<RocketChatChannel> &channel )
if ( !channel.isNull() && channel->getRoomId() != "" && !duplicateCheck.contains( channel->getRoomId() ) ) {
connect( channel.data(), &RocketChatChannel::messageAdded, this, &ChannelModel::onNewerMessage, Qt::UniqueConnection );
connect( channel.data(), &RocketChatChannel::unreadMessagesChanged, this, &ChannelModel::onUnreadMessageChanged, Qt::UniqueConnection );
duplicateCheck.insert( channel->getRoomId() );
int pos = channelList.findPosition( channel );
emit beginInsertRows( QModelIndex(), pos, pos );
channelList.insertSort( channel );
return false;
}
}
QHash<int, QByteArray> ChannelModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[name] = "name";
roles[roomId] = "roomId";
roles[unreadMessages] = "unreadMessages";
roles[channelType] = "type";
roles[lastMessageText] = "lastMessageText";
roles[readonly] = "readonly";
roles[archived] = "archived";
void ChannelModel::onNewerMessage( const QString &id, qint64 timestamp )
Q_UNUSED( timestamp )
for ( const auto ¤t : channelList ) {
if ( current->getRoomId() == id ) {
//emit dataChanged(index(pos),index(pos),{lastMessageText});
}
sortChanged();
}
void ChannelModel::onUnreadMessageChanged( const QString &id, int number )
Q_UNUSED( number )
qDebug() << "unread signal catched";
for ( const auto ¤t : channelList ) {
if ( current->getRoomId() == id ) {
if ( found ) {
qDebug() << "channel found";
emit dataChanged( index( pos ), index( pos ), {unreadMessages} );
void ChannelModel::addChannelSlot( const QSharedPointer<RocketChatChannel> &channel )
addChannel( channel );
}
QString ChannelModel::getType() const
{
return type;
}
void ChannelModel::setType( const QString &value )
{
type = value;
}
void ChannelModel::sortChanged()
{
beginResetModel();
std::sort( channelList.begin(), channelList.end(), []( QSharedPointer<RocketChatChannel> channel1, QSharedPointer<RocketChatChannel> channel2 ) {
auto youngest1 = channel1->getYoungestMessage();
auto youngest2 = channel2->getYoungestMessage();
if ( !youngest1.isNull() && !youngest2.isNull() ) {
auto timestamp1 = youngest1->getTimestamp();
auto timestamp2 = youngest2->getTimestamp();
return timestamp2 < timestamp1;
} else if ( youngest1.isNull() && !youngest2.isNull() ) {
} else if ( youngest2.isNull() && !youngest1.isNull() ) {
void ChannelModel::clear()
{
channelList.clear();