diff options
| author | Robert Pösel <robyer@seznam.cz> | 2014-09-19 15:42:26 +0000 | 
|---|---|---|
| committer | Robert Pösel <robyer@seznam.cz> | 2014-09-19 15:42:26 +0000 | 
| commit | 4279c9e641b798b68eb4d520228fc37445264c78 (patch) | |
| tree | bfae40114dbdb5e7cf826c3e1f8c42afcf097be4 | |
| parent | 9ed60637b814fb9303b4bebefacf8e88e5b52383 (diff) | |
Facebook: Receive info (message) about missed video call
git-svn-id: http://svn.miranda-ng.org/main/trunk@10520 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
| -rw-r--r-- | protocols/FacebookRM/src/constants.h | 8 | ||||
| -rw-r--r-- | protocols/FacebookRM/src/entities.h | 3 | ||||
| -rw-r--r-- | protocols/FacebookRM/src/json.cpp | 50 | ||||
| -rw-r--r-- | protocols/FacebookRM/src/process.cpp | 9 | ||||
| -rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 11 | 
5 files changed, 69 insertions, 12 deletions
| diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index 1e2c9fc1a6..d2fd847e69 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -100,6 +100,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  #define SEND_MESSAGE_ERROR						1
  #define SEND_MESSAGE_CANCEL						-1
 +// Event types
 +#define FACEBOOK_EVENTTYPE_CALL					10010
 +
  // Facebook request types // TODO: Provide MS_ and release in FB plugin API?
  enum RequestType {
  	REQUEST_LOGIN,				// connecting physically
 @@ -164,6 +167,11 @@ enum ClientType {  	CLIENT_MOBILE	 = 5	// Facebook on unknown mobile client (can't be determined for offline contacts)
  };
 +enum MessageType {
 +	MESSAGE = 1,	// Classic message
 +	CALL	= 2,	// Video call
 +};
 +
  typedef struct {
  	const char *name;
  	const char *id;
 diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h index 0be3d2d396..94fb9196f3 100644 --- a/protocols/FacebookRM/src/entities.h +++ b/protocols/FacebookRM/src/entities.h @@ -110,6 +110,7 @@ struct facebook_message  	bool isIncoming;  	bool isUnread;  	bool isChat; +	MessageType type;  	int flag_; @@ -119,6 +120,7 @@ struct facebook_message  		this->time = 0;  		this->isUnread = this->isIncoming = true;  		this->isChat = false; +		this->type = MESSAGE;  		this->flag_ = 0;  	} @@ -133,6 +135,7 @@ struct facebook_message  		this->isIncoming = msg.isIncoming;  		this->isUnread = msg.isUnread;  		this->isChat = msg.isChat; +		this->type = msg.type;  		this->flag_ = msg.flag_;  	}  }; diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 9590f0878d..367eb394fc 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -686,9 +686,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa  				proto->NotifyEvent()  			}*/  		} else if (t == "mercury") { -			// rename multi user chat, ... -			if (!proto->m_enableChat) -				continue; +			// rename multi user chat, video call, ...  			JSONNODE *actions_ = json_get(it, "actions");  			if (actions_ == NULL) @@ -700,18 +698,50 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa  				JSONNODE *thread_id_ = json_get(action_, "thread_id");  				JSONNODE *log_body_ = json_get(action_, "log_message_body");  				JSONNODE *log_data_ = json_get(action_, "log_message_data"); -				if (!log_data_ || !thread_id_) +				JSONNODE *log_type_ = json_get(action_, "log_message_type"); +				if (!log_data_ || !log_body_ || !thread_id_ || !log_type_)  					continue; -				JSONNODE *name_ = json_get(log_data_, "name"); -				std::string name = json_as_pstring(name_);  				std::tstring thread_id = json_as_string(thread_id_); -				std::string message = json_as_pstring(log_body_); +				std::string type = json_as_pstring(log_type_); +				std::string message_text = json_as_pstring(log_body_); + +				if (type == "log:video-call") { +					JSONNODE *other_user_fbid_ = json_get(action_, "other_user_fbid"); +					std::string id = json_as_pstring(other_user_fbid_); + +					JSONNODE *timestamp = json_get(action_, "timestamp"); +					JSONNODE *mid_ = json_get(action_, "message_id"); +					 +					std::string message_id = json_as_pstring(mid_); +					 +					facebook_message* message = new facebook_message(); +					message->isChat = false; +					message->isUnread = true; +					message->isIncoming = (id != proto->facy.self_.user_id); +					message->message_text = message_text; +					message->time = utils::time::fix_timestamp(json_as_float(timestamp)); +					message->user_id = id; +					message->message_id = message_id; +					message->sender_name = ""; +					message->thread_id = json_as_pstring(thread_id_); +					message->type = CALL; -				// proto->RenameChat(thread_id.c_str(), name.c_str()); // this don't work, why? -				proto->setStringUtf(proto->ChatIDToHContact(thread_id), FACEBOOK_KEY_NICK, name.c_str()); +					messages->push_back(message); +				} else { +					// TODO: check for other types, now we expect this is rename chat -				proto->UpdateChat(thread_id.c_str(), NULL, NULL, message.c_str()); +					if (!proto->m_enableChat) +						continue; + +					JSONNODE *name_ = json_get(log_data_, "name"); +					std::string name = json_as_pstring(name_); + +					// proto->RenameChat(thread_id.c_str(), name.c_str()); // this don't work, why? +					proto->setStringUtf(proto->ChatIDToHContact(thread_id), FACEBOOK_KEY_NICK, name.c_str()); + +					proto->UpdateChat(thread_id.c_str(), NULL, NULL, message_text.c_str()); +				}  			}  		} else if (t == "notifications_read" || t == "notifications_seen") {  			JSONNODE *alerts = json_get(it, "alert_ids"); diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index b10b9165b7..a2934dd1b3 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -706,7 +706,7 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message*> messages, boo  			if (!tid || strcmp(tid, messages[i]->thread_id.c_str()))  				setString(hContact, FACEBOOK_KEY_TID, messages[i]->thread_id.c_str()); -			if (messages[i]->isIncoming && messages[i]->isUnread) { +			if (messages[i]->isIncoming && messages[i]->isUnread && messages[i]->type == MESSAGE) {  				PROTORECVEVENT recv = { 0 };  				recv.flags = PREF_UTF;  				recv.szMessage = const_cast<char*>(messages[i]->message_text.c_str()); @@ -715,7 +715,12 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message*> messages, boo  			} else {  				DBEVENTINFO dbei = { 0 };  				dbei.cbSize = sizeof(dbei); -				dbei.eventType = EVENTTYPE_MESSAGE; +				 +				if (messages[i]->type == CALL) +					dbei.eventType = FACEBOOK_EVENTTYPE_CALL; +				else +					dbei.eventType = EVENTTYPE_MESSAGE; +				  				dbei.flags = DBEF_UTF;  				if (!messages[i]->isIncoming) diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index eed51d5316..2abb8323ee 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -92,6 +92,17 @@ FacebookProto::FacebookProto(const char* proto_name,const TCHAR* username) :  	// Set all contacts offline -- in case we crashed  	SetAllContactStatuses(ID_STATUS_OFFLINE); + +	// register special type of event +	// there's no need to declare the special service for getting text +	// because a blob contains only text +	DBEVENTTYPEDESCR evtype = { sizeof(evtype) }; +	evtype.module = m_szModuleName; +	evtype.eventType = FACEBOOK_EVENTTYPE_CALL; +	evtype.descr = LPGEN("Video call"); +	evtype.eventIcon = GetIconHandle("facebook"); +	evtype.flags = DETF_HISTORY | DETF_MSGWINDOW; +	CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&evtype);  }  FacebookProto::~FacebookProto() | 
