Skip to content

Commit

Permalink
Merge branch 'GroupChatName' into 'master'
Browse files Browse the repository at this point in the history
Fetch and update room name with RoomInterface and RoomConfiginterface. Contributes to MER#1444

See merge request mer-core/commhistory-daemon!6
  • Loading branch information
pvuorela committed May 3, 2021
2 parents d5a8e20 + 55724f6 commit 268398b
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 2 deletions.
82 changes: 80 additions & 2 deletions src/textchannellistener.cpp
Expand Up @@ -46,6 +46,8 @@
#include <TelepathyQt/Contact>
#include <TelepathyQt/ContactManager>
#include <TelepathyQt/PendingContacts>
#include <TelepathyQt/PendingVariant>
#include <TelepathyQt/PendingVariantMap>
#include <TelepathyQt/Connection>
#include <TelepathyQt/Properties>
#include <TelepathyQt/Presence>
Expand Down Expand Up @@ -239,8 +241,17 @@ void TextChannelListener::channelListenerReady()
{
qCDebug(lcCommhistoryd) << __PRETTY_FUNCTION__;

if (m_IsGroupChat)
handleTpProperties();
if (m_IsGroupChat) {
if(m_Channel->hasInterface(Tp::Client::ChannelInterfaceRoomConfigInterface::staticInterfaceName()) &&
m_Channel->hasInterface(Tp::Client::ChannelInterfaceRoomInterface::staticInterfaceName()))
{
handleTpRoomProperties();
}
else if(m_Channel->hasInterface(Tp::Client::DBus::PropertiesInterface::staticInterfaceName()))
{
handleTpProperties();
}
}

Tp::TextChannelPtr textChannel = Tp::TextChannelPtr::dynamicCast(m_Channel);

Expand Down Expand Up @@ -437,6 +448,44 @@ void TextChannelListener::handleTpProperties()
this, SLOT(slotListPropertiesFinished(QDBusPendingCallWatcher *)));
}

void TextChannelListener::handleTpRoomProperties()
{
Tp::Client::ChannelInterfaceRoomConfigInterface* roomConfigInterface = m_Channel->interface<Tp::Client::ChannelInterfaceRoomConfigInterface>();
connect( roomConfigInterface->requestAllProperties(),
SIGNAL(finished(Tp::PendingOperation*)),
this,
SLOT(slotRequestAllRoomProperies(Tp::PendingOperation*))
);
Tp::Client::ChannelInterfaceRoomInterface* roomInterface = m_Channel->interface<Tp::Client::ChannelInterfaceRoomInterface>();
connect( roomInterface->requestPropertyRoomName(),
SIGNAL(finished(Tp::PendingOperation*)),
this,
SLOT(slotRequestPropertyRoomName(Tp::PendingOperation*))
);
connect( roomConfigInterface,
SIGNAL(propertiesChanged(const QVariantMap&, const QStringList&)),
this,
SLOT(slotRoomPropertiesChanged(const QVariantMap&,const QStringList&))
);
roomConfigInterface->setMonitorProperties(true);
}

void TextChannelListener::processRoomProperties(const QVariantMap &properties)
{
QVariantMap::const_iterator i = properties.constBegin();

while(i != properties.constEnd()) {
if(i.key() == "Title") {
QString title = i.value().toString();
if( !title.isEmpty() && m_ChannelSubject != title ) {
m_ChannelSubject = title;
updateGroupChatName( ChannelSubject, false );
}
}
i++;
}
}

void TextChannelListener::slotListPropertiesFinished(QDBusPendingCallWatcher *watcher)
{
qCDebug(lcCommhistoryd) << Q_FUNC_INFO;
Expand Down Expand Up @@ -1773,6 +1822,35 @@ void TextChannelListener::slotPropertiesChanged(const Tp::PropertyValueList &pro
if (changedProperty != None)
updateGroupChatName(changedProperty, listProps);
}
void TextChannelListener::slotRequestAllRoomProperies(Tp::PendingOperation *operation)
{
DEBUG() << __FUNCTION__;

QVariantMap properties = dynamic_cast<Tp::PendingVariantMap*>( operation )->result();
processRoomProperties(properties);
}

void TextChannelListener::slotRequestPropertyRoomName(Tp::PendingOperation *operation)
{
DEBUG() << __FUNCTION__;

QString name = dynamic_cast<Tp::PendingVariant*>( operation )->result().toString();

if( !name.isEmpty() && m_ChannelName != name )
{
m_ChannelName = name;
if( m_ChannelSubject.isEmpty() )
{
updateGroupChatName(ChannelName, false);
}
}
}

void TextChannelListener::slotRoomPropertiesChanged(const QVariantMap &changedProperties, const QStringList &invalidatedProperties)
{
DEBUG() << __FUNCTION__;
processRoomProperties(changedProperties);
}

void TextChannelListener::slotGroupMembersChanged(
const Tp::Contacts &groupMembersAdded,
Expand Down
7 changes: 7 additions & 0 deletions src/textchannellistener.h
Expand Up @@ -42,6 +42,7 @@ namespace Tp {
class Message;
class ReceivedMessage;
class PendingOperation;
class PendingVariantMap;
class Presence;

namespace Client {
Expand Down Expand Up @@ -89,6 +90,10 @@ private Q_SLOTS:
void slotEventsCommitted(QList<CommHistory::Event> events, bool status);
void slotContactsReady(Tp::PendingOperation* operation);
void slotPropertiesChanged(const Tp::PropertyValueList &props, bool listProps = false);
void slotRequestAllRoomProperies(Tp::PendingOperation *operation);
void slotRequestPropertyRoomName(Tp::PendingOperation *operation);
void slotRoomPropertiesChanged(const QVariantMap &changedProperties,
const QStringList &invalidatedProperties);
void slotGroupMembersChanged(const Tp::Contacts &groupMembersAdded,
const Tp::Contacts &groupLocalPendingMembersAdded,
const Tp::Contacts &groupRemotePendingMembersAdded,
Expand Down Expand Up @@ -126,6 +131,8 @@ private Q_SLOTS:
void requestConversationId();
int groupId();
void handleTpProperties();
void handleTpRoomProperties();
void processRoomProperties(const QVariantMap &properties);

// delivery report
DeliveryHandlingStatus handleDeliveryReport(const Tp::ReceivedMessage &message,
Expand Down
7 changes: 7 additions & 0 deletions tests/stubs/TelepathyQt/PendingVariant
@@ -0,0 +1,7 @@
#ifndef _TelepathyQt4_Client_PendingVariant_HEADER_GUARD_
#define _TelepathyQt4_Client_PendingVariant_HEADER_GUARD_

#include "pending-variant.h"

#endif
// vim:set ft=cpp:
7 changes: 7 additions & 0 deletions tests/stubs/TelepathyQt/PendingVariantMap
@@ -0,0 +1,7 @@
#ifndef _TelepathyQt4_Client_PendingOperation_HEADER_GUARD_
#define _TelepathyQt4_Client_PendingOperation_HEADER_GUARD_

#include "pending-operation.h"

#endif
// vim:set ft=cpp:
8 changes: 8 additions & 0 deletions tests/stubs/TelepathyQt/abstract-interface.h
Expand Up @@ -56,6 +56,14 @@ class AbstractInterface : public QDBusAbstractInterface

bool isValid() const {return m_isValid;}

void setMonitorProperties(bool monitorProperties){
Q_UNUSED(monitorProperties);
}

Q_SIGNALS:
void propertiesChanged(const QVariantMap &changedProperties,
const QStringList &invalidatedProperties);

public:
void ut_setIsValid(bool valid) {m_isValid = valid;}

Expand Down
34 changes: 34 additions & 0 deletions tests/stubs/TelepathyQt/channel.h
Expand Up @@ -31,6 +31,9 @@
#include "AbstractInterface"
#include "Properties"

#include "pending-variant.h"
#include "pending-variant-map.h"

#include <QSet>
#include <QSharedDataPointer>
#include <QVariantMap>
Expand Down Expand Up @@ -79,6 +82,32 @@ namespace Client {
void ServicePointChanged(const Tp::ServicePoint& servicePoint);
};

class ChannelInterfaceRoomConfigInterface : public Tp::AbstractInterface {
public:
static inline QLatin1String staticInterfaceName()
{
return QLatin1String("org.freedesktop.Telepathy.Channel.Interface.RoomConfig1");
}

PendingVariantMap *requestAllProperties() const
{
return new PendingVariantMap;
}
};

class ChannelInterfaceRoomInterface : public Tp::AbstractInterface {
public:
static inline QLatin1String staticInterfaceName()
{
return QLatin1String("org.freedesktop.Telepathy.Channel.Interface.Room2");
}

PendingVariant *requestPropertyRoomName() const
{
return new PendingVariant;
}
};

}

class Channel : public StatefulDBusProxy
Expand All @@ -92,6 +121,11 @@ class Channel : public StatefulDBusProxy

QStringList interfaces() const;

inline bool hasInterface(const QString &name) const
{
return m_interfaces.contains(name);
}

template <typename Interface>
inline Interface *interface()
{
Expand Down
10 changes: 10 additions & 0 deletions tests/stubs/TelepathyQt/pending-variant-map.cpp
@@ -0,0 +1,10 @@
#include "pending-variant-map.h"

Tp::PendingVariantMap::PendingVariantMap()
{
}

QVariantMap Tp::PendingVariantMap::result() const
{
return QVariantMap();
}
26 changes: 26 additions & 0 deletions tests/stubs/TelepathyQt/pending-variant-map.h
@@ -0,0 +1,26 @@
#ifndef _TelepathyQt_pending_variant_map_h_HEADER_GUARD_
#define _TelepathyQt_pending_variant_map_h_HEADER_GUARD_

#include <TelepathyQt/PendingOperation>

#include <QDBusPendingCallWatcher>

namespace Tp
{

class PendingVariantMap : public PendingOperation
{
Q_OBJECT

public:
PendingVariantMap();

QVariantMap result() const;

private:

};

} // Tp

#endif
12 changes: 12 additions & 0 deletions tests/stubs/TelepathyQt/pending-variant.cpp
@@ -0,0 +1,12 @@
#include "pending-variant.h"


Tp::PendingVariant::PendingVariant()
{
}

QVariant Tp::PendingVariant::result() const
{
return QVariant();
}

25 changes: 25 additions & 0 deletions tests/stubs/TelepathyQt/pending-variant.h
@@ -0,0 +1,25 @@
#ifndef _TelepathyQt_pending_variant_h_HEADER_GUARD_
#define _TelepathyQt_pending_variant_h_HEADER_GUARD_

#include <TelepathyQt/PendingOperation>
#include <QDBusPendingCallWatcher>

namespace Tp
{

class PendingVariant : public PendingOperation
{
Q_OBJECT

public:
PendingVariant();

QVariant result() const;

private:

};

} // Tp

#endif
5 changes: 5 additions & 0 deletions tests/stubs/stubs.pri
Expand Up @@ -5,6 +5,9 @@
# Input

HEADERS += $$PWD/TelepathyQt/pending-operation.h
HEADERS += $$PWD/TelepathyQt/global.h
HEADERS += $$PWD/TelepathyQt/pending-variant-map.h
HEADERS += $$PWD/TelepathyQt/pending-variant.h
HEADERS += $$PWD/TelepathyQt/ready-object.h
HEADERS += $$PWD/TelepathyQt/account-manager.h
HEADERS += $$PWD/TelepathyQt/account.h
Expand All @@ -29,6 +32,8 @@ HEADERS += $$PWD/TpExtensions/cli-connection.h
HEADERS += $$PWD/notificationmanager.h

SOURCES += $$PWD/TelepathyQt/pending-operation.cpp
SOURCES += $$PWD/TelepathyQt/pending-variant-map.cpp
SOURCES += $$PWD/TelepathyQt/pending-variant.cpp
SOURCES += $$PWD/TelepathyQt/ready-object.cpp
SOURCES += $$PWD/TelepathyQt/account-manager.cpp
SOURCES += $$PWD/TelepathyQt/account.cpp
Expand Down

0 comments on commit 268398b

Please sign in to comment.