Skip to content
Snippets Groups Projects
channelmodel.h 3.72 KiB
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/>.           *
 *                                                                                          *
 ********************************************************************************************/


Armin Felder's avatar
Armin Felder committed
#ifndef CHANNELMODEL_H
#define CHANNELMODEL_H

#include <QAbstractListModel>
#include <QSharedPointer>
#include <QMultiMap>
#include <QSet>
#include <QDebug>
#include <QString>
#include <QTimer>

#include "repos/entities/rocketchatchannel.h"
#include "container/sortedvector.h"

class RocketChatChannel;

class ChannelModel : public QAbstractListModel
{
Armin Felder's avatar
Armin Felder committed
        enum class ChannelRoles : int {
            name = Qt::UserRole + 1,
            roomId,
            unreadMessages,
            lastMessageText,
            channelType,
            readonly,
Armin Felder's avatar
Armin Felder committed
            archived,
Armin Felder's avatar
Armin Felder committed
            ownerName,
Armin Felder's avatar
Armin Felder committed
            username,
Armin Felder's avatar
Armin Felder committed
            userStatus,
            avatarImg
Armin Felder's avatar
as  
Armin Felder committed
        ChannelModel() = default;
        int rowCount( const QModelIndex &parent = QModelIndex() ) const;
        QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
        bool addChannel( const QSharedPointer<RocketChatChannel> & );
        QString getType() const;
        void setType( const QString &value );
        void sortChanged( void );
        void clear( void );
Armin Felder's avatar
Armin Felder committed
    private:
        SortedVector<RocketChatChannel> channelList;
        QSet<QString> duplicateCheck;
        QHash<int, QByteArray> roleNames() const;
        QString type;
        void onNewerMessage( const QString &id, qint64 timestamp );
        void onUnreadMessageChanged( const QString &id, int number );
Armin Felder's avatar
Armin Felder committed
        void onDataChanged( const QString &id, const QString &property );
        void onDeleted( const QString &pId, bool deleted );
Armin Felder's avatar
Armin Felder committed
        void onChannelOrderChanged(const QString &pId, qint64 pTimestamp);

        QTimer timer;
    signals:
        void countChanged( void );
        void unreadMessagesChanged( void );

    public slots:
Armin Felder's avatar
sd  
Armin Felder committed
        void addChannelSlot(const QSharedPointer<RocketChatChannel> &);
Armin Felder's avatar
Armin Felder committed
        bool addChannelsSlot( const QVector<QSharedPointer<RocketChatChannel>> & );
Armin Felder's avatar
Armin Felder committed

};

#endif // CHANNELMODEL_H