Show a notification for invited rooms
This commit is contained in:
@@ -122,3 +122,8 @@ Comment[uk]=Надійшло нове повідомлення
|
||||
Comment[x-test]=xxThere is a new messagexx
|
||||
Comment[zh_CN]=有新消息
|
||||
Action=Popup
|
||||
|
||||
[Event/invite]
|
||||
Name=New Invite
|
||||
Comment=There is a new invite to a room
|
||||
Action=Popup
|
||||
|
||||
@@ -58,6 +58,21 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
|
||||
}
|
||||
});
|
||||
connect(this, &Room::displaynameChanged, this, &NeoChatRoom::displayNameChanged);
|
||||
|
||||
connectSingleShot(this, &Room::baseStateLoaded, this, [this]() {
|
||||
if (this->joinState() != JoinState::Invite) {
|
||||
return;
|
||||
}
|
||||
const QString senderId = getCurrentState<RoomMemberEvent>(localUser()->id())->senderId();
|
||||
QImage avatar_image;
|
||||
if (!user(senderId)->avatarUrl(this).isEmpty()) {
|
||||
avatar_image = user(senderId)->avatar(128, this);
|
||||
} else {
|
||||
qWarning() << "using this room's avatar";
|
||||
avatar_image = avatar(128);
|
||||
}
|
||||
NotificationsManager::instance().postInviteNotification(this, htmlSafeDisplayName(), htmlSafeMemberName(senderId), avatar_image);
|
||||
});
|
||||
}
|
||||
|
||||
void NeoChatRoom::uploadFile(const QUrl &url, const QString &body)
|
||||
|
||||
@@ -71,3 +71,30 @@ void NotificationsManager::postNotification(NeoChatRoom *room,
|
||||
|
||||
m_notifications.insert(room->id(), notification);
|
||||
}
|
||||
|
||||
void NotificationsManager::postInviteNotification(NeoChatRoom *room, const QString &title, const QString &sender, const QImage &icon)
|
||||
{
|
||||
if (!NeoChatConfig::self()->showNotifications()) {
|
||||
return;
|
||||
}
|
||||
QPixmap img;
|
||||
img.convertFromImage(icon);
|
||||
KNotification *notification = new KNotification("invite");
|
||||
notification->setText(i18n("%1 invited you to a room", sender));
|
||||
notification->setTitle(title);
|
||||
notification->setPixmap(img);
|
||||
notification->setDefaultAction(i18n("Open this invite in NeoChat"));
|
||||
connect(notification, &KNotification::defaultActivated, this, [=]() {
|
||||
RoomManager::instance().enterRoom(room);
|
||||
Q_EMIT Controller::instance().showWindow();
|
||||
});
|
||||
notification->setActions({i18n("Accept Invite"), i18n("Reject Invite")});
|
||||
connect(notification, &KNotification::action1Activated, this, [room]() {
|
||||
room->acceptInvitation();
|
||||
});
|
||||
connect(notification, &KNotification::action2Activated, this, [room]() {
|
||||
RoomManager::instance().leaveRoom(room);
|
||||
});
|
||||
notification->sendEvent();
|
||||
m_notifications.insert(room->id(), notification);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
|
||||
Q_INVOKABLE void
|
||||
postNotification(NeoChatRoom *room, const QString &roomName, const QString &sender, const QString &text, const QImage &icon, const QString &replyEventId);
|
||||
void postInviteNotification(NeoChatRoom *room, const QString &title, const QString &sender, const QImage &icon);
|
||||
|
||||
private:
|
||||
NotificationsManager(QObject *parent = nullptr);
|
||||
|
||||
Reference in New Issue
Block a user