/** * Create a message attached to a dedicated chat room; * @param cr the chat room. * @param message text message, NULL if absent. * @param external_body_url the URL given in external body or NULL. * @param state the LinphoneChatMessage.State of the message. * @param time the time_t at which the message has been received/sent. * @param is_read TRUE if the message should be flagged as read, FALSE otherwise. * @param is_incoming TRUE if the message has been received, FALSE otherwise. * @return a new #LinphoneChatMessage */ LinphoneChatMessage* linphone_chat_room_create_message_2( LinphoneChatRoom *cr, const char* message, const char* external_body_url, LinphoneChatMessageState state, time_t time, bool_t is_read, bool_t is_incoming) { LinphoneCore *lc=linphone_chat_room_get_lc(cr); LinphoneChatMessage* msg = ms_new0(LinphoneChatMessage,1); msg->chat_room=(LinphoneChatRoom*)cr; msg->message=message?ms_strdup(message):NULL; msg->external_body_url=external_body_url?ms_strdup(external_body_url):NULL; msg->time=time; msg->state=state; msg->is_read=is_read; if (is_incoming) { msg->dir=LinphoneChatMessageIncoming; linphone_chat_message_set_from(msg, linphone_chat_room_get_peer_address(cr)); linphone_chat_message_set_to(msg, linphone_address_new(linphone_core_get_identity(lc))); } else { msg->dir=LinphoneChatMessageOutgoing; linphone_chat_message_set_to(msg, linphone_chat_room_get_peer_address(cr)); linphone_chat_message_set_from(msg, linphone_address_new(linphone_core_get_identity(lc))); } return msg; }
/* 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); }
/* 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; }