Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an Away Status to Contacts #211 #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/core/ContactUser.cpp
Expand Up @@ -347,6 +347,11 @@ void ContactUser::requestRemoved()
}
}

void ContactUser::setAway() {
m_status = Away;
emit statusChanged();
}

void ContactUser::assignConnection(Protocol::Connection *connection)
{
if (connection == m_connection) {
Expand Down
4 changes: 3 additions & 1 deletion src/core/ContactUser.h
Expand Up @@ -80,7 +80,8 @@ class ContactUser : public QObject
Offline,
RequestPending,
RequestRejected,
Outdated
Outdated,
Away
};

UserIdentity * const identity;
Expand Down Expand Up @@ -131,6 +132,7 @@ public slots:
void setHostname(const QString &hostname);

void updateStatus();
void setAway();

signals:
void statusChanged();
Expand Down
16 changes: 14 additions & 2 deletions src/core/ConversationModel.cpp
Expand Up @@ -277,14 +277,26 @@ QVariant ConversationModel::data(const QModelIndex &index, int role) const
const MessageData &message = messages[index.row()];

switch (role) {
case Qt::DisplayRole: return message.text;
case Qt::DisplayRole:
if(message.status == Received) {
if (message.text.startsWith(QLatin1String("/away"))) {
m_contact->setAway();
} else if (message.text.startsWith(QLatin1String("/back"))) {
m_contact->updateStatus();
}
}
return message.text;
case TimestampRole: return message.time;
case IsOutgoingRole: return message.status != Received;
case StatusRole: return message.status;

case SectionRole: {
if (m_contact->status() == ContactUser::Online)
if (m_contact->status() == ContactUser::Online) {
return QString();
}
if (m_contact->status() == ContactUser::Away) {
return QStringLiteral("away");
}
if (index.row() < messages.size() - 1) {
const MessageData &next = messages[index.row()+1];
if (next.status != Received && next.status != Delivered)
Expand Down
18 changes: 16 additions & 2 deletions src/ui/qml/MessageDelegate.qml
Expand Up @@ -24,6 +24,8 @@ Column {
text: {
if (model.section === "offline")
return qsTr("%1 is offline").arg(contact !== null ? contact.nickname : "")
else if (model.section === "away")
return qsTr("%1 is away").arg(contact !== null ? contact.nickname : "")
else
return Qt.formatDateTime(model.timestamp, Qt.DefaultLocaleShortDate)
}
Expand Down Expand Up @@ -103,8 +105,20 @@ Column {
wrapMode: TextEdit.Wrap
readOnly: true
selectByMouse: true
text: LinkedText.parsed(model.text)

text: {
if(model.isOutgoing) {
if(model.text === "/away")
return qsTr("You are now <b>Away</b> to %1").arg(contact !== null ? contact.nickname : "");
else if(model.text === "/back")
return qsTr("You are now <b>Online</b> to %1").arg(contact !== null ? contact.nickname : "");
} else {
if(model.text === "/away")
return qsTr("%1 is <b>away</b>").arg(contact !== null ? contact.nickname : "");
else if(model.text === "/back")
return qsTr("%1 has <b>returned</b>").arg(contact !== null ? contact.nickname : "");
}
return LinkedText.parsed(model.text)
}
onLinkActivated: {
textField.deselect()
delegate.showContextMenu(link)
Expand Down
2 changes: 2 additions & 0 deletions src/ui/qml/PresenceIcon.qml
Expand Up @@ -12,6 +12,8 @@ Rectangle {
onStatusChanged: {
if (status === ContactUser.Online)
color = "#3EBB4F"
else if (status === ContactUser.Away)
color = "#EEEE44"
else
color = "#999999"
}
Expand Down