Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Robert Maerkisch
kaidan
Commits
b3b72117
Commit
b3b72117
authored
May 13, 2018
by
Linus Jahn
Committed by
Jonah Brüchert
May 15, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MessageHandler: Fix timezone bug of timestamps, Clean up
Finally got fixed! :) Fixes #159.
parent
4d53d079
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
20 deletions
+16
-20
src/MessageHandler.cpp
src/MessageHandler.cpp
+14
-18
src/MessageModel.cpp
src/MessageModel.cpp
+2
-2
No files found.
src/MessageHandler.cpp
View file @
b3b72117
...
...
@@ -45,26 +45,21 @@
#include "MessageModel.h"
#include "Notifications.h"
QDateTime
glooxStamp
ToQDateTime
(
std
::
string
stamp
_
)
QDateTime
string
ToQDateTime
(
std
::
string
stamp
)
{
QString
s
tamp
=
QString
::
fromStdString
(
stamp
_
);
QString
qS
tamp
=
QString
::
fromStdString
(
stamp
);
QDateTime
dateTime
;
if
(
stamp
.
contains
(
'Z'
))
{
dateTime
=
QDateTime
::
fromString
(
stamp
,
"yyyy-MM-ddThh:mm:ss.zzzZ"
);
}
else
if
(
stamp
.
contains
(
'-'
)
&&
stamp
.
contains
(
':'
)
&&
stamp
.
contains
(
'.'
))
{
dateTime
=
QDateTime
::
fromString
(
stamp
,
"yyyy-MM-ddThh:mm:ss.zzz"
);
}
else
if
(
stamp
.
contains
(
'-'
)
&&
stamp
.
contains
(
':'
))
{
dateTime
=
QDateTime
::
fromString
(
stamp
,
"yyyy-MM-ddThh:mm:ss"
);
}
else
if
(
stamp
.
contains
(
':'
)
&&
stamp
.
contains
(
'T'
))
{
dateTime
=
QDateTime
::
fromString
(
stamp
,
"yyyyMMddThh:mm:ss"
);
}
else
{
dateTime
=
QDateTime
::
fromString
(
stamp
,
"hh:mm"
);
}
if
(
qStamp
.
contains
(
'.'
))
dateTime
=
QDateTime
::
fromString
(
qStamp
,
Qt
::
ISODateWithMs
);
else
dateTime
=
QDateTime
::
fromString
(
qStamp
,
Qt
::
ISODate
);
if
(
!
dateTime
.
isValid
())
return
QDateTime
();
return
QDateTime
::
currentDateTime
().
toUTC
();
// XMPP timestamps are always in UTC
// also read it as such if 'Z' is missing in ISO timestamp
dateTime
.
setTimeSpec
(
Qt
::
UTC
);
return
dateTime
;
}
...
...
@@ -127,12 +122,13 @@ void MessageHandler::handleMessage(const gloox::Message &stanza, gloox::MessageS
const
gloox
::
DelayedDelivery
*
delayedDelivery
=
message
->
when
();
if
(
delayedDelivery
)
timestamp
=
glooxStamp
ToQDateTime
(
delayedDelivery
->
stamp
())
timestamp
=
string
ToQDateTime
(
delayedDelivery
->
stamp
())
.
toString
(
Qt
::
ISODate
);
// fallback: use current time from local clock
if
(
timestamp
.
isEmpty
())
timestamp
=
QDateTime
::
currentDateTime
().
toString
(
Qt
::
ISODate
);
timestamp
=
QDateTime
::
currentDateTime
().
toUTC
()
.
toString
(
Qt
::
ISODate
);
// add the message to the database
emit
messageModel
->
addMessageRequested
(
fromJid
,
toJid
,
timestamp
,
...
...
@@ -211,11 +207,11 @@ void MessageHandler::sendMessage(QString toJid, QString body)
body
.
toStdString
());
// add the message to the database
const
QString
timestamp
=
QDateTime
::
currentDateTime
().
toString
(
Qt
::
ISODate
);
const
QString
timestamp
=
QDateTime
::
currentDateTime
().
toUTC
().
toString
(
Qt
::
ISODate
);
const
QString
id
=
QString
::
fromStdString
(
message
.
id
());
const
QString
fromJid
=
QString
::
fromStdString
(
client
->
jid
().
bare
());
emit
messageModel
->
addMessageRequested
(
fromJid
,
toJid
,
timestamp
,
body
,
id
,
true
);
emit
messageModel
->
addMessageRequested
(
fromJid
,
toJid
,
timestamp
,
body
,
id
,
true
);
// XEP-0184: Message Delivery Receipts
// request a delivery receipt from the other client
...
...
src/MessageModel.cpp
View file @
b3b72117
...
...
@@ -120,8 +120,8 @@ void MessageModel::addMessage(const QString author, const QString recipient,
record
.
setValue
(
"timestamp"
,
timestamp
);
record
.
setValue
(
"message"
,
message
);
record
.
setValue
(
"id"
,
msgId
);
record
.
setValue
(
"isSent"
,
sentByMe
?
false
:
true
);
record
.
setValue
(
"isDelivered"
,
sentByMe
?
false
:
true
);
record
.
setValue
(
"isSent"
,
!
sentByMe
);
record
.
setValue
(
"isDelivered"
,
!
sentByMe
);
if
(
!
insertRecord
(
rowCount
(),
record
))
{
qWarning
()
<<
"Failed to add message to DB:"
<<
lastError
().
text
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment