Skip to content

Commit

Permalink
MEM::isUserActivityNotable: watch out for stateKey, not only sender
Browse files Browse the repository at this point in the history
If the base event is a state event, we consider stateKey instead of
sender; and we also check other state events' stateKey rather than
sender. This covers cases like kicking and (non-self-)banning. Closes
#248.
  • Loading branch information
KitsuneRal committed Aug 7, 2018
1 parent f3b13f6 commit c0e387a
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions client/models/messageeventmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,17 @@ QString MessageEventModel::renderDate(QDateTime timestamp) const
}

bool MessageEventModel::isUserActivityNotable(
const QMatrixClient::Room::rev_iter_t& baseIt) const
const QuaternionRoom::rev_iter_t& baseIt) const
{
const auto& senderId = (*baseIt)->senderId();
const auto& userId = (*baseIt)->isStateEvent()
? (*baseIt)->stateKey() : (*baseIt)->senderId();

// TODO: Go up and down the timeline (limit to 100 events for
// the sake of performance) and collect all messages of
// this author; find out if there's anything besides joins, leaves
// and redactions; if not, double-check whether the current event is
// a part of a re-join without following redactions.
// Go up to the nearest join and down to the nearest leave of this author
// (limit the lookup to 100 events for the sake of performance);
// in this range find out if there's any event from that user besides
// joins, leaves and redacted (self- or by somebody else); if there's not,
// double-check that there are no redactions and that it's not a single
// join or leave.

using namespace QMatrixClient;
bool joinFound = false, redactionsFound = false;
Expand All @@ -297,7 +299,7 @@ bool MessageEventModel::isUserActivityNotable(
it != limit; ++it)
{
const auto& e = **it;
if (e.senderId() != senderId)
if (e.senderId() != userId && e.stateKey() != userId)
continue;

if (e.isRedacted())
Expand All @@ -306,14 +308,15 @@ bool MessageEventModel::isUserActivityNotable(
continue;
}

if (auto* me = it->viewAs<QMatrixClient::RoomMemberEvent>())
if (auto* me = it->viewAs<RoomMemberEvent>())
{
if (me->isJoin())
{
joinFound = true;
break;
}
continue;
if (e.stateKey() != userId)
return true; // An action on another member is notable
if (!me->isJoin())
continue;

joinFound = true;
break;
}
return true; // Consider all other events notable
}
Expand All @@ -327,7 +330,7 @@ bool MessageEventModel::isUserActivityNotable(
it != limit; ++it)
{
const auto& e = **it;
if (e.senderId() != senderId)
if (e.senderId() != userId && e.stateKey() != userId)
continue;

if (e.isRedacted())
Expand All @@ -338,12 +341,13 @@ bool MessageEventModel::isUserActivityNotable(

if (auto* me = it->viewAs<RoomMemberEvent>())
{
if (me->isLeave() || me->membership() == MembershipType::Ban)
{
leaveFound = true;
break;
}
continue;
if (e.stateKey() != userId)
return true; // An action on another member is notable
if (!me->isLeave() && me->membership() != MembershipType::Ban)
continue;

leaveFound = true;
break;
}
return true;
}
Expand Down Expand Up @@ -613,6 +617,7 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const
if (memberEvent || evt.isRedacted())
{
if (evt.senderId() != m_currentRoom->localUser()->id() &&
evt.stateKey() != m_currentRoom->localUser()->id() &&
!Settings().value("UI/show_spammy").toBool())
{
// QElapsedTimer et; et.start();
Expand Down

0 comments on commit c0e387a

Please sign in to comment.