Conversation.h 3.92 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/**************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux                                *
* Author: Jger Nicolas <nicolas.jager@savoirfairelinux.com>              *
* Author: Traczyk Andreas <traczyk.andreas@savoirfairelinux.com>          *
*                                                                         *
* This program is free software; you can redistribute it and/or modify    *
* it under the terms of the GNU General Public License as published by    *
* the Free Software Foundation; either version 3 of the License, or       *
* (at your option) any later version.                                     *
*                                                                         *
* This program 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 General Public License for more details.                            *
*                                                                         *
* You should have received a copy of the GNU General Public License       *
* along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
**************************************************************************/
19 20
#pragma once

21 22 23
using namespace Platform;
using namespace Windows::UI::Xaml::Data;

24 25 26 27 28
/* strings required by Windows::Data::Json. Defined here on puprose */
String^ conversationKey = "conversation";
String^ messageKey      = "message";
String^ fromContactKey  = "fromContact";
String^ payloadKey      = "payload";
29 30 31
String^ timeReceivedKey = "timeReceived";
String^ isReceivedKey   = "isReceived";
String^ messageIdKey    = "messageId";
32

33 34
namespace RingClientUWP
{
35 36

public ref class ConversationMessage sealed : public INotifyPropertyChanged
37 38
{
public:
39 40 41
    void raiseNotifyPropertyChanged(String^ propertyName);
    virtual event PropertyChangedEventHandler^ PropertyChanged;

42 43
    property bool FromContact;
    property String^ Payload;
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    property std::time_t TimeReceived;
    property bool IsReceived;
    property String^ MessageId;
    property int MessageIndex;

    property String^ MessageAvatar {
        String^ get() {
            return getMessageAvatar();
        }
    }

    property SolidColorBrush^ MessageAvatarColorBrush {
        SolidColorBrush^ get() {
            return getMessageAvatarColorBrush();
        }
    }

    property String^ MessageAvatarInitial {
        String^ get() {
            return getMessageAvatarInitial();
        }
    }

    property uint64_t MessageIdInteger {
        uint64_t get() {
            return strtoull(Utils::toString(MessageId).c_str(), nullptr, 0);
        }
    }
72 73 74

    /* functions */
    JsonObject^ ToJsonObject();
75 76 77 78 79 80 81
    String^ getMessageAvatar();
    SolidColorBrush^ getMessageAvatarColorBrush();
    String^ getMessageAvatarInitial();

protected:
    void NotifyPropertyChanged(String^ propertyName);

82 83 84 85 86 87
};

public ref class Conversation sealed
{
public:
    Conversation();
88 89 90 91 92 93 94

    /* functions */
    void addMessage(bool fromContact,
                    String^ payload,
                    std::time_t timeReceived,
                    bool isReceived,
                    String^ MessageId);
95

96 97
internal:
    /* properties */
98 99
    property IObservableVector<ConversationMessage^>^ _messages {
        IObservableVector<ConversationMessage^>^ get() {
100 101 102 103
            return messagesList_;
        }
    }

104 105 106 107 108
    /* functions */
    void update(const std::vector<std::string>& properties);
    ConversationMessage^ findMessage(uint64_t messageId);
    unsigned getMessageIndex(uint64_t messageId);

109
private:
110
    /* members */
111 112
    IObservableVector<ConversationMessage^>^ messagesList_;
    ListBox^ messageListBox_;
113 114 115 116 117 118

};
#define MSG_FROM_CONTACT true
#define MSG_FROM_ME false
}