Example #1
0
/* DB layout:
 * | 0  | storage_id
 * | 1  | localContact
 * | 2  | remoteContact
 * | 3  | direction flag
 * | 4  | message
 * | 5  | time (unused now, used to be string-based timestamp)
 * | 6  | read flag
 * | 7  | status
 * | 8  | external body url
 * | 9  | utc timestamp
 * | 10 | app data text
 * | 11 | linphone content
 */
static void create_chat_message(char **argv, void *data){
	LinphoneChatRoom *cr = (LinphoneChatRoom *)data;
	LinphoneAddress *from;
	LinphoneAddress *to;

	unsigned int storage_id = atoi(argv[0]);

	// check if the message exists in the transient list, in which case we should return that one.
	LinphoneChatMessage* new_message = get_transient_message(cr, storage_id);
	if( new_message == NULL ){
		new_message = linphone_chat_room_create_message(cr, argv[4]);

		if(atoi(argv[3])==LinphoneChatMessageIncoming){
			new_message->dir=LinphoneChatMessageIncoming;
			from=linphone_address_new(argv[2]);
			to=linphone_address_new(argv[1]);
		} else {
			new_message->dir=LinphoneChatMessageOutgoing;
			from=linphone_address_new(argv[1]);
			to=linphone_address_new(argv[2]);
		}
		linphone_chat_message_set_from(new_message,from);
		linphone_address_destroy(from);
		if (to){
			linphone_chat_message_set_to(new_message,to);
			linphone_address_destroy(to);
		}

		if( argv[9] != NULL ){
			new_message->time = (time_t)atol(argv[9]);
		} else {
			new_message->time = time(NULL);
		}

		new_message->is_read=atoi(argv[6]);
		new_message->state=atoi(argv[7]);
		new_message->storage_id=storage_id;
		new_message->external_body_url= argv[8] ? ms_strdup(argv[8])  : NULL;
		new_message->appdata          = argv[10]? ms_strdup(argv[10]) : NULL;

		if (argv[11] != NULL) {
			int id = atoi(argv[11]);
			if (id >= 0) {
				fetch_content_from_database(cr->lc->db, new_message, id);
			}
		}
	}
	cr->messages_hist=ms_list_prepend(cr->messages_hist,new_message);
}
Example #2
0
/* DB layout:
 * | 0  | storage_id
 * | 1  | localContact
 * | 2  | remoteContact
 * | 3  | direction flag
 * | 4  | message
 * | 5  | time (unused now, used to be string-based timestamp)
 * | 6  | read flag
 * | 7  | status
 * | 8  | external body url
 * | 9  | utc timestamp
 * | 10 | app data text
 * | 11 | linphone content id
 */
static int create_chat_message(void *data, int argc, char **argv, char **colName){
	LinphoneChatRoom *cr = (LinphoneChatRoom *)data;
	unsigned int storage_id = atoi(argv[0]);

	// check if the message exists in the transient list, in which case we should return that one.
	LinphoneChatMessage* new_message = get_transient_message(cr, storage_id);
	if( new_message == NULL ){
		LinphoneAddress *local_addr=linphone_address_new(argv[1]);
		new_message = linphone_chat_room_create_message(cr, argv[4]);

		if(atoi(argv[3])==LinphoneChatMessageIncoming){
			new_message->dir=LinphoneChatMessageIncoming;
			linphone_chat_message_set_from(new_message,linphone_chat_room_get_peer_address(cr));
			new_message->to = local_addr; /*direct assignation to avoid a copy*/
		} else {
			new_message->dir=LinphoneChatMessageOutgoing;
			new_message->from = local_addr; /*direct assignation to avoid a copy*/
			linphone_chat_message_set_to(new_message,linphone_chat_room_get_peer_address(cr));
		}

		new_message->time = (time_t)atol(argv[9]);
		new_message->is_read=atoi(argv[6]);
		new_message->state=atoi(argv[7]);
		new_message->storage_id=storage_id;
		new_message->external_body_url= ms_strdup(argv[8]);
		new_message->appdata = ms_strdup(argv[10]);

		if (argv[11] != NULL) {
			int id = atoi(argv[11]);
			if (id >= 0) {
				fetch_content_from_database(cr->lc->db, new_message, id);
			}
		}
	}
	cr->messages_hist=ms_list_prepend(cr->messages_hist,new_message);

	return 0;
}