Adapt to power level changes in room version 12
This commit is contained in:
committed by
Tobias Fella
parent
24e43d063a
commit
aa40fc84ea
@@ -536,6 +536,9 @@ bool NeoChatRoom::containsUser(const QString &userID) const
|
||||
|
||||
bool NeoChatRoom::canSendEvent(const QString &eventType) const
|
||||
{
|
||||
if (roomCreatorHasUltimatePowerLevel() && isCreator(localMember().id())) {
|
||||
return true;
|
||||
}
|
||||
auto plEvent = currentState().get<RoomPowerLevelsEvent>();
|
||||
if (!plEvent) {
|
||||
return false;
|
||||
@@ -548,6 +551,9 @@ bool NeoChatRoom::canSendEvent(const QString &eventType) const
|
||||
|
||||
bool NeoChatRoom::canSendState(const QString &eventType) const
|
||||
{
|
||||
if (roomCreatorHasUltimatePowerLevel() && isCreator(localMember().id())) {
|
||||
return true;
|
||||
}
|
||||
auto plEvent = currentState().get<RoomPowerLevelsEvent>();
|
||||
if (!plEvent) {
|
||||
return false;
|
||||
@@ -1741,4 +1747,20 @@ void NeoChatRoom::setHiddenFilter(std::function<bool(const Quotient::RoomEvent *
|
||||
NeoChatRoom::m_hiddenFilter = hiddenFilter;
|
||||
}
|
||||
|
||||
bool NeoChatRoom::roomCreatorHasUltimatePowerLevel() const
|
||||
{
|
||||
bool ok = false;
|
||||
auto version = this->version().toInt(&ok);
|
||||
// This is terrible. For non-numeric room versions, I don't think there's a way of knowing whether they're pre- or post hydra.
|
||||
// We just assume they are. Shouldn't matter for normal users anyway.
|
||||
return !ok || version > 11;
|
||||
}
|
||||
|
||||
bool NeoChatRoom::isCreator(const QString &userId) const
|
||||
{
|
||||
auto createEvent = currentState().get<RoomCreateEvent>();
|
||||
return roomCreatorHasUltimatePowerLevel() && createEvent
|
||||
&& (createEvent->senderId() == userId || createEvent->contentPart<QStringList>(u"additional_creators"_s).contains(userId));
|
||||
}
|
||||
|
||||
#include "moc_neochatroom.cpp"
|
||||
|
||||
Reference in New Issue
Block a user