Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb42099-multi-recipient-group' into 'master'
[commhistoryd] Refine group matching when there are multiple recipients. Contributes to JB#42099

See merge request mer-core/commhistory-daemon!27
  • Loading branch information
blam committed Jan 9, 2019
2 parents 9fd71e1 + 08001bb commit 7112419
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
84 changes: 42 additions & 42 deletions src/textchannellistener.cpp
Expand Up @@ -339,20 +339,7 @@ void TextChannelListener::slotGroupInserted(const QModelIndex &index, int start,
DEBUG() << Q_FUNC_INFO << "Account path handled by this listener: " << m_Account->objectPath();
DEBUG() << Q_FUNC_INFO << "Target handled by this listener: " << targetId();

for (int i = start; i <= end; i++) {
QModelIndex row = m_GroupModel->index(i, 0, index);
CommHistory::Group group = m_GroupModel->group(row);

DEBUG() << Q_FUNC_INFO << "Inserted group's account: " << group.localUid();
DEBUG() << Q_FUNC_INFO << "Inserted group's target: " << group.recipients().value(0).remoteUid();

const Recipient recipient(m_Account->objectPath(), targetId());
if (group.isValid() && group.recipients().containsMatch(recipient)) {
DEBUG() << Q_FUNC_INFO << "found listener for group" << group.id();
m_Group = group;
break;
}
}
updateCurrentGroup(start, end, index);
}

void TextChannelListener::slotGroupRemoved(const QModelIndex &index, int start, int end)
Expand Down Expand Up @@ -503,34 +490,7 @@ void TextChannelListener::slotOnModelReady(bool status)
// otherwise add a new group only when a new message(received/sent) comes
const int groupCount = m_GroupModel->rowCount();
if (groupCount > 0 && m_Account) {
const Recipient recipient(m_Account->objectPath(), targetId());
int fallbackRow = -1;
int row = 0;
for ( ; row < groupCount; row++) {
const QModelIndex &index = m_GroupModel->index(row, 0);
const CommHistory::Group &group = m_GroupModel->group(index);
if (group.isValid()) {
const CommHistory::RecipientList &recipients = group.recipients();
if (recipients.count() > 1) {
// This is a multi-member group; prefer to continue searching for an exact match
if (fallbackRow == -1 && recipients.containsMatch(recipient)) {
fallbackRow = row;
}
} else if (recipients.containsMatch(recipient)) {
m_Group = group;
DEBUG() << Q_FUNC_INFO << "found existing group:" << m_Group.id();
break;
}
}
}
if (row == groupCount) {
if (fallbackRow != -1) {
m_Group = m_GroupModel->group(m_GroupModel->index(fallbackRow, 0));
DEBUG() << Q_FUNC_INFO << "found existing multi-member group:" << m_Group.id();
} else {
DEBUG() << Q_FUNC_INFO << "no existing group found for targetId:" << targetId();
}
}
updateCurrentGroup(0, groupCount - 1);
}

channelListenerReady();
Expand Down Expand Up @@ -1468,6 +1428,46 @@ void TextChannelListener::sendGroupChatEvent(const QString &message)
}
}

void TextChannelListener::updateCurrentGroup(int start, int end, const QModelIndex &parent)
{
DEBUG() << __PRETTY_FUNCTION__ << start << end;

const Recipient recipient(m_Account->objectPath(), targetId());
int fallbackRow = -1;
int row = start;
for ( ; row <= end; row++) {
const QModelIndex &index = m_GroupModel->index(row, 0, parent);
const CommHistory::Group &group = m_GroupModel->group(index);

DEBUG() << Q_FUNC_INFO << "Inserted group's account: " << group.localUid();
DEBUG() << Q_FUNC_INFO << "Inserted group's first target: " << group.recipients().value(0).remoteUid();

if (group.isValid()) {
const CommHistory::RecipientList &recipients = group.recipients();
if (recipients.count() > 1) {
DEBUG() << Q_FUNC_INFO << "has multiple recipients" << recipients.count();
// This is a multi-member group; prefer to continue searching for an exact match
if (fallbackRow == -1 && recipients.containsMatch(recipient)) {
DEBUG() << Q_FUNC_INFO << "set fallbackRow" << fallbackRow;
fallbackRow = row;
}
} else if (recipients.containsMatch(recipient)) {
m_Group = group;
DEBUG() << Q_FUNC_INFO << "found existing group:" << m_Group.id();
break;
}
}
}
if (row == end) {
if (fallbackRow != -1) {
m_Group = m_GroupModel->group(m_GroupModel->index(fallbackRow, 0));
DEBUG() << Q_FUNC_INFO << "found existing multi-member group:" << m_Group.id();
} else {
DEBUG() << Q_FUNC_INFO << "no existing group found for targetId:" << targetId();
}
}
}

void TextChannelListener::slotEventsCommitted(QList<CommHistory::Event> events, bool status)
{
DEBUG() << Q_FUNC_INFO << status;
Expand Down
1 change: 1 addition & 0 deletions src/textchannellistener.h
Expand Up @@ -147,6 +147,7 @@ private Q_SLOTS:
const CommHistory::Event &event);
void sendGroupChatEvent(const QString &message);
void showErrorNote(const QString &errorMsg, const QString &category = ErrorCategory);
void updateCurrentGroup(int start, int end, const QModelIndex &parent = QModelIndex());

// attempt to read original message from delivery report
bool recoverDeliveryEcho(const Tp::Message &message, CommHistory::Event &event);
Expand Down

0 comments on commit 7112419

Please sign in to comment.