summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp
blob: 8f5fd2dcc9d7d72d480d74797d015b644bb7520b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * FMessage.cpp
 *
 *  Created on: 02/07/2012
 *      Author: Antonio
 */

#include "../common.h" // #TODO Remove Miranda-dependency

#include "utilities.h"

FMessage::FMessage() :
	key("", false, "")
{
	this->timestamp = 0;
	this->media_wa_type = 0;
	this->longitude = 0;
	this->latitude = 0;
	this->media_duration_seconds = 0;
	this->media_size = 0;
}

FMessage::FMessage(const std::string &remote_jid, bool from_me, const std::string &id) :
	key(remote_jid, from_me, id)
{
	this->timestamp = time(NULL);
	this->media_wa_type = 0;
	this->longitude = 0;
	this->latitude = 0;
	this->media_duration_seconds = 0;
	this->media_size = 0;
}

std::string FMessage::getMessage_WA_Type_StrValue(unsigned char type)
{
	switch (type) {
	case FMessage::WA_TYPE_UNDEFINED:
		return "";
	case FMessage::WA_TYPE_SYSTEM:
		return "system";
	case FMessage::WA_TYPE_AUDIO:
		return "audio";
	case FMessage::WA_TYPE_CONTACT:
		return "vcard";
	case FMessage::WA_TYPE_IMAGE:
		return "image";
	case FMessage::WA_TYPE_LOCATION:
		return "location";
	case FMessage::WA_TYPE_VIDEO:
		return "video";
	}

	return "";
}

FMessage::~FMessage()
{
}

Key::Key(const std::string &remote_jid, bool from_me, const std::string &id)
{
	this->remote_jid = remote_jid;
	this->from_me = from_me;
	this->id = id;
}

std::string Key::toString()
{
	return "Key[id=" + id + ", from_me=" + (from_me ? "true" : "false") + ", remote_jid=" + remote_jid + "]";
}


unsigned char FMessage::getMessage_WA_Type(const std::string &type)
{
	if (type.empty())
		return WA_TYPE_UNDEFINED;

	std::string typeLower = type;
	std::transform(typeLower.begin(), typeLower.end(), typeLower.begin(), ::tolower);
	if (typeLower.compare("system") == 0)
		return WA_TYPE_SYSTEM;
	if (typeLower.compare("image") == 0)
		return WA_TYPE_IMAGE;
	if (typeLower.compare("audio") == 0)
		return WA_TYPE_AUDIO;
	if (typeLower.compare("video") == 0)
		return WA_TYPE_VIDEO;
	if (typeLower.compare("vcard") == 0)
		return WA_TYPE_CONTACT;
	if (typeLower.compare("location") == 0)
		return WA_TYPE_LOCATION;

	return WA_TYPE_UNDEFINED;
}