Use DesktopNotificationsAllowedRole to check if user is online.

Rename ServerUserStatus to ServerUserStatusRole.

Signed-off-by: Camila <hello@camila.codes>
This commit is contained in:
Camila 2021-04-21 19:04:21 +02:00 committed by Camila (Rebase PR Action)
parent bd65eee278
commit 419595ce5e
6 changed files with 20 additions and 6 deletions

View File

@ -230,6 +230,7 @@ bool AccountState::isDesktopNotificationsAllowed() const
void AccountState::setDesktopNotificationsAllowed(bool isAllowed)
{
_isDesktopNotificationsAllowed = isAllowed;
emit desktopNotificationsAllowedChanged();
}
void AccountState::checkConnectivity()

View File

@ -202,6 +202,7 @@ signals:
void isConnectedChanged();
void hasFetchedNavigationApps();
void statusChanged();
void desktopNotificationsAllowedChanged();
protected Q_SLOTS:
void slotConnectionValidatorResult(ConnectionValidator::Status status, const QStringList &errors);

View File

@ -93,7 +93,7 @@ MenuItem {
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.isDesktopNotificationsAllowed ? qsTr("Current user status is online") : qsTr("Current user status is do not disturb")
}
}

View File

@ -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);
}
@ -745,6 +746,11 @@ void UserModel::addUser(AccountStatePtr &user, const bool &isCurrent)
emit dataChanged(index(row, 0), index(row, 0), {UserModel::StatusIconRole,
UserModel::StatusMessageRole});
});
connect(u, &User::desktopNotificationsAllowedChanged, this, [this, row] {
emit dataChanged(index(row, 0), index(row, 0), {UserModel::DesktopNotificationsAllowedRole});
});
_users << u;
if (isCurrent) {
@ -884,12 +890,14 @@ 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 == ServerUserStatus) {
} else if (role == ServerUserStatusRole) {
return _users[index.row()]->serverHasUserStatus();
} else if (role == StatusIconRole) {
return _users[index.row()]->statusIcon();
} 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) {
@ -907,12 +915,13 @@ QHash<int, QByteArray> UserModel::roleNames() const
QHash<int, QByteArray> roles;
roles[NameRole] = "name";
roles[ServerRole] = "server";
roles[ServerUserStatusRole] = "serverUserStatus";
roles[StatusIconRole] = "statusIcon";
roles[StatusMessageRole] = "statusMessage";
roles[DesktopNotificationsAllowedRole] = "isDesktopNotificationsAllowed";
roles[AvatarRole] = "avatar";
roles[IsCurrentUserRole] = "isCurrentUser";
roles[IsConnectedRole] = "isConnected";
roles[ServerUserStatus] = "serverUserStatus";
roles[IdRole] = "id";
return roles;
}

View File

@ -21,9 +21,10 @@ class User : public QObject
Q_OBJECT
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QString server READ server CONSTANT)
Q_PROPERTY(bool serverHasUserStatus READ serverHasUserStatus)
Q_PROPERTY(QUrl statusIcon READ statusIcon NOTIFY statusChanged)
Q_PROPERTY(QString statusMessage READ statusMessage NOTIFY statusChanged)
Q_PROPERTY(bool serverHasUserStatus READ serverHasUserStatus)
Q_PROPERTY(QString isDesktopNotificationsAllowed READ isDesktopNotificationsAllowed NOTIFY desktopNotificationsAllowedChanged)
Q_PROPERTY(bool hasLocalFolder READ hasLocalFolder NOTIFY hasLocalFolderChanged)
Q_PROPERTY(bool serverHasTalk READ serverHasTalk NOTIFY serverHasTalkChanged)
Q_PROPERTY(QString avatar READ avatarUrl NOTIFY avatarChanged)
@ -65,6 +66,7 @@ signals:
void avatarChanged();
void accountStateChanged(int state);
void statusChanged();
void desktopNotificationsAllowedChanged();
public slots:
void slotItemCompleted(const QString &folder, const SyncFileItemPtr &item);
@ -156,12 +158,13 @@ public:
enum UserRoles {
NameRole = Qt::UserRole + 1,
ServerRole,
ServerUserStatusRole,
StatusIconRole,
StatusMessageRole,
DesktopNotificationsAllowedRole,
AvatarRole,
IsCurrentUserRole,
IsConnectedRole,
ServerUserStatus,
IdRole
};

View File

@ -381,7 +381,7 @@ Window {
sourceSize.height: Style.accountAvatarStateIndicatorSize
Accessible.role: Accessible.Indicator
Accessible.name: UserModel.isUserStatusOnline(UserModel.currentUserId()) ? qsTr("Current user status is online") : qsTr("Current user status is do not disturb")
Accessible.name: UserModel.isDesktopNotificationsAllowed ? qsTr("Current user status is online") : qsTr("Current user status is do not disturb")
}
}