Skip to content

Commit

Permalink
Merge pull request #3182 from nextcloud/bugfix/user-status
Browse files Browse the repository at this point in the history
Bugfix/user status
  • Loading branch information
Camila authored May 25, 2021
2 parents c684191 + f758157 commit 5d2cfd8
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 126 deletions.
10 changes: 10 additions & 0 deletions src/gui/accountstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ QUrl AccountState::statusIcon() const
return _userStatus->icon();
}

QString AccountState::statusEmoji() const
{
return _userStatus->emoji();
}

QString AccountState::stateString(State state)
{
switch (state) {
Expand Down Expand Up @@ -229,7 +234,12 @@ bool AccountState::isDesktopNotificationsAllowed() const

void AccountState::setDesktopNotificationsAllowed(bool isAllowed)
{
if (_isDesktopNotificationsAllowed == isAllowed) {
return;
}

_isDesktopNotificationsAllowed = isAllowed;
emit desktopNotificationsAllowedChanged();
}

void AccountState::checkConnectivity()
Expand Down
7 changes: 6 additions & 1 deletion src/gui/accountstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,17 @@ class AccountState : public QObject, public QSharedData
*/
UserStatus::Status status() const;

/** Returns the user status Message (emoji + text)
/** Returns the user status Message (text)
*/
QString statusMessage() const;

/** Returns the user status icon url
*/
QUrl statusIcon() const;

/** Returns the user status emoji
*/
QString statusEmoji() const;

/** Returns the notifications status retrieved by the notificatons endpoint
* https://github.com/nextcloud/desktop/issues/2318#issuecomment-680698429
Expand Down Expand Up @@ -202,6 +206,7 @@ public slots:
void isConnectedChanged();
void hasFetchedNavigationApps();
void statusChanged();
void desktopNotificationsAllowedChanged();

protected Q_SLOTS:
void slotConnectionValidatorResult(ConnectionValidator::Status status, const QStringList &errors);
Expand Down
62 changes: 45 additions & 17 deletions src/gui/tray/UserLine.qml
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ MenuItem {
spacing: 0
Image {
id: accountAvatar
Layout.leftMargin: 4
Layout.leftMargin: 7
verticalAlignment: Qt.AlignCenter
cache: false
source: model.avatar != "" ? model.avatar : "image://avatars/fallbackBlack"
Layout.preferredHeight: (userLineLayout.height -16)
Layout.preferredWidth: (userLineLayout.height -16)
Layout.preferredHeight: Style.accountAvatarSize
Layout.preferredWidth: Style.accountAvatarSize
Rectangle {
id: accountStatusIndicatorBackground
visible: model.isConnected &&
model.serverHasUserStatus
width: accountStatusIndicator.sourceSize.width + 2
height: width
anchors.bottom: accountAvatar.bottom
Expand All @@ -81,47 +83,73 @@ MenuItem {
}
Image {
id: accountStatusIndicator
source: model.statusIcon
visible: model.isConnected &&
model.serverHasUserStatus
source: model.statusIcon
cache: false
x: accountStatusIndicatorBackground.x + 1
y: accountStatusIndicatorBackground.y + 1
sourceSize.width: Style.accountAvatarStateIndicatorSize
sourceSize.height: Style.accountAvatarStateIndicatorSize

Accessible.role: Accessible.Indicator
Accessible.name: model.isStatusOnline ? qsTr("Current user status is online") : qsTr("Current user status is do not disturb")
Accessible.name: model.desktopNotificationsAllowed ? qsTr("Current user status is online") : qsTr("Current user status is do not disturb")
}
}

Column {
id: accountLabels
spacing: 4
spacing: Style.accountLabelsSpacing
Layout.alignment: Qt.AlignLeft
Layout.leftMargin: 6
Layout.leftMargin: Style.accountLabelsLayoutMargin
anchors.top: accountAvatar.top
anchors.topMargin: Style.userStatusAnchorsMargin
anchors.left: accountAvatar.right
anchors.leftMargin: Style.accountLabelsAnchorsMargin
Label {
id: accountUser
width: 128
text: name
elide: Text.ElideRight
color: "black"
font.pixelSize: 12
font.pixelSize: Style.topLinePixelSize
font.bold: true
}
Label {
id: userStatusMessage
width: 128
text: statusMessage
elide: Text.ElideRight
color: "black"
font.pixelSize: 10
Row {
id: userStatus
visible: model.isConnected &&
model.serverHasUserStatus
anchors.top: accountUser.bottom
Label {
id: emoji
visible: model.statusEmoji !== ""
width: Style.userStatusEmojiSize
text: statusEmoji
}
Label {
id: message
anchors.bottom: emoji.bottom
anchors.left: emoji.right
anchors.leftMargin: emoji.width + Style.userStatusSpacing
visible: model.statusMessage !== ""
width: Style.currentAccountLabelWidth
text: statusMessage
elide: Text.ElideRight
color: "black"
font.pixelSize: Style.subLinePixelSize
}
}
Label {
id: accountServer
width: 128
anchors.top: userStatus.bottom
anchors.topMargin: message.visible
? message.height + Style.accountServerAnchorsMargin
: Style.userStatusAnchorsMargin
width: Style.currentAccountLabelWidth
text: server
elide: Text.ElideRight
color: "black"
font.pixelSize: 10
font.pixelSize: Style.subLinePixelSize
}
}
}
Expand Down
71 changes: 30 additions & 41 deletions src/gui/tray/UserModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ User::User(AccountStatePtr &account, const bool &isCurrent, QObject *parent)

connect(_account->account().data(), &Account::accountChangedAvatar, this, &User::avatarChanged);
connect(_account.data(), &AccountState::statusChanged, this, &User::statusChanged);
connect(_account.data(), &AccountState::desktopNotificationsAllowedChanged, this, &User::desktopNotificationsAllowedChanged);

connect(_activityModel, &ActivityListModel::sendNotificationRequest, this, &User::slotSendNotificationRequest);
}
Expand Down Expand Up @@ -214,7 +215,6 @@ void User::slotRefreshActivities()

void User::slotRefreshUserStatus()
{
// TODO: check for _account->account()->capabilities().userStatus()
if (_account.data() && _account.data()->isConnected()) {
_account.data()->fetchUserStatus();
}
Expand Down Expand Up @@ -576,6 +576,16 @@ QUrl User::statusIcon() const
return _account->statusIcon();
}

QString User::statusEmoji() const
{
return _account->statusEmoji();
}

bool User::serverHasUserStatus() const
{
return _account->account()->capabilities().userStatus();
}

QImage User::avatar() const
{
return AvatarJob::makeCircularAvatar(_account->account()->avatar());
Expand Down Expand Up @@ -669,7 +679,6 @@ void UserModel::buildUserList()
}
if (_init) {
_users.first()->setCurrentUser(true);
connect(_users.first(), &User::accountStateChanged, this, &UserModel::refreshCurrentUserGui);
_init = false;
}
}
Expand All @@ -692,16 +701,6 @@ Q_INVOKABLE bool UserModel::isUserConnected(const int &id)
return _users[id]->isConnected();
}

Q_INVOKABLE QUrl UserModel::statusIcon(int id)
{
if (id < 0 || id >= _users.size()) {
return {};
}

return _users[id]->statusIcon();
}


QImage UserModel::avatarById(const int &id)
{
if (id < 0 || id >= _users.size())
Expand Down Expand Up @@ -740,13 +739,21 @@ void UserModel::addUser(AccountStatePtr &user, const bool &isCurrent)

connect(u, &User::statusChanged, this, [this, row] {
emit dataChanged(index(row, 0), index(row, 0), {UserModel::StatusIconRole,
UserModel::StatusEmojiRole,
UserModel::StatusMessageRole});
});

connect(u, &User::desktopNotificationsAllowedChanged, this, [this, row] {
emit dataChanged(index(row, 0), index(row, 0), { UserModel::DesktopNotificationsAllowedRole });
});

connect(u, &User::accountStateChanged, this, [this, row] {
emit dataChanged(index(row, 0), index(row, 0), { UserModel::IsConnectedRole });
});

_users << u;
if (isCurrent) {
_currentUserId = _users.indexOf(_users.last());
connect(u, &User::accountStateChanged, this, &UserModel::refreshCurrentUserGui);
}

endInsertRows();
Expand Down Expand Up @@ -799,13 +806,10 @@ Q_INVOKABLE void UserModel::switchCurrentUser(const int &id)
{
if (_currentUserId < 0 || _currentUserId >= _users.size())
return;

disconnect(_users[_currentUserId], &User::accountStateChanged, this, &UserModel::refreshCurrentUserGui);

_users[_currentUserId]->setCurrentUser(false);
_users[id]->setCurrentUser(true);
connect(_users[id], &User::accountStateChanged, this, &UserModel::refreshCurrentUserGui);
_currentUserId = id;
emit refreshCurrentUserGui();
emit newUserSelected();
}

Expand All @@ -815,7 +819,6 @@ Q_INVOKABLE void UserModel::login(const int &id)
return;

_users[id]->login();
emit refreshCurrentUserGui();
}

Q_INVOKABLE void UserModel::logout(const int &id)
Expand All @@ -824,7 +827,6 @@ Q_INVOKABLE void UserModel::logout(const int &id)
return;

_users[id]->logout();
emit refreshCurrentUserGui();
}

Q_INVOKABLE void UserModel::removeAccount(const int &id)
Expand All @@ -847,10 +849,6 @@ Q_INVOKABLE void UserModel::removeAccount(const int &id)
return;
}

if (_users[id]->isCurrentUser()) {
disconnect(_users[id], &User::accountStateChanged, this, &UserModel::refreshCurrentUserGui);
}

if (_users[id]->isCurrentUser() && _users.count() > 1) {
id == 0 ? switchCurrentUser(1) : switchCurrentUser(0);
}
Expand All @@ -861,8 +859,6 @@ Q_INVOKABLE void UserModel::removeAccount(const int &id)
beginRemoveRows(QModelIndex(), id, id);
_users.removeAt(id);
endRemoveRows();

emit refreshCurrentUserGui();
}

int UserModel::rowCount(const QModelIndex &parent) const
Expand All @@ -881,10 +877,16 @@ QVariant UserModel::data(const QModelIndex &index, int role) const
return _users[index.row()]->name();
} else if (role == ServerRole) {
return _users[index.row()]->server();
} else if (role == ServerHasUserStatusRole) {
return _users[index.row()]->serverHasUserStatus();
} else if (role == StatusIconRole) {
return _users[index.row()]->statusIcon();
} else if (role == StatusEmojiRole) {
return _users[index.row()]->statusEmoji();
} else if (role == StatusMessageRole) {
return _users[index.row()]->statusMessage();
} else if (role == DesktopNotificationsAllowedRole) {
return _users[index.row()]->isDesktopNotificationsAllowed();
} else if (role == AvatarRole) {
return _users[index.row()]->avatarUrl();
} else if (role == IsCurrentUserRole) {
Expand All @@ -902,8 +904,11 @@ QHash<int, QByteArray> UserModel::roleNames() const
QHash<int, QByteArray> roles;
roles[NameRole] = "name";
roles[ServerRole] = "server";
roles[ServerHasUserStatusRole] = "serverHasUserStatus";
roles[StatusIconRole] = "statusIcon";
roles[StatusEmojiRole] = "statusEmoji";
roles[StatusMessageRole] = "statusMessage";
roles[DesktopNotificationsAllowedRole] = "desktopNotificationsAllowed";
roles[AvatarRole] = "avatar";
roles[IsCurrentUserRole] = "isCurrentUser";
roles[IsConnectedRole] = "isConnected";
Expand All @@ -919,22 +924,6 @@ ActivityListModel *UserModel::currentActivityModel()
return _users[currentUserIndex()]->getActivityModel();
}

bool UserModel::currentUserHasActivities()
{
if (currentUserIndex() < 0 || currentUserIndex() >= _users.size())
return false;

return _users[currentUserIndex()]->hasActivities();
}

bool UserModel::currentUserHasLocalFolder()
{
if (currentUserIndex() < 0 || currentUserIndex() >= _users.size())
return false;

return _users[currentUserIndex()]->getFolder() != nullptr;
}

void UserModel::fetchCurrentActivityModel()
{
if (currentUserId() < 0 || currentUserId() >= _users.size())
Expand Down
Loading

0 comments on commit 5d2cfd8

Please sign in to comment.