~phablet-team/telephony-service/qml-start-chat

« back to all changes in this revision

Viewing changes to libtelephonyservice/chatentry.cpp

merge parent

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
 
166
166
void ChatEntry::onRolesChanged(const HandleRolesMap &added, const HandleRolesMap &removed)
167
167
{
168
 
    Q_UNUSED(added);
169
 
    Q_UNUSED(removed);
170
 
 
171
 
    RolesMap rolesMap;
172
168
    Tp::TextChannel* channel = 0;
173
169
    if (rolesInterface) {
174
 
        rolesMap = rolesInterface->getRoles();
 
170
        if (mRolesMap.isEmpty()) {
 
171
            mRolesMap = rolesInterface->getRoles();
 
172
        }
175
173
        channel = qvariant_cast<Tp::TextChannel*>(rolesInterface->property("channel"));
176
174
    }
177
175
 
 
176
    QMapIterator<uint, uint> it(removed);
 
177
    while (it.hasNext()) {
 
178
        it.next();
 
179
        mRolesMap.remove(it.key());
 
180
    }
 
181
 
 
182
    QMapIterator<uint, uint> it2(added);
 
183
    while (it2.hasNext()) {
 
184
        it2.next();
 
185
        mRolesMap[it2.key()] = it2.value();
 
186
    }
 
187
 
 
188
    // TODO avoid iterating over all participants when not needed
178
189
    Q_FOREACH(Participant* participant, mParticipants) {
179
 
        if (rolesMap.contains(participant->handle())) {
180
 
            participant->setRoles(rolesMap[participant->handle()]);
 
190
        if (mRolesMap.contains(participant->handle())) {
 
191
            participant->setRoles(mRolesMap[participant->handle()]);
181
192
        }
182
193
    }
183
194
 
184
195
    Q_FOREACH(Participant* participant, mLocalPendingParticipants) {
185
 
        if (rolesMap.contains(participant->handle())) {
186
 
            participant->setRoles(rolesMap[participant->handle()]);
 
196
        if (mRolesMap.contains(participant->handle())) {
 
197
            participant->setRoles(mRolesMap[participant->handle()]);
187
198
        }
188
199
    }
189
200
 
190
201
    Q_FOREACH(Participant* participant, mRemotePendingParticipants) {
191
 
        if (rolesMap.contains(participant->handle())) {
192
 
            participant->setRoles(rolesMap[participant->handle()]);
 
202
        if (mRolesMap.contains(participant->handle())) {
 
203
            participant->setRoles(mRolesMap[participant->handle()]);
193
204
        }
194
205
    }
195
206
 
202
213
        return;
203
214
    }
204
215
 
205
 
    mSelfContactRoles = rolesMap[selfContact->handle().at(0)];
 
216
    mSelfContactRoles = mRolesMap[selfContact->handle().at(0)];
206
217
    Q_EMIT selfContactRolesChanged();
207
218
}
208
219
 
685
696
        }
686
697
    }
687
698
 
688
 
    RolesMap rolesMap;
689
 
    if (rolesInterface) {
690
 
        rolesMap = rolesInterface->getRoles();
 
699
    if (rolesInterface && mRolesMap.isEmpty()) {
 
700
        mRolesMap = rolesInterface->getRoles();
691
701
    }
692
702
    // now add the new participants
693
703
    // FIXME: check for duplicates?
694
704
    Q_FOREACH(Tp::ContactPtr contact, added) {
695
705
        uint handle = contact->handle().at(0);
696
 
        list << new Participant(contact->id(), rolesMap[handle], handle, this);
 
706
        list << new Participant(contact->id(), mRolesMap[handle], handle, this);
697
707
    }
698
708
}
699
709