<commit_before>/******************************************************************************
* Copyright (C) 2018 <NAME> <<EMAIL>>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#pragma once

#include "roomevent.h"

namespace QMatrixClient {
    class StateEventBase: public RoomEvent
    {
        public:
            using factory_t = EventFactory<StateEventBase>;

            using RoomEvent::RoomEvent;
            ~StateEventBase() override = default;

            bool isStateEvent() const override { return true; }
            QString replacedState() const;
            void dumpTo(QDebug dbg) const override;

            virtual bool repeatsState() const;
    };
    using StateEventPtr = event_ptr_tt<StateEventBase>;
    using StateEvents = EventsArray<StateEventBase>;

    template <>
    inline bool is<StateEventBase>(const Event& e) { return e.isStateEvent(); }

    /**
     * A combination of event type and state key uniquely identifies a piece
     * of state in Matrix.
     * \sa https://matrix.org/docs/spec/client_server/unstable.html#types-of-room-events
     */
    using StateEventKey = std::pair<QString, QString>;

    template <typename ContentT>
    struct Prev
    {
        template <typename... ContentParamTs>
        explicit Prev(const QJsonObject& unsignedJson,
                      ContentParamTs&&... contentParams)
            : senderId(unsignedJson.value("prev_sender"_ls).toString())
            , content(unsignedJson.value(PrevContentKeyL).toObject(),
                       std::forward<ContentParamTs>(contentParams)...)
        { }

        QString senderId;
        ContentT content;
    };

    template <typename ContentT>
    class StateEvent: public StateEventBase
    {
        public:
            using content_type = ContentT;

            template <typename... ContentParamTs>
            explicit StateEvent(Type type, const QJsonObject& fullJson,
                                ContentParamTs&&... contentParams)<commit_msg>Fix Qt<5.7 build for std::hash<StateEventKey><commit_after>/******************************************************************************
* Copyright (C) 2018 <NAME> <<EMAIL>>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#pragma once

#include "roomevent.h"

namespace QMatrixClient {
    class StateEventBase: public RoomEvent
    {
        public:
            using factory_t = EventFactory<StateEventBase>;

            using RoomEvent::RoomEvent;
            ~StateEventBase() override = default;

            bool isStateEvent() const override { return true; }
            QString replacedState() const;
            void dumpTo(QDebug dbg) const override;

            virtual bool repeatsState() const;
    };
    using StateEventPtr = event_ptr_tt<StateEventBase>;
    using StateEvents = EventsArray<StateEventBase>;

    template <>
    inline bool is<StateEventBase>(const Event& e) { return e.isStateEvent(); }

    /**
     * A combination of event type and state key uniquely identifies a piece
     * of state in Matrix.
     * \sa https://matrix.org/docs/spec/client_server/unstable.html#types-of-room-events
     */
    using StateEventKey = QPair<QString, QString>;

    template <typename ContentT>
    struct Prev
    {
        template <typename... ContentParamTs>
        explicit Prev(const QJsonObject& unsignedJson,
                      ContentParamTs&&... contentParams)
            : senderId(unsignedJson.value("prev_sender"_ls).toString())
            , content(unsignedJson.value(PrevContentKeyL).toObject(),
                       std::forward<ContentParamTs>(contentParams)...)
        { }

        QString senderId;
        ContentT content;
    };

    template <typename ContentT>
    class StateEvent: public StateEventBase
    {
        public:
            using content_type = ContentT;

            template <typename... ContentParamTs>
            explicit StateEvent(Type type, const QJsonObject& fullJson,
                                ContentParamTs&&... contentParams)
{'fraction_non_alphanumeric': 0.10892193308550185, 'fraction_numerical': 0.006691449814126394, 'mean_word_length': 2.8271692745376957, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 32, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6779178', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1310, 'n_words': 479}