/*!
 * This function will be called before the first testfunction is executed.
 */
void Ut_MessageReviver::initTestCase()
{
    groupModel.enableContactChanges(false);
    CommHistory::Group group;
    group.setLocalUid(ACCOUNT_PATH);
    group.setRemoteUids(QStringList() << NUMBER);
    groupModel.addGroup(group);

    CommHistory::EventModel model;

    QSignalSpy commit(&model,
                      SIGNAL(eventsCommitted(const QList<CommHistory::Event>&, bool)));
    CommHistory::Event event;
    event.setType(CommHistory::Event::SMSEvent);
    event.setDirection(CommHistory::Event::Inbound);
    event.setStartTime(QDateTime::currentDateTime());
    event.setEndTime(QDateTime::currentDateTime());
    event.setLocalUid(ACCOUNT_PATH);
    event.setGroupId(group.id());
    event.setRemoteUid(NUMBER);
    event.setFreeText("blah");
    event.setMessageToken("mrtc1");
    model.addEvent(event, false);
    waitSignal(commit, 5000);
}
ConversationChannel *GroupManager::getConversation(const QString &localUid, const QString &remoteUid, bool create)
{
    CommHistory::Group group = groupFromUid(localUid, remoteUid);
    if (group.isValid())
        return getConversationById(group.id());
    if (!create)
        return 0;

    qDebug() << "ConversationChannel creating group for" << localUid << remoteUid;
    group.setLocalUid(localUid);
    group.setRemoteUids(QStringList() << remoteUid);
    group.setChatType(CommHistory::Group::ChatTypeP2P);
    if (!mGroupModel->addGroup(group)) {
        qWarning() << "ConversationChannel failed creating group" << localUid << remoteUid;
        return 0;
    }
    Q_ASSERT(group.isValid());

    ConversationChannel *c = new ConversationChannel(this);
    c->setupGroup(group);
    addGroup(group.id(), c);
    return c;
}