Commit c1f0fa7b authored by armin's avatar armin
Browse files

asd

parent 01713517
...@@ -38,103 +38,105 @@ QVariant ChannelModel::data( const QModelIndex &index, int role ) const ...@@ -38,103 +38,105 @@ QVariant ChannelModel::data( const QModelIndex &index, int role ) const
auto currentChannel = channelList.at( row ); auto currentChannel = channelList.at( row );
auto roleType = static_cast<ChannelRoles>( role ); if ( !currentChannel.isNull() ) {
auto roleType = static_cast<ChannelRoles>( role );
switch ( roleType ) { switch ( roleType ) {
case ChannelRoles::name: case ChannelRoles::name:
return currentChannel->getName(); return currentChannel->getName();
case ChannelRoles::roomId: case ChannelRoles::roomId:
return currentChannel->getRoomId(); return currentChannel->getRoomId();
case ChannelRoles::lastMessageText: { case ChannelRoles::lastMessageText: {
auto channel = channelList.at( row ); auto channel = channelList.at( row );
auto message = channel->getYoungestMessage(); auto message = channel->getYoungestMessage();
if ( message.isNull() ) { if ( message.isNull() ) {
return ""; return "";
} }
if ( message->getMessageType() == QStringLiteral( "file" ) || message->getMessageType() == QStringLiteral( "image" ) || message->getMessageType() == QStringLiteral( "audio" ) ) {
return tr( QByteArrayLiteral( "file upload" ) );
}
if ( message->getMessageType() == QStringLiteral( "file" ) || message->getMessageType() == QStringLiteral( "image" ) || message->getMessageType() == QStringLiteral( "audio" ) ) { auto messageText = message->getMessageString();
return tr( QByteArrayLiteral( "file upload" ) ); messageText = messageText.replace( "<img height='20' width='20'", "<img height='10' width='10'" );
return messageText;
} }
auto messageText = message->getMessageString(); case ChannelRoles::channelType:
messageText = messageText.replace( "<img height='20' width='20'", "<img height='10' width='10'" ); return currentChannel->getType();
return messageText;
}
case ChannelRoles::channelType: case ChannelRoles::unreadMessages:
return currentChannel->getType(); return currentChannel->getUnreadMessages();
case ChannelRoles::unreadMessages: case ChannelRoles::readonly:
return currentChannel->getUnreadMessages(); return currentChannel->getReadOnly() || currentChannel->getArchived() || currentChannel->getBlocked();
case ChannelRoles::readonly: case ChannelRoles::ownerId:
return currentChannel->getReadOnly() || currentChannel->getArchived() || currentChannel->getBlocked(); return currentChannel->getOwnerId();
case ChannelRoles::ownerId: case ChannelRoles::archived:
return currentChannel->getOwnerId(); return currentChannel->getArchived();
case ChannelRoles::archived: case ChannelRoles::blocked:
return currentChannel->getArchived(); return currentChannel->getBlocked();
case ChannelRoles::blocked: case ChannelRoles::username:
return currentChannel->getBlocked(); return currentChannel->getUsername();
case ChannelRoles::username: case ChannelRoles::userStatus: {
return currentChannel->getUsername(); int status = 0;
auto partner = currentChannel->getChatPartner();
case ChannelRoles::userStatus: { if ( !partner.isNull() ) {
int status = 0; switch ( partner->getStatus() ) {
auto partner = currentChannel->getChatPartner(); case RocketChatUser::status::ONLINE :
status = 0;
break;
if ( !partner.isNull() ) { case RocketChatUser::status::AWAY :
switch ( partner->getStatus() ) { status = 1;
case RocketChatUser::status::ONLINE : break;
status = 0;
break;
case RocketChatUser::status::AWAY : case RocketChatUser::status::OFFLINE:
status = 1; status = 2;
break; break;
case RocketChatUser::status::OFFLINE: case RocketChatUser::status::BUSY:
status = 2; status = 3;
break; break;
}
case RocketChatUser::status::BUSY:
status = 3;
break;
} }
return status;
} }
return status; case ChannelRoles::deleted:
} return currentChannel->getDeleted();
case ChannelRoles::deleted:
return currentChannel->getDeleted();
case ChannelRoles::ownerName: case ChannelRoles::ownerName:
return currentChannel->getOwnerName(); return currentChannel->getOwnerName();
case ChannelRoles::avatarImg: { case ChannelRoles::avatarImg: {
auto avatarImg = currentChannel->getAvatarImg(); auto avatarImg = currentChannel->getAvatarImg();
if ( !avatarImg.isNull() ) { if ( !avatarImg.isNull() ) {
auto path = Utils::getPathPrefix() + avatarImg->getFilePath(); auto path = Utils::getPathPrefix() + avatarImg->getFilePath();
if ( path.endsWith( "svg" ) ) { if ( path.endsWith( "svg" ) ) {
return "qrc:res/user-identity.svg"; return "qrc:res/user-identity.svg";
} else {
return path;
}
} else { } else {
return path; return "";
} }
} else {
return "";
} }
}
}
} }
return QVariant(); return QVariant();
...@@ -174,6 +176,8 @@ bool ChannelModel::addChannelsSlot( const QList<QSharedPointer<RocketChatChannel ...@@ -174,6 +176,8 @@ bool ChannelModel::addChannelsSlot( const QList<QSharedPointer<RocketChatChannel
int from = -1; int from = -1;
int to = -1; int to = -1;
beginResetModel();
for ( const auto &channel : pChannels ) { for ( const auto &channel : pChannels ) {
if ( !channel.isNull() && !channel->getRoomId().isEmpty() && !duplicateCheck.contains( channel->getRoomId() ) ) { if ( !channel.isNull() && !channel->getRoomId().isEmpty() && !duplicateCheck.contains( channel->getRoomId() ) ) {
//connect( channel.data(), &RocketChatChannel::messageAdded, this, &ChannelModel::onNewerMessage, Qt::UniqueConnection ); //connect( channel.data(), &RocketChatChannel::messageAdded, this, &ChannelModel::onNewerMessage, Qt::UniqueConnection );
...@@ -197,9 +201,9 @@ bool ChannelModel::addChannelsSlot( const QList<QSharedPointer<RocketChatChannel ...@@ -197,9 +201,9 @@ bool ChannelModel::addChannelsSlot( const QList<QSharedPointer<RocketChatChannel
} }
} }
beginInsertRows( QModelIndex(), from, to ); //beginInsertRows( QModelIndex(), from, to );
endInsertRows(); //endInsertRows();
// endResetModel(); endResetModel();
return true; return true;
} }
......
...@@ -113,7 +113,7 @@ QList<QSharedPointer<RocketChatChannel> > RocketChatChannelService::processChann ...@@ -113,7 +113,7 @@ QList<QSharedPointer<RocketChatChannel> > RocketChatChannelService::processChann
qint64 updatedAt = -1; qint64 updatedAt = -1;
//don't ask ... //don't ask ...
if ( currentChannelObject.contains( QStringLiteral( "_updatedAt" ) ) ) { if ( currentChannelObject.contains( QStringLiteral( "_updatedAt" ) ) && !currentChannelObject.contains( QStringLiteral( "ls" ) ) ) {
auto updatedObj = currentChannelObject[QStringLiteral( "_updatedAt" )].toObject(); auto updatedObj = currentChannelObject[QStringLiteral( "_updatedAt" )].toObject();
updatedAt = static_cast<qint64>( updatedObj[QStringLiteral( "$date" )].toDouble() ); updatedAt = static_cast<qint64>( updatedObj[QStringLiteral( "$date" )].toDouble() );
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment