mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-21 21:28:08 +00:00
Init chatrooms at storage startup using sotred conversations + JNI glue to get chatrooms list
This commit is contained in:
parent
952adab4f8
commit
1ccf89e4fb
7 changed files with 82 additions and 1 deletions
|
|
@ -31,6 +31,15 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns an array of chat rooms
|
||||
* @param lc #LinphoneCore object
|
||||
* @return An array of #LinpĥoneChatRoom
|
||||
**/
|
||||
MSList* linphone_core_get_chat_rooms(LinphoneCore *lc) {
|
||||
return lc->chatrooms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new chat room for messaging from a sip uri like sip:joe@sip.linphone.org
|
||||
* @param lc #LinphoneCore object
|
||||
|
|
|
|||
|
|
@ -865,6 +865,7 @@ LINPHONE_PUBLIC int linphone_chat_room_get_unread_messages_count(LinphoneChatRoo
|
|||
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 const char* linphone_chat_message_state_to_string(const LinphoneChatMessageState state);
|
||||
LINPHONE_PUBLIC LinphoneChatMessageState linphone_chat_message_get_state(const LinphoneChatMessage* message);
|
||||
|
|
|
|||
|
|
@ -2158,6 +2158,24 @@ extern "C" jboolean Java_org_linphone_core_LinphoneChatMessageImpl_isOutgoing(JN
|
|||
return (jboolean) linphone_chat_message_is_outgoing((LinphoneChatMessage*)ptr);
|
||||
}
|
||||
|
||||
extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_getChatRooms(JNIEnv* env
|
||||
,jobject thiz
|
||||
,jlong ptr) {
|
||||
MSList* chats = linphone_core_get_chat_rooms((LinphoneCore*)ptr);
|
||||
int chatsSize = ms_list_size(chats);
|
||||
jlongArray jChats = env->NewLongArray(chatsSize);
|
||||
jlong *jInternalArray = env->GetLongArrayElements(jChats, NULL);
|
||||
|
||||
for (int i = 0; i < chatsSize; i++) {
|
||||
jInternalArray[i] = (unsigned long) (chats->data);
|
||||
chats = chats->next;
|
||||
}
|
||||
|
||||
env->ReleaseLongArrayElements(jChats, jInternalArray, 0);
|
||||
|
||||
return jChats;
|
||||
}
|
||||
|
||||
extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv* env
|
||||
,jobject thiz
|
||||
,jlong ptr
|
||||
|
|
|
|||
|
|
@ -76,6 +76,14 @@ static void create_chat_message(char **argv, void *data){
|
|||
cr->messages_hist=ms_list_prepend(cr->messages_hist,new_message);
|
||||
}
|
||||
|
||||
// Called when fetching all conversations from database
|
||||
static int callback_all(void *data, int argc, char **argv, char **colName){
|
||||
LinphoneCore* lc = (LinphoneCore*) data;
|
||||
char* address = argv[0];
|
||||
linphone_core_create_chat_room(lc, address);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int callback(void *data, int argc, char **argv, char **colName){
|
||||
create_chat_message(argv,data);
|
||||
return 0;
|
||||
|
|
@ -94,13 +102,24 @@ void linphone_sql_request_message(sqlite3 *db,const char *stmt,LinphoneChatRoom
|
|||
void linphone_sql_request(sqlite3* db,const char *stmt){
|
||||
char* errmsg=NULL;
|
||||
int ret;
|
||||
ret=sqlite3_exec(db,stmt,0,0,&errmsg);
|
||||
ret=sqlite3_exec(db,stmt,NULL,NULL,&errmsg);
|
||||
if(ret != SQLITE_OK) {
|
||||
ms_error("linphone_sql_request: error sqlite3_exec(): %s.\n", errmsg);
|
||||
sqlite3_free(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
// Process the request to fetch all chat contacts
|
||||
void linphone_sql_request_all(sqlite3* db,const char *stmt, LinphoneCore* lc){
|
||||
char* errmsg=NULL;
|
||||
int ret;
|
||||
ret=sqlite3_exec(db,stmt,callback_all,lc,&errmsg);
|
||||
if(ret != SQLITE_OK) {
|
||||
ms_error("linphone_sql_request_all: error sqlite3_exec(): %s.\n", errmsg);
|
||||
sqlite3_free(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
void linphone_chat_message_store(LinphoneChatMessage *msg){
|
||||
LinphoneCore *lc=linphone_chat_room_get_lc(msg->chat_room);
|
||||
if (lc->db){
|
||||
|
|
@ -205,6 +224,13 @@ void linphone_create_table(sqlite3* db){
|
|||
}
|
||||
}
|
||||
|
||||
void linphone_message_storage_init_chat_rooms(LinphoneCore *lc) {
|
||||
if (lc->db==NULL) return NULL;
|
||||
char *buf=sqlite3_mprintf("SELECT remoteContact FROM history Group By remoteContact;");
|
||||
linphone_sql_request_all(lc->db,buf,lc);
|
||||
sqlite3_free(buf);
|
||||
}
|
||||
|
||||
void linphone_core_message_storage_init(LinphoneCore *lc){
|
||||
int ret;
|
||||
const char *errmsg;
|
||||
|
|
@ -217,6 +243,9 @@ void linphone_core_message_storage_init(LinphoneCore *lc){
|
|||
}
|
||||
linphone_create_table(db);
|
||||
lc->db=db;
|
||||
|
||||
// Create a chatroom for each contact in the chat history
|
||||
linphone_message_storage_init_chat_rooms(lc);
|
||||
}
|
||||
|
||||
void linphone_core_message_storage_close(LinphoneCore *lc){
|
||||
|
|
@ -244,6 +273,9 @@ MSList *linphone_chat_room_get_history(LinphoneChatRoom *cr,int nb_message){
|
|||
void linphone_chat_room_delete_history(LinphoneChatRoom *cr){
|
||||
}
|
||||
|
||||
void linphone_message_storage_init_chat_rooms(LinphoneCore *lc) {
|
||||
}
|
||||
|
||||
void linphone_core_message_storage_init(LinphoneCore *lc){
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -730,6 +730,7 @@ void linphone_upnp_destroy(LinphoneCore *lc);
|
|||
|
||||
#ifdef MSG_STORAGE_ENABLED
|
||||
sqlite3 * linphone_message_storage_init();
|
||||
void linphone_message_storage_init_chat_rooms(LinphoneCore *lc);
|
||||
#endif
|
||||
void linphone_chat_message_store(LinphoneChatMessage *msg);
|
||||
void linphone_chat_message_store_state(LinphoneChatMessage *msg);
|
||||
|
|
|
|||
|
|
@ -1320,4 +1320,10 @@ public interface LinphoneCore {
|
|||
* @param path the database where the chat messages will be stored.
|
||||
*/
|
||||
public void setChatDatabasePath(String path);
|
||||
|
||||
/**
|
||||
* Gets the chat rooms
|
||||
* @return an array of LinphoneChatRoom
|
||||
*/
|
||||
public LinphoneChatRoom[] getChatRooms();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ class LinphoneCoreImpl implements LinphoneCore {
|
|||
private native void setInCallTimeout(long nativePtr, int timeout);
|
||||
private native void setPrimaryContact(long nativePtr, String displayName, String username);
|
||||
private native void setChatDatabasePath(long nativePtr, String path);
|
||||
private native long[] getChatRooms(long nativePtr);
|
||||
|
||||
LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException {
|
||||
mListener=listener;
|
||||
|
|
@ -984,4 +985,17 @@ class LinphoneCoreImpl implements LinphoneCore {
|
|||
public void setChatDatabasePath(String path) {
|
||||
setChatDatabasePath(nativePtr, path);
|
||||
}
|
||||
|
||||
public synchronized LinphoneChatRoom[] getChatRooms() {
|
||||
long[] typesPtr = getChatRooms(nativePtr);
|
||||
if (typesPtr == null) return null;
|
||||
|
||||
LinphoneChatRoom[] proxies = new LinphoneChatRoom[typesPtr.length];
|
||||
|
||||
for (int i=0; i < proxies.length; i++) {
|
||||
proxies[i] = new LinphoneChatRoomImpl(typesPtr[i]);
|
||||
}
|
||||
|
||||
return proxies;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue