Example #1
0
ChannelWatcher::ChannelWatcher(const Tp::TextChannelPtr &channel, const QString &accountObjectPath, QObject *parent)
    : QObject(parent),
      m_channel(channel),
      m_accountObjectPath(accountObjectPath),
      m_db(QSqlDatabase::database()),
      m_contactDbId(0), //sqlite auto-increment starts at 1
      m_accountDbId(0)
{
    qDebug() << "Delivery reports support" << channel->deliveryReportingSupport();

    connect(channel.data(), &Tp::TextChannel::invalidated, this, &ChannelWatcher::invalidated);
    connect(channel.data(), &Tp::TextChannel::invalidated, this, [=]() {
        qDebug() << "Channel invalidated";
    });

    connect(channel.data(), &Tp::TextChannel::messageReceived, this, &ChannelWatcher::onMessageReceived);
    connect(channel.data(), &Tp::TextChannel::messageSent, this, &ChannelWatcher::onMessageSent);

    qDebug() << this << "New channel being watched" << channel.data();

    storeContactInfo();
    storeAccountInfo();

    Q_FOREACH (const Tp::ReceivedMessage &message, channel->messageQueue()) {
        onMessageReceived(message);
    }
}
void ChannelContactModel::setTextChannel(const Tp::TextChannelPtr &channel)
{
    //remove existing contacts in list
    beginRemoveRows(QModelIndex(), 0, m_contacts.size());
    m_contacts.clear();
    endRemoveRows();

    //add existing contacts from channel
    addContacts(channel->groupContacts());

    //monitor for future changes
    connect(channel.data(),
            SIGNAL(groupMembersChanged(Tp::Contacts,Tp::Contacts,Tp::Contacts,
                                       Tp::Contacts,Tp::Channel::GroupMemberChangeDetails)),
            SLOT(onGroupMembersChanged(Tp::Contacts,Tp::Contacts,Tp::Contacts,
                                     Tp::Contacts,Tp::Channel::GroupMemberChangeDetails)));
}