Commit 90b6aa36 authored by Sylvain Berfini's avatar Sylvain Berfini

Added some methods to allow to create a chat message completely and to store a...

Added some methods to allow to create a chat message completely and to store a chat message in database + JNI bindings for these methods
parent 01d35e5b
......@@ -270,6 +270,34 @@ LinphoneChatMessage* linphone_chat_room_create_message(LinphoneChatRoom *cr, con
return msg;
}
/**
* Create a message attached to a dedicated chat room;
* @param cr the chat room.
* @param message text message, NULL if absent.
* @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;
}
/**
* Send a message to peer member of this chat room.
* @param cr #LinphoneChatRoom object
......@@ -368,6 +396,16 @@ const LinphoneAddress* linphone_chat_message_get_from(const LinphoneChatMessage*
return message->from;
}
/**
* Set destination of the message
*@param message #LinphoneChatMessage obj
*@param to #LinphoneAddress destination of this message (copied)
*/
void linphone_chat_message_set_to(LinphoneChatMessage* message, const LinphoneAddress* to) {
if(message->to) linphone_address_destroy(message->to);
message->to=linphone_address_clone(to);
}
/**
* Get destination of the message
*@param message #LinphoneChatMessage obj
......
......@@ -860,6 +860,7 @@ LINPHONE_PUBLIC LinphoneChatRoom * linphone_core_get_or_create_chat_room(Linphon
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAddress *addr);
LINPHONE_PUBLIC void linphone_chat_room_destroy(LinphoneChatRoom *cr);
LINPHONE_PUBLIC LinphoneChatMessage* linphone_chat_room_create_message(LinphoneChatRoom *cr,const char* message);
LINPHONE_PUBLIC 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);
LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr);
LINPHONE_PUBLIC void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg);
LINPHONE_PUBLIC void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangeCb status_cb,void* ud);
......@@ -873,6 +874,7 @@ LINPHONE_PUBLIC LinphoneCore* linphone_chat_room_get_lc(LinphoneChatRoom *cr);
LINPHONE_PUBLIC void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud);
LINPHONE_PUBLIC void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr);
LINPHONE_PUBLIC MSList* linphone_core_get_chat_rooms(LinphoneCore *lc);
LINPHONE_PUBLIC unsigned int linphone_chat_message_store(LinphoneChatMessage *msg);
LINPHONE_PUBLIC const char* linphone_chat_message_state_to_string(const LinphoneChatMessageState state);
LINPHONE_PUBLIC LinphoneChatMessageState linphone_chat_message_get_state(const LinphoneChatMessage* message);
......@@ -880,6 +882,7 @@ LINPHONE_PUBLIC LinphoneChatMessage* linphone_chat_message_clone(const LinphoneC
LINPHONE_PUBLIC void linphone_chat_message_destroy(LinphoneChatMessage* msg);
LINPHONE_PUBLIC void linphone_chat_message_set_from(LinphoneChatMessage* message, const LinphoneAddress* from);
LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_message_get_from(const LinphoneChatMessage* message);
LINPHONE_PUBLIC void linphone_chat_message_set_to(LinphoneChatMessage* message, const LinphoneAddress* from);
LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_message_get_to(const LinphoneChatMessage* message);
LINPHONE_PUBLIC const char* linphone_chat_message_get_external_body_url(const LinphoneChatMessage* message);
LINPHONE_PUBLIC void linphone_chat_message_set_external_body_url(LinphoneChatMessage* message,const char* url);
......
......@@ -2104,6 +2104,27 @@ extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_createLinphoneChatM
return (jlong) chatMessage;
}
extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_createLinphoneChatMessage2(JNIEnv* env
,jobject thiz
,jlong ptr
,jstring jmessage
,jstring jurl
,jint state
,jlong time
,jboolean read
,jboolean incoming) {
const char* message = jmessage?env->GetStringUTFChars(jmessage, NULL):NULL;
const char* url = jurl?env->GetStringUTFChars(jurl, NULL):NULL;
LinphoneChatMessage *chatMessage = linphone_chat_room_create_message_2((LinphoneChatRoom *)ptr, message, url, (LinphoneChatMessageState)state, (time_t)time, read, incoming);
if (jmessage != NULL)
env->ReleaseStringUTFChars(jmessage, message);
if (jurl != NULL)
env->ReleaseStringUTFChars(jurl, url);
return (jlong) chatMessage;
}
extern "C" jint Java_org_linphone_core_LinphoneChatRoomImpl_getUnreadMessagesCount(JNIEnv* env
,jobject thiz
,jlong ptr) {
......@@ -2145,6 +2166,13 @@ extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setUserData(JNIEn
jobject ud = env->NewGlobalRef(thiz);
linphone_chat_message_set_user_data((LinphoneChatMessage*)ptr,(void*) ud);
}
extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_store(JNIEnv* env
,jobject thiz
,jlong ptr) {
linphone_chat_message_store((LinphoneChatMessage*)ptr);
}
extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getText(JNIEnv* env
,jobject thiz
,jlong ptr) {
......
......@@ -125,6 +125,7 @@ void linphone_sql_request_all(sqlite3* db,const char *stmt, LinphoneCore* lc){
unsigned int linphone_chat_message_store(LinphoneChatMessage *msg){
LinphoneCore *lc=linphone_chat_room_get_lc(msg->chat_room);
int id=0;
if (lc->db){
char *peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(msg->chat_room));
char *local_contact=linphone_address_as_string_uri_only(linphone_chat_message_get_local_address(msg));
......
......@@ -737,7 +737,6 @@ void linphone_upnp_destroy(LinphoneCore *lc);
sqlite3 * linphone_message_storage_init();
void linphone_message_storage_init_chat_rooms(LinphoneCore *lc);
#endif
unsigned int linphone_chat_message_store(LinphoneChatMessage *msg);
void linphone_chat_message_store_state(LinphoneChatMessage *msg);
void linphone_core_message_storage_init(LinphoneCore *lc);
void linphone_core_message_storage_close(LinphoneCore *lc);
......
......@@ -130,4 +130,9 @@ public interface LinphoneChatMessage {
* @return true if the message has been sent, false if it has been received
*/
boolean isOutgoing();
/**
* THIS METHOD IS ONLY USED TO IMPORT OLD MESSAGES, DON'T USE IT FOR ANY OTHER USAGE!
*/
void store();
}
......@@ -17,6 +17,9 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.core;
import org.linphone.core.LinphoneChatMessage.State;
/**
*
* A chat room is the place where text messages are exchanged.
......@@ -87,4 +90,10 @@ public interface LinphoneChatRoom {
* @param message to update
*/
void updateUrl(LinphoneChatMessage message);
/**
* Create a LinphoneChatMessage
* @return LinphoneChatMessage object
*/
LinphoneChatMessage createLinphoneChatMessage(String message, String url, State state, long timestamp, boolean isRead, boolean isIncoming);
}
......@@ -12,6 +12,7 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage {
private native int getStatus(long ptr);
private native boolean isRead(long ptr);
private native boolean isOutgoing(long ptr);
private native void store(long ptr);
protected LinphoneChatMessageImpl(long aNativePtr) {
nativePtr = aNativePtr;
......@@ -84,4 +85,8 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage {
public boolean isOutgoing() {
return isOutgoing(nativePtr);
}
public void store() {
store(nativePtr);
}
}
......@@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.core;
import org.linphone.core.LinphoneChatMessage.State;
import org.linphone.core.LinphoneChatMessage.StateListener;
class LinphoneChatRoomImpl implements LinphoneChatRoom {
......@@ -33,6 +34,9 @@ class LinphoneChatRoomImpl implements LinphoneChatRoom {
private native void markAsRead(long ptr);
private native void deleteMessage(long room, long message);
private native void updateUrl(long room, long message);
private native long createLinphoneChatMessage2(long ptr, String message,
String url, int state, long timestamp, boolean isRead,
boolean isIncoming);
protected LinphoneChatRoomImpl(long aNativePtr) {
nativePtr = aNativePtr;
......@@ -49,7 +53,6 @@ class LinphoneChatRoomImpl implements LinphoneChatRoom {
@Override
public void sendMessage(LinphoneChatMessage message, StateListener listener) {
sendMessage2(nativePtr, message.getNativePtr(), listener);
}
@Override
......@@ -94,4 +97,11 @@ class LinphoneChatRoomImpl implements LinphoneChatRoom {
if (message != null)
updateUrl(nativePtr, message.getNativePtr());
}
@Override
public LinphoneChatMessage createLinphoneChatMessage(String message,
String url, State state, long timestamp, boolean isRead,
boolean isIncoming) {
return new LinphoneChatMessageImpl(createLinphoneChatMessage2(nativePtr, message, url, state.value(), timestamp / 1000, isRead, isIncoming));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment