Verified Commit dc078cb1 authored by Linus Jahn's avatar Linus Jahn Committed by Jonah Brüchert

RosterItem: Refactor compare operators and add displayName()

parent eadd942a
......@@ -85,6 +85,11 @@ void RosterItem::setLastMessage(const QString &lastMessage)
m_lastMessage = lastMessage;
}
QString RosterItem::displayName() const
{
return m_name.isEmpty() ? m_jid : m_name;
}
bool RosterItem::operator==(const RosterItem &other) const
{
return m_jid == other.jid() &&
......@@ -103,24 +108,26 @@ bool RosterItem::operator<(const RosterItem &other) const
{
if (lastExchanged() != other.lastExchanged())
return lastExchanged() > other.lastExchanged();
return (name().isEmpty() ? jid().toUpper() : name().toUpper()) <
(other.name().isEmpty() ? other.jid().toUpper() : other.name().toUpper());
return displayName().toUpper() < other.displayName().toUpper();
}
bool RosterItem::operator>(const RosterItem &other) const
{
if (lastExchanged() != other.lastExchanged())
return lastExchanged() < other.lastExchanged();
return (name().isEmpty() ? jid().toUpper() : name().toUpper()) >
(other.name().isEmpty() ? other.jid().toUpper() : other.name().toUpper());
return displayName().toUpper() > other.displayName().toUpper();
}
bool RosterItem::operator<=(const RosterItem &other) const
{
return operator<(other) || operator==(other);
if (lastExchanged() != other.lastExchanged())
return lastExchanged() >= other.lastExchanged();
return displayName().toUpper() <= other.displayName().toUpper();
}
bool RosterItem::operator>=(const RosterItem &other) const
{
return operator>(other) || operator==(other);
if (lastExchanged() != other.lastExchanged())
return lastExchanged() <= other.lastExchanged();
return displayName().toUpper() >= other.displayName().toUpper();
}
......@@ -58,6 +58,8 @@ public:
QString lastMessage() const;
void setLastMessage(const QString &lastMessage);
QString displayName() const;
bool operator==(const RosterItem &other) const;
bool operator!=(const RosterItem &other) const;
......
Markdown is supported
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