forked from blue/squawk
Refactoring, account destruction fix, some thoughts about where to store contact settings (omemo enable status for instance)
This commit is contained in:
parent
283e9ebc4d
commit
fffef9876a
15 changed files with 352 additions and 380 deletions
|
@ -42,57 +42,48 @@ Core::Conference::Conference(const QString& p_jid, const QString& p_account, boo
|
|||
connect(room, &QXmppMucRoom::error, this, &Conference::onRoomError);
|
||||
|
||||
room->setNickName(nick);
|
||||
if (autoJoin) {
|
||||
if (autoJoin)
|
||||
room->join();
|
||||
}
|
||||
|
||||
archive->readAllResourcesAvatars(exParticipants);
|
||||
}
|
||||
|
||||
Core::Conference::~Conference()
|
||||
{
|
||||
if (joined) {
|
||||
Core::Conference::~Conference(){
|
||||
if (joined)
|
||||
room->leave();
|
||||
}
|
||||
|
||||
room->deleteLater();
|
||||
}
|
||||
|
||||
QString Core::Conference::getNick() const
|
||||
{
|
||||
QString Core::Conference::getNick() const {
|
||||
return nick;
|
||||
}
|
||||
|
||||
bool Core::Conference::getAutoJoin()
|
||||
{
|
||||
bool Core::Conference::getAutoJoin() const {
|
||||
return autoJoin;
|
||||
}
|
||||
|
||||
bool Core::Conference::getJoined() const
|
||||
{
|
||||
bool Core::Conference::getJoined() const {
|
||||
return joined;
|
||||
}
|
||||
|
||||
void Core::Conference::setJoined(bool p_joined)
|
||||
{
|
||||
void Core::Conference::setJoined(bool p_joined) {
|
||||
if (joined != p_joined) {
|
||||
if (p_joined) {
|
||||
if (p_joined)
|
||||
room->join();
|
||||
} else {
|
||||
else
|
||||
room->leave();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Conference::setAutoJoin(bool p_autoJoin)
|
||||
{
|
||||
void Core::Conference::setAutoJoin(bool p_autoJoin) {
|
||||
if (autoJoin != p_autoJoin) {
|
||||
autoJoin = p_autoJoin;
|
||||
emit autoJoinChanged(autoJoin);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Conference::setNick(const QString& p_nick)
|
||||
{
|
||||
void Core::Conference::setNick(const QString& p_nick) {
|
||||
if (nick != p_nick) {
|
||||
if (joined) {
|
||||
room->setNickName(p_nick);
|
||||
|
@ -103,45 +94,38 @@ void Core::Conference::setNick(const QString& p_nick)
|
|||
}
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomJoined()
|
||||
{
|
||||
void Core::Conference::onRoomJoined() {
|
||||
joined = true;
|
||||
emit joinedChanged(joined);
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomLeft()
|
||||
{
|
||||
void Core::Conference::onRoomLeft() {
|
||||
joined = false;
|
||||
emit joinedChanged(joined);
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomNameChanged(const QString& p_name)
|
||||
{
|
||||
void Core::Conference::onRoomNameChanged(const QString& p_name) {
|
||||
setName(p_name);
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomNickNameChanged(const QString& p_nick)
|
||||
{
|
||||
void Core::Conference::onRoomNickNameChanged(const QString& p_nick) {
|
||||
if (p_nick != nick) {
|
||||
nick = p_nick;
|
||||
emit nickChanged(nick);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomError(const QXmppStanza::Error& err)
|
||||
{
|
||||
void Core::Conference::onRoomError(const QXmppStanza::Error& err) {
|
||||
qDebug() << "MUC" << jid << "error:" << err.text();
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomParticipantAdded(const QString& p_name)
|
||||
{
|
||||
void Core::Conference::onRoomParticipantAdded(const QString& p_name) {
|
||||
QStringList comps = p_name.split("/");
|
||||
QString resource = comps.back();
|
||||
QXmppPresence pres = room->participantPresence(p_name);
|
||||
QXmppMucItem mi = pres.mucItem();
|
||||
if (resource == jid) {
|
||||
if (resource == jid)
|
||||
resource = "";
|
||||
}
|
||||
|
||||
std::map<QString, Archive::AvatarInfo>::const_iterator itr = exParticipants.find(resource);
|
||||
bool hasAvatar = itr != exParticipants.end();
|
||||
|
@ -166,19 +150,7 @@ void Core::Conference::onRoomParticipantAdded(const QString& p_name)
|
|||
)
|
||||
}
|
||||
};
|
||||
|
||||
if (hasAvatar) {
|
||||
if (itr->second.autogenerated) {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::valid));
|
||||
} else {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::autocreated));
|
||||
}
|
||||
cData.insert("avatarPath", avatarPath(resource) + "." + itr->second.type);
|
||||
} else {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::empty));
|
||||
cData.insert("avatarPath", "");
|
||||
emit requestVCard(p_name);
|
||||
}
|
||||
careAboutAvatar(hasAvatar, itr->second, cData, resource, p_name);
|
||||
|
||||
emit addParticipant(resource, cData);
|
||||
}
|
||||
|
@ -196,9 +168,9 @@ void Core::Conference::onRoomParticipantAdded(const QString& p_name)
|
|||
break;
|
||||
case QXmppPresence::VCardUpdateValidPhoto:{ //there is a photo, need to load
|
||||
if (hasAvatar) {
|
||||
if (itr->second.autogenerated || itr->second.hash != pres.photoHash()) {
|
||||
if (itr->second.autogenerated || itr->second.hash != pres.photoHash())
|
||||
emit requestVCard(p_name);
|
||||
}
|
||||
|
||||
} else {
|
||||
emit requestVCard(p_name);
|
||||
}
|
||||
|
@ -207,8 +179,7 @@ void Core::Conference::onRoomParticipantAdded(const QString& p_name)
|
|||
}
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomParticipantChanged(const QString& p_name)
|
||||
{
|
||||
void Core::Conference::onRoomParticipantChanged(const QString& p_name) {
|
||||
QStringList comps = p_name.split("/");
|
||||
QString resource = comps.back();
|
||||
QXmppPresence pres = room->participantPresence(p_name);
|
||||
|
@ -216,9 +187,8 @@ void Core::Conference::onRoomParticipantChanged(const QString& p_name)
|
|||
handlePresence(pres);
|
||||
if (resource != jid) {
|
||||
QDateTime lastInteraction = pres.lastUserInteraction();
|
||||
if (!lastInteraction.isValid()) {
|
||||
if (!lastInteraction.isValid())
|
||||
lastInteraction = QDateTime::currentDateTimeUtc();
|
||||
}
|
||||
|
||||
emit changeParticipant(resource, {
|
||||
{"lastActivity", lastInteraction},
|
||||
|
@ -237,8 +207,7 @@ void Core::Conference::onRoomParticipantChanged(const QString& p_name)
|
|||
}
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomParticipantRemoved(const QString& p_name)
|
||||
{
|
||||
void Core::Conference::onRoomParticipantRemoved(const QString& p_name) {
|
||||
QStringList comps = p_name.split("/");
|
||||
QString resource = comps.back();
|
||||
if (resource == jid) {
|
||||
|
@ -248,29 +217,24 @@ void Core::Conference::onRoomParticipantRemoved(const QString& p_name)
|
|||
}
|
||||
}
|
||||
|
||||
QString Core::Conference::getSubject() const
|
||||
{
|
||||
if (joined) {
|
||||
QString Core::Conference::getSubject() const {
|
||||
if (joined)
|
||||
return room->subject();
|
||||
} else {
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Conference::onRoomSubjectChanged(const QString& p_name)
|
||||
{
|
||||
void Core::Conference::onRoomSubjectChanged(const QString& p_name) {
|
||||
emit subjectChanged(p_name);
|
||||
}
|
||||
|
||||
void Core::Conference::handlePresence(const QXmppPresence& pres)
|
||||
{
|
||||
void Core::Conference::handlePresence(const QXmppPresence& pres) {
|
||||
QString id = pres.from();
|
||||
QStringList comps = id.split("/");
|
||||
QString jid = comps.front();
|
||||
QString resource("");
|
||||
if (comps.size() > 1) {
|
||||
if (comps.size() > 1)
|
||||
resource = comps.back();
|
||||
}
|
||||
|
||||
switch (pres.vCardUpdateType()) {
|
||||
case QXmppPresence::VCardUpdateNone: //this presence has nothing to do with photo
|
||||
|
@ -284,14 +248,13 @@ void Core::Conference::handlePresence(const QXmppPresence& pres)
|
|||
setAutoGeneratedAvatar(resource);
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case QXmppPresence::VCardUpdateValidPhoto:{ //there is a photo, need to load
|
||||
Archive::AvatarInfo info;
|
||||
bool hasAvatar = readAvatarInfo(info, resource);
|
||||
if (hasAvatar) {
|
||||
if (info.autogenerated || info.hash != pres.photoHash()) {
|
||||
if (info.autogenerated || info.hash != pres.photoHash())
|
||||
emit requestVCard(id);
|
||||
}
|
||||
} else {
|
||||
emit requestVCard(id);
|
||||
}
|
||||
|
@ -300,17 +263,15 @@ void Core::Conference::handlePresence(const QXmppPresence& pres)
|
|||
}
|
||||
}
|
||||
|
||||
bool Core::Conference::setAutoGeneratedAvatar(const QString& resource)
|
||||
{
|
||||
bool Core::Conference::setAutoGeneratedAvatar(const QString& resource) {
|
||||
Archive::AvatarInfo newInfo;
|
||||
bool result = RosterItem::setAutoGeneratedAvatar(newInfo, resource);
|
||||
if (result && resource.size() != 0) {
|
||||
std::map<QString, Archive::AvatarInfo>::iterator itr = exParticipants.find(resource);
|
||||
if (itr == exParticipants.end()) {
|
||||
if (itr == exParticipants.end())
|
||||
exParticipants.insert(std::make_pair(resource, newInfo));
|
||||
} else {
|
||||
else
|
||||
itr->second = newInfo;
|
||||
}
|
||||
emit changeParticipant(resource, {
|
||||
{"avatarState", static_cast<uint>(Shared::Avatar::autocreated)},
|
||||
{"avatarPath", avatarPath(resource) + "." + newInfo.type}
|
||||
|
@ -320,17 +281,15 @@ bool Core::Conference::setAutoGeneratedAvatar(const QString& resource)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool Core::Conference::setAvatar(const QByteArray& data, Archive::AvatarInfo& info, const QString& resource)
|
||||
{
|
||||
bool Core::Conference::setAvatar(const QByteArray& data, Archive::AvatarInfo& info, const QString& resource) {
|
||||
bool result = RosterItem::setAvatar(data, info, resource);
|
||||
if (result && resource.size() != 0) {
|
||||
if (data.size() > 0) {
|
||||
std::map<QString, Archive::AvatarInfo>::iterator itr = exParticipants.find(resource);
|
||||
if (itr == exParticipants.end()) {
|
||||
if (itr == exParticipants.end())
|
||||
exParticipants.insert(std::make_pair(resource, info));
|
||||
} else {
|
||||
else
|
||||
itr->second = info;
|
||||
}
|
||||
|
||||
emit changeParticipant(resource, {
|
||||
{"avatarState", static_cast<uint>(Shared::Avatar::autocreated)},
|
||||
|
@ -338,9 +297,8 @@ bool Core::Conference::setAvatar(const QByteArray& data, Archive::AvatarInfo& in
|
|||
});
|
||||
} else {
|
||||
std::map<QString, Archive::AvatarInfo>::iterator itr = exParticipants.find(resource);
|
||||
if (itr != exParticipants.end()) {
|
||||
if (itr != exParticipants.end())
|
||||
exParticipants.erase(itr);
|
||||
}
|
||||
|
||||
emit changeParticipant(resource, {
|
||||
{"avatarState", static_cast<uint>(Shared::Avatar::empty)},
|
||||
|
@ -353,10 +311,8 @@ bool Core::Conference::setAvatar(const QByteArray& data, Archive::AvatarInfo& in
|
|||
return result;
|
||||
}
|
||||
|
||||
void Core::Conference::handleResponseVCard(const QXmppVCardIq& card, const QString &resource, Shared::VCard& out)
|
||||
{
|
||||
void Core::Conference::handleResponseVCard(const QXmppVCardIq& card, const QString &resource, Shared::VCard& out) {
|
||||
RosterItem::handleResponseVCard(card, resource, out);
|
||||
|
||||
if (resource.size() > 0) {
|
||||
emit changeParticipant(resource, {
|
||||
{"avatarState", static_cast<uint>(out.getAvatarType())},
|
||||
|
@ -365,11 +321,21 @@ void Core::Conference::handleResponseVCard(const QXmppVCardIq& card, const QStri
|
|||
}
|
||||
}
|
||||
|
||||
QMap<QString, QVariant> Core::Conference::getAllAvatars() const
|
||||
{
|
||||
QMap<QString, QVariant> Core::Conference::getAllAvatars() const {
|
||||
QMap<QString, QVariant> result;
|
||||
for (const std::pair<const QString, Archive::AvatarInfo>& pair : exParticipants) {
|
||||
for (const std::pair<const QString, Archive::AvatarInfo>& pair : exParticipants)
|
||||
result.insert(pair.first, avatarPath(pair.first) + "." + pair.second.type);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QMap<QString, QVariant> Core::Conference::getInfo() const {
|
||||
QMap<QString, QVariant> data = RosterItem::getInfo();
|
||||
|
||||
data.insert("autoJoin", getAutoJoin());
|
||||
data.insert("joined", getJoined());
|
||||
data.insert("nick", getNick());
|
||||
data.insert("avatars", getAllAvatars());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue