aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-01-12 20:38:50 +0100
committerdec05eba <dec05eba@protonmail.com>2019-01-12 20:38:51 +0100
commit156291b2c15895c41bd3d096d03a88433de49084 (patch)
treeafc3700c2bcc2712656a2dc36c70d56403e9cd38 /src
parentce82dfde0925ade8a589a0b88ef7183ebcf3430f (diff)
Fix crash when sending message with no previous message
Diffstat (limited to 'src')
-rw-r--r--src/Room.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/Room.cpp b/src/Room.cpp
index a8a8d6a..c7135da 100644
--- a/src/Room.cpp
+++ b/src/Room.cpp
@@ -281,16 +281,19 @@ namespace dchat
{
case RoomDataType::ADD_MESSAGE:
{
- RoomMessage message;
- message.id = *request.requestHash;
- message.creator = user;
- message.timestampSeconds = timestampSeconds;
- message.text = std::string((const char*)request.decryptedData.data + 1, request.decryptedData.size - 1);
+ auto message = std::make_shared<RoomMessage>();
+ message->id = *request.requestHash;
+ message->creator = user;
+ message->timestampSeconds = timestampSeconds;
+ message->text = std::string((const char*)request.decryptedData.data + 1, request.decryptedData.size - 1);
RoomAddMessageRequest roomRequest;
roomRequest.room = room;
roomRequest.loadedFromCache = request.loadedFromCache;
roomRequest.message = std::move(message);
+ roomRequest.prevMessage = nullptr;
+ if(!room->messages.empty())
+ roomRequest.prevMessage = room->messages.back();
if(callbackFuncs.addMessageCallbackFunc)
callbackFuncs.addMessageCallbackFunc(roomRequest);