Commit 952adab4 authored by Sylvain Berfini's avatar Sylvain Berfini

Added more JNI bindings for ChatMessages + few fixes in messaeg_storage (some...

Added more JNI bindings for ChatMessages + few fixes in messaeg_storage (some properties weren't set when read from database)
parent 389922ac
......@@ -181,6 +181,7 @@ void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessag
msg->time=sal_msg->time;
msg->state=LinphoneChatMessageStateDelivered;
msg->is_read=FALSE;
msg->dir=LinphoneChatMessageIncoming;
ch=sal_op_get_recv_custom_header(op);
if (ch) msg->custom_headers=sal_custom_header_clone(ch);
......@@ -401,6 +402,22 @@ const char * linphone_chat_message_get_custom_header(LinphoneChatMessage* messag
return sal_custom_header_find(message->custom_headers,header_name);
}
/**
* Returns TRUE if the message has been read, otherwise returns FALSE.
* @param message the message
**/
bool_t linphone_chat_message_is_read(LinphoneChatMessage* message) {
return message->is_read;
}
/**
* Returns TRUE if the message has been sent, returns FALSE if the message has been received.
* @param message the message
**/
bool_t linphone_chat_message_is_outgoing(LinphoneChatMessage* message) {
return message->dir == LinphoneChatMessageOutgoing;
}
/**
* Duplicate a LinphoneChatMessage
**/
......
......@@ -884,6 +884,8 @@ LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_message_get_peer_address(Li
LINPHONE_PUBLIC LinphoneAddress *linphone_chat_message_get_local_address(const LinphoneChatMessage* message);
LINPHONE_PUBLIC void linphone_chat_message_add_custom_header(LinphoneChatMessage* message, const char *header_name, const char *header_value);
LINPHONE_PUBLIC const char * linphone_chat_message_get_custom_header(LinphoneChatMessage* message, const char *header_name);
LINPHONE_PUBLIC bool_t linphone_chat_message_is_read(LinphoneChatMessage* message);
LINPHONE_PUBLIC bool_t linphone_chat_message_is_outgoing(LinphoneChatMessage* message);
/**
* @}
......
......@@ -523,7 +523,7 @@ public:
,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
,message ? env->NewStringUTF(message) : NULL);
}
static void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *msg) {
static void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *msg) {
JNIEnv *env = 0;
jint result = jvm->AttachCurrentThread(&env,NULL);
if (result != 0) {
......@@ -2140,6 +2140,24 @@ extern "C" jlong Java_org_linphone_core_LinphoneChatMessageImpl_getTime(JNIEnv*
return (jlong) linphone_chat_message_get_time((LinphoneChatMessage*)ptr);
}
extern "C" jint Java_org_linphone_core_LinphoneChatMessageImpl_getStatus(JNIEnv* env
,jobject thiz
,jlong ptr) {
return (jint) linphone_chat_message_get_state((LinphoneChatMessage*)ptr);
}
extern "C" jboolean Java_org_linphone_core_LinphoneChatMessageImpl_isRead(JNIEnv* env
,jobject thiz
,jlong ptr) {
return (jboolean) linphone_chat_message_is_read((LinphoneChatMessage*)ptr);
}
extern "C" jboolean Java_org_linphone_core_LinphoneChatMessageImpl_isOutgoing(JNIEnv* env
,jobject thiz
,jlong ptr) {
return (jboolean) linphone_chat_message_is_outgoing((LinphoneChatMessage*)ptr);
}
extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv* env
,jobject thiz
,jlong ptr
......
......@@ -48,8 +48,10 @@ static void create_chat_message(char **argv, void *data){
char tmp2[80]={0};
if(atoi(argv[3])==LinphoneChatMessageIncoming){
new_message->dir=LinphoneChatMessageIncoming;
from=linphone_address_new(argv[2]);
} else {
new_message->dir=LinphoneChatMessageOutgoing;
from=linphone_address_new(argv[1]);
}
linphone_chat_message_set_from(new_message,from);
......@@ -69,6 +71,7 @@ static void create_chat_message(char **argv, void *data){
ret.tm_isdst=-1;
}
new_message->time=argv[5]!=NULL ? mktime(&ret) : time(NULL);
new_message->is_read=atoi(argv[6]);
new_message->state=atoi(argv[7]);
cr->messages_hist=ms_list_prepend(cr->messages_hist,new_message);
}
......
......@@ -112,4 +112,22 @@ public interface LinphoneChatMessage {
* @return the time in milliseconds
*/
long getTime();
/**
* Gets the status of the message
* @return the status of the message
*/
LinphoneChatMessage.State getStatus();
/**
* Returns wether or not the message has been read
* @return true if it has been read, flase otherwise
*/
boolean isRead();
/**
* Returns wether the message has been sent or received
* @return true if the message has been sent, false if it has been received
*/
boolean isOutgoing();
}
......@@ -9,6 +9,9 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage {
private native void setExternalBodyUrl(long ptr, String url);
private native long getFrom(long ptr);
private native long getTime(long ptr);
private native int getStatus(long ptr);
private native boolean isRead(long ptr);
private native boolean isOutgoing(long ptr);
protected LinphoneChatMessageImpl(long aNativePtr) {
nativePtr = aNativePtr;
......@@ -69,4 +72,16 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage {
public long getTime() {
return getTime(nativePtr) * 1000; // Need milliseconds, not seconds
}
public LinphoneChatMessage.State getStatus() {
return LinphoneChatMessage.State.fromInt(getStatus(nativePtr));
}
public boolean isRead() {
return isRead(nativePtr);
}
public boolean isOutgoing() {
return isOutgoing(nativePtr);
}
}
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