ChatMessage.cpp 4.26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
ChatMessage.cpp
Copyright (C) 2015  Belledonne Communications, Grenoble, France
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 2
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, write to the Free Software
14
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
15 16 17 18 19 20
*/

#include "Address.h"
#include "ApiLock.h"
#include "ChatMessage.h"

21
using namespace BelledonneCommunications::Linphone::Native;
22

23
Platform::String^ ChatMessage::AppData::get()
24 25
{
	API_LOCK;
26
	return Utils::cctops(linphone_chat_message_get_appdata(this->message));
27 28
}

29
void ChatMessage::AppData::set(Platform::String^ appData)
30 31
{
	API_LOCK;
32
	linphone_chat_message_set_appdata(this->message, Utils::pstoccs(appData));
33 34
}

35
Platform::String^ ChatMessage::ExternalBodyUrl::get()
36 37
{
	API_LOCK;
38
	return Utils::cctops(linphone_chat_message_get_external_body_url(this->message));
39 40
}

41
void ChatMessage::ExternalBodyUrl::set(Platform::String^ url)
42 43
{
	API_LOCK;
44
	const char* body = Utils::pstoccs(url);
45 46 47 48
	linphone_chat_message_set_external_body_url(this->message, body);
	delete(body);
}

49
Platform::String^ ChatMessage::FileTransferFilepath::get()
50 51
{
	API_LOCK;
52
	return Utils::cctops(linphone_chat_message_get_file_transfer_filepath(this->message));
53 54
}

55
Platform::String^ ChatMessage::FileTransferName::get()
56 57 58 59 60 61
{
	API_LOCK;
	Platform::String^ fileName;
	const LinphoneContent *content = linphone_chat_message_get_file_transfer_information(this->message);
	if (content)
	{
62
		fileName = Utils::cctops(linphone_content_get_name(content));
63 64 65 66
	}
	return fileName;
}

67
Address^ ChatMessage::FromAddress::get()
68 69
{
	API_LOCK;
70
	return (Address^) Utils::CreateAddress((void*)linphone_chat_message_get_from_address(this->message));
71 72
}

73
Platform::Boolean ChatMessage::IsOutgoing::get()
74 75 76 77 78
{
	API_LOCK;
	return (linphone_chat_message_is_outgoing(this->message) == TRUE);
}

79
Platform::Boolean ChatMessage::IsRead::get()
80 81 82 83 84
{
	API_LOCK;
	return (linphone_chat_message_is_read(this->message) == TRUE);
}

85
Address^ ChatMessage::PeerAddress::get()
86 87
{
	API_LOCK;
88
	return (Address^) Utils::CreateAddress((void*)linphone_chat_message_get_peer_address(this->message));
89 90
}

91
ChatMessageState ChatMessage::State::get()
92 93
{
	API_LOCK;
94
	return (ChatMessageState) linphone_chat_message_get_state(this->message);
95 96
}

97
Platform::String^ ChatMessage::Text::get()
98 99
{
	API_LOCK;
100
	return Utils::cctops(linphone_chat_message_get_text(this->message));
101 102
}

103
int64 ChatMessage::Time::get()
104 105 106 107 108 109 110
{
	API_LOCK;
	return linphone_chat_message_get_time(this->message);
}

static void status_cb(::LinphoneChatMessage* msg, ::LinphoneChatMessageState state, void* ud)
{
111 112
	RefToPtrProxy<ChatMessageListener^> *proxy = reinterpret_cast< RefToPtrProxy<ChatMessageListener^> *>(ud);
	ChatMessageListener^ listener = (proxy) ? proxy->Ref() : nullptr;
113 114

	if (listener != nullptr) {
115 116
		ChatMessage^ lChatMessage = (ChatMessage^)Utils::GetChatMessage(msg);
		listener->MessageStateChanged(lChatMessage, (ChatMessageState) state);
117 118 119
	}
}

120
void ChatMessage::StartFileDownload(ChatMessageListener^ listener, Platform::String^ filepath)
121 122 123 124 125 126 127 128 129
{
	API_LOCK;
	RefToPtrProxy<ChatMessageListener^> *listenerPtr = new RefToPtrProxy<ChatMessageListener^>(listener);
	const char *cfilepath = Utils::pstoccs(filepath);
	linphone_chat_message_set_file_transfer_filepath(this->message, cfilepath);
	linphone_chat_message_start_file_download(this->message, status_cb, listenerPtr);
	delete(cfilepath);
}

130
ChatMessage::ChatMessage(::LinphoneChatMessage *cm)
131 132 133 134
	: message(cm)
{
	API_LOCK;
	RefToPtrProxy<ChatMessage^> *chat_message = new RefToPtrProxy<ChatMessage^>(this);
135
	linphone_chat_message_ref(message);
136 137 138
	linphone_chat_message_set_user_data(this->message, chat_message);
}

139
ChatMessage::~ChatMessage()
140 141 142 143 144 145
{
	API_LOCK;
	linphone_chat_message_unref(message);
	RefToPtrProxy<ChatMessage^> *chat_message = reinterpret_cast< RefToPtrProxy<ChatMessage^> *>(linphone_chat_message_get_user_data(this->message));
	delete chat_message;
}