diff --git a/coreapi/chat.c b/coreapi/chat.c index 8dbd60f75..80d00a08e 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -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 **/ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 54391842c..7fb60b6aa 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -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); /** * @} diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 808bc19fd..436e1983e 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -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 diff --git a/coreapi/message_storage.c b/coreapi/message_storage.c index 765543f7a..13e46e147 100644 --- a/coreapi/message_storage.c +++ b/coreapi/message_storage.c @@ -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); } diff --git a/java/common/org/linphone/core/LinphoneChatMessage.java b/java/common/org/linphone/core/LinphoneChatMessage.java index b6b6c30ec..6a539d740 100644 --- a/java/common/org/linphone/core/LinphoneChatMessage.java +++ b/java/common/org/linphone/core/LinphoneChatMessage.java @@ -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(); } diff --git a/java/impl/org/linphone/core/LinphoneChatMessageImpl.java b/java/impl/org/linphone/core/LinphoneChatMessageImpl.java index 8162f67bf..ac308aa92 100644 --- a/java/impl/org/linphone/core/LinphoneChatMessageImpl.java +++ b/java/impl/org/linphone/core/LinphoneChatMessageImpl.java @@ -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); + } }