TEST(chatpresenter, test_incomingMessages)
{
    Poco::SharedPtr<MockChatService> m(new MockChatService);

    Mvp::Presenter::TextChatPresenter presenter(m.get());
    Poco::SharedPtr<MockChatView> v(new MockChatView());
    EXPECT_CALL(*v, initialize());

    ON_CALL(*m, getParticipants())
        .WillByDefault(Return(contacts));
    ON_CALL(*m, messageHistory(_))
        .WillByDefault(Return(messages));

    EXPECT_CALL(*m, chatName());
    EXPECT_CALL(*v, setChatTitle(_));
    EXPECT_CALL(*m, messageHistory(_));
    EXPECT_CALL(*m, isConsumer());
    EXPECT_CALL(*v, enableControls(_));
    EXPECT_CALL(*v, showLeaveAction(_));
    EXPECT_CALL(*m, getParticipants());
    EXPECT_CALL(*v, setParticipants(_));
    presenter.setView(v.get());

    EXPECT_CALL(*v, showView());
    presenter.showView();

    EXPECT_CALL(*v, addMessage(_));
    m->triggerIncomingMessage();
}
TEST(chatpresenter, test_postingsms)
{
    Poco::SharedPtr<MockChatService> m(new MockChatService);

    Mvp::Presenter::TextChatPresenter presenter(m.get());
    Poco::SharedPtr<MockChatView> v(new MockChatView());
    EXPECT_CALL(*v, initialize());

    ON_CALL(*m, getParticipants())
        .WillByDefault(Return(contacts));
    ON_CALL(*m, messageHistory(_))
        .WillByDefault(Return(messages));

    EXPECT_CALL(*m, chatName());
    EXPECT_CALL(*v, setChatTitle(_));
    EXPECT_CALL(*m, messageHistory(_));
    EXPECT_CALL(*m, isConsumer());
    EXPECT_CALL(*v, enableControls(_));
    EXPECT_CALL(*v, showLeaveAction(_));
    EXPECT_CALL(*m, getParticipants());
    EXPECT_CALL(*v, setParticipants(_));
    presenter.setView(v.get());

    EXPECT_CALL(*v, showView());
    presenter.showView();

    EXPECT_CALL(*v, setSmsMode(true));
    v->triggerToggleMode();

    EXPECT_CALL(*m, postSMS(_));
    v->triggerPostMessage();

    EXPECT_CALL(*v, reportMessageStatus(
        Mvp::View::AbstractChatView::SmsDelivered, _));
    m->triggerSmsDelivered();

    EXPECT_CALL(*v, reportMessageStatus(
        Mvp::View::AbstractChatView::MiscError, _));
    m->triggerSmsError();
}
Exemple #3
0
void GroupWindow::viewGroup()
{
    Group *group = (Group *) contact;

    GroupInfoWindow *groupInfoWindow = new GroupInfoWindow(group, Client::roster, this);

    emit photoUpdate(group->jid, group->photoId, false);
    emit getParticipants(group->jid);

    groupInfoWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
    groupInfoWindow->setAttribute(Qt::WA_DeleteOnClose);
    groupInfoWindow->setWindowFlags(groupInfoWindow->windowFlags() | Qt::Window);

    groupInfoWindow->show();

}
std::vector<Poco::SharedPtr<ContactData> >
    ConvManagerService::getNonParticipants()
{
    std::vector<Poco::SharedPtr<ContactData> > nonParticipants;

    // Gets the Skype Core instance.
    SkypeCore *skype = SkypeCore::instance();

    /* Once we have decided which group to fetch it's necessary to get a
    * contact group object passing which kind of group you want, in our
    * case ALL_BUDDIES.
    */
    SkypeContactGroup::Ref contactGroup;
    skype->GetHardwiredContactGroup(ContactGroup::ALL_BUDDIES, contactGroup);

    // Now we have a specialized group with a set of contacts.
    ContactRefs list;
    contactGroup->GetContacts(list);

    // We need the participants, so we can filter them out.
    std::vector<Poco::SharedPtr<ContactData> > participants =
        getParticipants();

    // Let's extract some data from the contacts.
    unsigned int size = list.size();
    for (unsigned int i = 0; i < size; ++i) {
        // Now let's see if the contact is a participant already.
        Poco::SharedPtr<ContactData> newData(Util::dataFromContact(list[i]));

        bool isParticipant = false;

        unsigned int pSize = participants.size();
        for (unsigned int j = 0; j < pSize; ++j)
            if (participants[j]->skypeName == newData->skypeName ||
                (m_conversationMode == Call && newData->status == Offline)) {
                isParticipant = true;
                break;
            }

        // Otherwise, add it to the list.
        if (!isParticipant)
            nonParticipants.push_back(newData);
    }

    return nonParticipants;
}
Exemple #5
0
ChatWindow *MainWindow::createChatWindow(Contact& contact, bool show)
{
    // Just open one window at a time to avoid duplicates
    createWindowMutex.lock();

    ChatWindow *chat;

    QString jid = contact.jid;

    if (contact.type == Contact::TypeGroup)
        Utilities::logData("Group");
    else
        Utilities::logData("Contact");

    if (!chatWindowList.contains(jid))
    {
        Utilities::logData("There's no previous chat window");

        if (contact.type == Contact::TypeContact)
            chat = new ChatWindow(&contact,this);
        else
            chat = new GroupWindow((Group *)&contact,this);

        chatWindowList.insert(jid,chat);

        if (!lastContactsList.contains(jid))
        {
            // This is a new chat and it is not in the
            // open chats list

            // Create the open chats item
            ChatDisplayItem *item = new ChatDisplayItem(&contact);
            lastContactsList.insert(jid,item);
            model->appendRow(item);

            // Set the last line logged in the item
            FMessage msg = chat->lastMessage();
            item->updateData(msg);

            // Store this chat in the DB
            ConversationsDBEntry entry;
            entry.jid = jid;
            entry.muted = false;
            entry.muteExpireTimestamp = 0;
            chatsDB.createChat(entry);

            if (contact.type == Contact::TypeContact)
                emit subscribe(jid);
        }
        else
        {
            // This chat is in the open chats list

            // Configure mute settings
            ChatDisplayItem *item = lastContactsList.value(jid);
            if (item->muted)
                chat->setMute(item->muteExpireTimestamp);
        }

        chat->setAttribute(Qt::WA_DeleteOnClose);

        if (!show)
                Utilities::logData("Chat window will not be shown");
        if (show)
        {
            Utilities::logData("Showing chat window");
            qint64 startTime = QDateTime::currentMSecsSinceEpoch();
            chat->show();
            qint64 endTime = QDateTime::currentMSecsSinceEpoch() - startTime;
            Utilities::logData("Chat window showed " + QString::number(endTime) +
                               " milliseconds.");
        }

        connect(chat,SIGNAL(sendMessage(FMessage)),
                this,SLOT(sendMessageFromChat(FMessage)));

        connect(chat,SIGNAL(destroyed(QObject *)),
                this,SLOT(deleteChat(QObject *)));

        connect(chat,SIGNAL(mute(QString,bool,qint64)),
                this,SLOT(mute(QString,bool,qint64)));

        connect(chat,SIGNAL(blockOrUnblockContact(QString,bool)),
                this,SLOT(blockOrUnblockContact(QString,bool)));

        connect(chat,SIGNAL(photoRefresh(QString,QString,bool)),
                this,SLOT(requestPhotoRefresh(QString,QString,bool)));

        connect(chat,SIGNAL(requestStatus(QString)),
                this,SLOT(requestContactStatus(QString)));

        connect(chat,SIGNAL(voiceNotePlayed(FMessage)),
                this,SLOT(sendVoiceNotePlayed(FMessage)));

        if (contact.type == Contact::TypeGroup)
        {
            GroupWindow *groupChat = (GroupWindow *) chat;
            connect(groupChat,SIGNAL(changeSubject(QString,QString)),
                    this,SLOT(sendSetGroupSubjectFromChat(QString,QString)));

            connect(groupChat,SIGNAL(requestLeaveGroup(QString)),
                    this,SLOT(requestLeaveGroupFromChat(QString)));

            connect(groupChat,SIGNAL(getParticipants(QString)),
                    this,SLOT(requestGetParticipants(QString)));
        }
        else
            emit queryLastOnline(jid);
    }