Commit 55cd2d71 authored by Lasath Fernando's avatar Lasath Fernando Committed by David Edmundson
Browse files

Fixed a bug with ConversationsModel where it wasn't actually setting the...

Fixed a bug with ConversationsModel where it wasn't actually setting the textChannel on revalidated chats.
Fixed a bug with MessagesModel where signals weren't getting set up properly when textChannel was changed.
parent 4cb7a675
......@@ -59,21 +59,25 @@ ConversationsModel::ConversationsModel() :
void ConversationsModel::onInconmingConversation ( Conversation* newConvo )
{
bool found = false;
//check if conversation's channel is already being handled, if so replace it
bool handled = false;
Tp::TextChannelPtr newChannel = newConvo->model()->textChannel();
if (!newChannel->targetHandleType() == Tp::HandleTypeNone) {
//loop through all tabs checking for matches
//loop through all conversations checking for matches
Q_FOREACH(Conversation *convo, d->conversations) {
if (convo->target()->id() == newChannel->targetId()
&& convo->model()->textChannel()->targetHandleType() == newChannel->targetHandleType()) {
found = true;
if (convo->target()->id() == newChannel->targetId() &&
convo->model()->textChannel()->targetHandleType() == newChannel->targetHandleType()) {
convo->model()->setTextChannel(newChannel);
newConvo->deleteLater();
handled = true;
break;
}
}
}
if(!found) {
if(!handled) {
beginInsertRows(QModelIndex(), rowCount(), rowCount());
d->conversations.append(newConvo);
endInsertRows();
......
......@@ -99,19 +99,18 @@ void MessagesModel::setTextChannel(Tp::TextChannelPtr channel)
setupChannelSignals(channel);
if (d->textChannel) {
removeChannelSignals(channel);
removeChannelSignals(d->textChannel);
}
//FIXME: check messageQue for any lost messages
d->textChannel = channel;
Q_EMIT textChannelChanged(channel);
d->textChannel = channel;
Q_EMIT textChannelChanged(d->textChannel);
QList<Tp::ReceivedMessage> queue
= channel->messageQueue();
Q_FOREACH(Tp::ReceivedMessage message, queue
) {
QList<Tp::ReceivedMessage> messageQueue = channel->messageQueue();
Q_FOREACH(Tp::ReceivedMessage message, messageQueue) {
bool messageAlreadyInModel = false;
Q_FOREACH(MessageItem current, d->messages) {
//FIXME: docs say messageToken can return an empty string. What to do if that happens?
//Tp::Message has an == operator. maybe I can use that?
if (current.id == message.messageToken()) {
messageAlreadyInModel = true;
}
......@@ -127,6 +126,7 @@ void MessagesModel::onMessageReceived(Tp::ReceivedMessage message)
int unreadCount = d->textChannel->messageQueue().size();
kDebug() << "unreadMessagesCount =" << unreadCount;
kDebug() << "text =" << message.text();
kDebug() << "messageToken =" << message.messageToken();
if (message.messageType() == Tp::ChannelTextMessageTypeNormal) {
int length = rowCount();
......@@ -287,9 +287,8 @@ void MessagesModel::printallmessages()
kDebug() << msg.text;
}
beginResetModel();
d->messages.clear();
// d->messages.clear();
endResetModel();
}
#include "moc_messages-model.cpp"
// kate: indent-mode cstyle; space-indent on; indent-width 4; replace-tabs on;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment