forked from blue/squawk
pal resourse sticking, notifications of unread messages, new message icons
This commit is contained in:
parent
4c5efad9dc
commit
b44873d587
12 changed files with 119 additions and 95 deletions
|
@ -31,6 +31,8 @@ Models::Element::Element(Type p_type, const Models::Account* acc, const QString&
|
|||
{
|
||||
connect(feed, &MessageFeed::requestArchive, this, &Element::requestArchive);
|
||||
connect(feed, &MessageFeed::fileDownloadRequest, this, &Element::fileDownloadRequest);
|
||||
connect(feed, &MessageFeed::unreadMessagesCountChanged, this, &Element::onFeedUnreadMessagesCountChanged);
|
||||
connect(feed, &MessageFeed::unnoticedMessage, this, &Element::onFeedUnnoticedMessage);
|
||||
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("avatarState");
|
||||
if (itr != data.end()) {
|
||||
|
@ -134,11 +136,6 @@ unsigned int Models::Element::getMessagesCount() const
|
|||
void Models::Element::addMessage(const Shared::Message& data)
|
||||
{
|
||||
feed->addMessage(data);
|
||||
if (type == contact) {
|
||||
changed(4);
|
||||
} else if (type == room) {
|
||||
changed(5);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Element::changeMessage(const QString& id, const QMap<QString, QVariant>& data)
|
||||
|
@ -170,3 +167,17 @@ void Models::Element::fileError(const QString& messageId, const QString& error,
|
|||
{
|
||||
feed->fileError(messageId, error, up);
|
||||
}
|
||||
|
||||
void Models::Element::onFeedUnreadMessagesCountChanged()
|
||||
{
|
||||
if (type == contact) {
|
||||
changed(4);
|
||||
} else if (type == room) {
|
||||
changed(5);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Element::onFeedUnnoticedMessage(const Shared::Message& msg)
|
||||
{
|
||||
emit unnoticedMessage(getAccountName(), msg);
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
signals:
|
||||
void requestArchive(const QString& before);
|
||||
void fileDownloadRequest(const QString& url);
|
||||
void unnoticedMessage(const QString& account, const Shared::Message& msg);
|
||||
|
||||
protected:
|
||||
void setJid(const QString& p_jid);
|
||||
|
@ -59,6 +60,10 @@ protected:
|
|||
bool columnInvolvedInDisplay(int col) override;
|
||||
const Account* getParentAccount() const override;
|
||||
|
||||
protected slots:
|
||||
void onFeedUnreadMessagesCountChanged();
|
||||
void onFeedUnnoticedMessage(const Shared::Message& msg);
|
||||
|
||||
protected:
|
||||
QString jid;
|
||||
QString avatarPath;
|
||||
|
|
|
@ -44,12 +44,16 @@ Models::MessageFeed::MessageFeed(const Element* ri, QObject* parent):
|
|||
rosterItem(ri),
|
||||
syncState(incomplete),
|
||||
uploads(),
|
||||
downloads()
|
||||
downloads(),
|
||||
unreadMessages(new std::set<QString>()),
|
||||
observersAmount(0)
|
||||
{
|
||||
}
|
||||
|
||||
Models::MessageFeed::~MessageFeed()
|
||||
{
|
||||
delete unreadMessages;
|
||||
|
||||
for (Shared::Message* message : storage) {
|
||||
delete message;
|
||||
}
|
||||
|
@ -75,6 +79,14 @@ void Models::MessageFeed::addMessage(const Shared::Message& msg)
|
|||
beginInsertRows(QModelIndex(), position, position);
|
||||
storage.insert(copy);
|
||||
endInsertRows();
|
||||
|
||||
emit newMessage(msg);
|
||||
|
||||
if (observersAmount == 0 && !msg.getForwarded()) { //not to notify when the message is delivered by the carbon copy
|
||||
unreadMessages->insert(msg.getId()); //cuz it could be my own one or the one I read on another device
|
||||
emit unreadMessagesCountChanged();
|
||||
emit unnoticedMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::MessageFeed::changeMessage(const QString& id, const QMap<QString, QVariant>& data)
|
||||
|
@ -97,6 +109,11 @@ void Models::MessageFeed::changeMessage(const QString& id, const QMap<QString, Q
|
|||
|
||||
if (functor.hasIdBeenModified()) {
|
||||
changeRoles.insert(MessageRoles::Id);
|
||||
std::set<QString>::const_iterator umi = unreadMessages->find(id);
|
||||
if (umi != unreadMessages->end()) {
|
||||
unreadMessages->erase(umi);
|
||||
unreadMessages->insert(msg->getId());
|
||||
}
|
||||
}
|
||||
|
||||
//change message is a final event in download/upload event train
|
||||
|
@ -258,6 +275,13 @@ QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const
|
|||
case Bulk: {
|
||||
FeedItem item;
|
||||
item.id = msg->getId();
|
||||
|
||||
std::set<QString>::const_iterator umi = unreadMessages->find(item.id);
|
||||
if (umi != unreadMessages->end()) {
|
||||
unreadMessages->erase(umi);
|
||||
emit unreadMessagesCount();
|
||||
}
|
||||
|
||||
item.sentByMe = sentByMe(*msg);
|
||||
item.date = msg->getTime();
|
||||
item.state = msg->getState();
|
||||
|
@ -308,7 +332,7 @@ int Models::MessageFeed::rowCount(const QModelIndex& parent) const
|
|||
|
||||
unsigned int Models::MessageFeed::unreadMessagesCount() const
|
||||
{
|
||||
return storage.size(); //let's say they are all new for now =)
|
||||
return unreadMessages->size();
|
||||
}
|
||||
|
||||
bool Models::MessageFeed::canFetchMore(const QModelIndex& parent) const
|
||||
|
@ -456,6 +480,16 @@ void Models::MessageFeed::fileError(const QString& messageId, const QString& err
|
|||
//TODO
|
||||
}
|
||||
|
||||
void Models::MessageFeed::incrementObservers()
|
||||
{
|
||||
++observersAmount;
|
||||
}
|
||||
|
||||
void Models::MessageFeed::decrementObservers()
|
||||
{
|
||||
--observersAmount;
|
||||
}
|
||||
|
||||
|
||||
QModelIndex Models::MessageFeed::modelIndexById(const QString& id) const
|
||||
{
|
||||
|
|
|
@ -66,10 +66,16 @@ public:
|
|||
void fileError(const QString& messageId, const QString& error, bool up);
|
||||
void fileComplete(const QString& messageId, bool up);
|
||||
|
||||
void incrementObservers();
|
||||
void decrementObservers();
|
||||
|
||||
signals:
|
||||
void requestArchive(const QString& before);
|
||||
void requestStateChange(bool requesting);
|
||||
void fileDownloadRequest(const QString& url);
|
||||
void unreadMessagesCountChanged();
|
||||
void newMessage(const Shared::Message& msg);
|
||||
void unnoticedMessage(const Shared::Message& msg);
|
||||
|
||||
public:
|
||||
enum MessageRoles {
|
||||
|
@ -140,6 +146,9 @@ private:
|
|||
Progress uploads;
|
||||
Progress downloads;
|
||||
|
||||
std::set<QString>* unreadMessages;
|
||||
uint16_t observersAmount;
|
||||
|
||||
static const QHash<int, QByteArray> roles;
|
||||
};
|
||||
|
||||
|
|
|
@ -448,6 +448,7 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
contact = new Contact(acc, jid, data);
|
||||
connect(contact, &Contact::requestArchive, this, &Roster::onElementRequestArchive);
|
||||
connect(contact, &Contact::fileDownloadRequest, this, &Roster::fileDownloadRequest);
|
||||
connect(contact, &Contact::unnoticedMessage, this, &Roster::unnoticedMessage);
|
||||
contacts.insert(std::make_pair(id, contact));
|
||||
} else {
|
||||
contact = itr->second;
|
||||
|
@ -785,6 +786,7 @@ void Models::Roster::addRoom(const QString& account, const QString jid, const QM
|
|||
Room* room = new Room(acc, jid, data);
|
||||
connect(room, &Contact::requestArchive, this, &Roster::onElementRequestArchive);
|
||||
connect(room, &Contact::fileDownloadRequest, this, &Roster::fileDownloadRequest);
|
||||
connect(room, &Contact::unnoticedMessage, this, &Roster::unnoticedMessage);
|
||||
rooms.insert(std::make_pair(id, room));
|
||||
acc->appendChild(room);
|
||||
}
|
||||
|
|
|
@ -92,6 +92,7 @@ public:
|
|||
signals:
|
||||
void requestArchive(const QString& account, const QString& jid, const QString& before);
|
||||
void fileDownloadRequest(const QString& url);
|
||||
void unnoticedMessage(const QString& account, const Shared::Message& msg);
|
||||
|
||||
private:
|
||||
Element* getElement(const ElId& id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue