From 40c80b397326f7753a15c7a43fc5483876ae9f58 Mon Sep 17 00:00:00 2001
From: Armin Felder <armin.felder@osalliance.com>
Date: Mon, 3 Dec 2018 02:56:37 +0100
Subject: [PATCH] reply message segfault fix

---
 CustomModels/messagemodel.cpp         | 16 ++++++++++------
 repos/entities/rocketchatattachment.h | 10 +++++++---
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/CustomModels/messagemodel.cpp b/CustomModels/messagemodel.cpp
index d1645e9..94e7c47 100644
--- a/CustomModels/messagemodel.cpp
+++ b/CustomModels/messagemodel.cpp
@@ -109,10 +109,12 @@ QVariant MessagesModel::data( const QModelIndex &index, int role ) const
 
                     if ( !first.isNull() ) {
                         //TODO: WTF!!!
-                        auto msg =  qSharedPointerCast<RocketChatReplyMessage>( first );
+                        if ( first->getType() == QStringLiteral( "replyMessage" ) ) {
+                            auto msg =  qSharedPointerCast<RocketChatReplyMessage>( first );
 
-                        if ( !msg.isNull() ) {
-                            return msg->getMessageString();
+                            if ( !msg.isNull() ) {
+                                return msg->getMessageString();
+                            }
                         }
                     }
                 }
@@ -127,10 +129,12 @@ QVariant MessagesModel::data( const QModelIndex &index, int role ) const
 
                     if ( !first.isNull() ) {
                         //TODO: WTF!!!
-                        auto msg =  qSharedPointerCast<RocketChatReplyMessage>( first );
+                        if ( first->getType() == QStringLiteral( "replyMessage" ) ) {
+                            auto msg =  qSharedPointerCast<RocketChatReplyMessage>( first );
 
-                        if ( !msg.isNull() ) {
-                            return msg->getAuthor();
+                            if ( !msg.isNull() ) {
+                                return msg->getAuthor();
+                            }
                         }
                     }
                 }
diff --git a/repos/entities/rocketchatattachment.h b/repos/entities/rocketchatattachment.h
index 97d6d11..f63c78b 100644
--- a/repos/entities/rocketchatattachment.h
+++ b/repos/entities/rocketchatattachment.h
@@ -28,10 +28,14 @@ class RocketChatAttachment : public QObject
 {
         Q_OBJECT
     public:
-        RocketChatAttachment( const QString &pFileUrl, const QString &pType, const QString &pTitle );
+        enum class attachmentsType {
+            replyMessage
+        };
+
+        RocketChatAttachment( const QString &pFileUrl, const attachmentsType &pType, const QString &pTitle );
 
         const QString &getUrl() const;
-        const QString &getType() const;
+        const attachmentsType getType() const;
         const QString &getTitle() const;
 
         int getWidth() const;
@@ -42,7 +46,7 @@ class RocketChatAttachment : public QObject
 
     protected:
         QString mUrl;
-        QString mType;
+        attachmentsType mType;
         QString mTitle;
         int mWidth = -1;
         int mHeight = -1;
-- 
GitLab