Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Merge pull request #14 from lduboeuf/xenial_-_sentdateempty
Browse files Browse the repository at this point in the history
handle case where sms or mms don't have the sent date set
  • Loading branch information
Flohack74 committed Sep 30, 2020
2 parents cc44948 + 4945418 commit db5e35b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ofonotextchannel.cpp
Expand Up @@ -461,7 +461,7 @@ void oFonoTextChannel::messageReceived(const QString &message, uint handle, cons
Tp::MessagePart header;
header["message-token"] = QDBusVariant(info["SentTime"].toString() +"-" + QString::number(mMessageCounter++));
header["message-received"] = QDBusVariant(QDateTime::currentDateTime().toTime_t());
header["message-sent"] = QDBusVariant(QDateTime::fromString(info["SentTime"].toString(), Qt::ISODate).toTime_t());
header["message-sent"] = QDBusVariant(getSentDate(info["SentTime"].toString()).toTime_t());
header["message-sender"] = QDBusVariant(handle);
header["message-sender-id"] = QDBusVariant(mPhoneNumbers[0]);
header["message-type"] = QDBusVariant(Tp::ChannelTextMessageTypeNormal);
Expand All @@ -480,7 +480,7 @@ void oFonoTextChannel::mmsReceived(const QString &id, uint handle, const QVarian
header["message-token"] = QDBusVariant(id);
header["message-sender"] = QDBusVariant(handle);
header["message-received"] = QDBusVariant(QDateTime::currentDateTimeUtc().toTime_t());
header["message-sent"] = QDBusVariant(QDateTime::fromString(properties["SentTime"].toString(), Qt::ISODate).toTime_t());
header["message-sent"] = QDBusVariant(getSentDate(properties["Date"].toString()).toTime_t());
header["message-type"] = QDBusVariant(Tp::DeliveryStatusDelivered);
header["x-canonical-mms"] = QDBusVariant(true);
if (!subject.isEmpty())
Expand Down Expand Up @@ -518,3 +518,14 @@ void oFonoTextChannel::mmsReceived(const QString &id, uint handle, const QVarian

mTextChannel->addReceivedMessage(message);
}

QDateTime oFonoTextChannel::getSentDate(const QString &sentTime){
QDateTime dt = QDateTime::fromString(sentTime, Qt::ISODate);
QDateTime currentDate = QDateTime::currentDateTimeUtc();
//some text message may not have the Sentime set, use the received one in that case
if (!dt.isValid() || dt > currentDate){
dt = currentDate;
}

return dt;
}
1 change: 1 addition & 0 deletions ofonotextchannel.h
Expand Up @@ -60,6 +60,7 @@ private Q_SLOTS:

private:
~oFonoTextChannel();
QDateTime getSentDate(const QString &sentTime);
Tp::BaseChannelPtr mBaseChannel;
QStringList mPhoneNumbers;
oFonoConnection *mConnection;
Expand Down

0 comments on commit db5e35b

Please sign in to comment.