]> sjero.net Git - linphone/commitdiff
Add time in LinphoneChatMessage and SalMessage
authorMargaux Clerc <margaux.clerc@belledonne-communications.com>
Wed, 30 Jan 2013 14:46:28 +0000 (15:46 +0100)
committerMargaux Clerc <margaux.clerc@belledonne-communications.com>
Wed, 30 Jan 2013 14:48:49 +0000 (15:48 +0100)
coreapi/callbacks.c
coreapi/chat.c
coreapi/linphonecore.h
coreapi/private.h
coreapi/sal.h
coreapi/sal_eXosip2.c
coreapi/sal_eXosip2_presence.c
gtk/chat.c
gtk/linphone.h
gtk/main.c
gtk/main.ui

index 8baad9af2503d7cca51b1c20ab6ac315319da158..552d34804a67cc6d2ffd4cf549ed2740c7950e76 100644 (file)
@@ -845,7 +845,7 @@ static bool_t is_duplicate_msg(LinphoneCore *lc, const char *msg_id){
 static void text_received(Sal *sal, const SalMessage *msg){
        LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
        if (is_duplicate_msg(lc,msg->message_id)==FALSE){
-               linphone_core_message_received(lc,msg->from,msg->text,msg->url);
+               linphone_core_message_received(lc,msg);
        }
 }
 
index 00f237377aabc6f2ae87b9f15bb17850fb062e80..c502efa9f0f1cc51dd6d6bf071fb9521dcf647e8 100644 (file)
@@ -103,13 +103,13 @@ void linphone_chat_room_message_received(LinphoneChatRoom *cr, LinphoneCore *lc,
        
 }
 
-void linphone_core_message_received(LinphoneCore *lc, const char *from, const char *raw_msg,const char* external_url){
+void linphone_core_message_received(LinphoneCore *lc, const SalMessage *sal_msg){
        MSList *elem;
        LinphoneChatRoom *cr=NULL;
        LinphoneAddress *addr;
        char *cleanfrom;
        LinphoneChatMessage* msg;
-       addr=linphone_address_new(from);
+       addr=linphone_address_new(sal_msg->from);
        linphone_address_clean(addr);
        for(elem=lc->chatrooms;elem!=NULL;elem=ms_list_next(elem)){
                cr=(LinphoneChatRoom*)elem->data;
@@ -123,10 +123,12 @@ void linphone_core_message_received(LinphoneCore *lc, const char *from, const ch
                /* create a new chat room */
                cr=linphone_core_create_chat_room(lc,cleanfrom);
        }
-       msg = linphone_chat_room_create_message(cr, raw_msg);
+       msg = linphone_chat_room_create_message(cr, sal_msg->text);
        linphone_chat_message_set_from(msg, cr->peer_url);
-       if (external_url) {
-               linphone_chat_message_set_external_body_url(msg, external_url);
+       msg->time=sal_msg->time;
+       
+       if (sal_msg->url) {
+               linphone_chat_message_set_external_body_url(msg, sal_msg->url);
        }
        linphone_address_destroy(addr);
        linphone_chat_room_message_received(cr,lc,msg);
@@ -221,6 +223,11 @@ void linphone_chat_message_set_from(LinphoneChatMessage* message, const Linphone
 LinphoneAddress* linphone_chat_message_get_from(const LinphoneChatMessage* message) {
        return message->from;
 }
+
+time_t linphone_chat_message_get_time(const LinphoneChatMessage* message) {
+       return message->time;
+}
+
 const char * linphone_chat_message_get_text(const LinphoneChatMessage* message) {
        return message->message;
 }
index 6eb401638b2849787bb987ea5e525e99a7697f93..f780d2f658b76525af1ae4ed13fab42a6f17a313 100644 (file)
@@ -735,7 +735,14 @@ void linphone_chat_message_set_external_body_url(LinphoneChatMessage* message,co
  * Get text part of this message
  * @return text or NULL if no text.
  */
-const char * linphone_chat_message_get_text(const LinphoneChatMessage* message);       
+const char * linphone_chat_message_get_text(const LinphoneChatMessage* message);
+
+/**
+ * Get the time the message was sent
+ * @return time_t or NULL if no time
+ */
+time_t linphone_chat_message_get_time(const LinphoneChatMessage* message);
+
 /**
  * user pointer get function
  */
index c421b2bc6f1ef6acc8b4b831c6bc704dac852fb0..ca79a722f7acef67c7c68c92dd477e7d8f38d128 100644 (file)
@@ -103,6 +103,7 @@ struct _LinphoneChatMessage {
        void* message_userdata;
        char* external_body_url;
        LinphoneAddress* from;
+       time_t time;
 };
 
 typedef struct StunCandidate{
@@ -279,7 +280,7 @@ void linphone_proxy_config_write_to_config_file(struct _LpConfig* config,Linphon
 
 int linphone_proxy_config_normalize_number(LinphoneProxyConfig *cfg, const char *username, char *result, size_t result_len);
 
-void linphone_core_message_received(LinphoneCore *lc, const char *from, const char *raw_msg,const char* external_url);
+void linphone_core_message_received(LinphoneCore *lc, const SalMessage *msg);
 
 void linphone_core_play_tone(LinphoneCore *lc);
 
index b751dfc0d43cf0616e277c547f9f4f973eb5e71c..46294b6038b86eb32bf0f420958436a729580e6b 100644 (file)
@@ -195,6 +195,7 @@ typedef struct SalMessage{
        const char *text;
        const char *url;
        const char *message_id;
+       time_t time;
 }SalMessage;
 
 #define SAL_MEDIA_DESCRIPTION_MAX_MESSAGE_ATTRIBUTES 5
index 076f3d934405384b86739d54fa204c7fad9b1325..91ec04679137e83817efeaeda06d335d8af63fff 100644 (file)
@@ -52,7 +52,6 @@ void sal_get_default_local_ip(Sal *sal, int address_family,char *ip, size_t iple
        }
 }
 
-
 static SalOp * sal_find_call(Sal *sal, int cid){
        const MSList *elem;
        SalOp *op;
@@ -1766,6 +1765,9 @@ static bool_t comes_from_local_if(osip_message_t *msg){
        return FALSE;
 }
 
+static const char *days[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};\r
+static const char *months[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
+
 static void text_received(Sal *sal, eXosip_event_t *ev){
        osip_body_t *body=NULL;
        char *from=NULL,*msg=NULL;
@@ -1775,6 +1777,26 @@ static void text_received(Sal *sal, eXosip_event_t *ev){
        int external_body_size=0;
        SalMessage salmsg;
        char message_id[256]={0};
+       osip_header_t *date=NULL;
+       struct tm ret={};
+       char tmp1[80]={0};
+       char tmp2[80]={0};
+       int i,j;
+
+       osip_message_get_date(ev->request,0,&date);
+       if(date==NULL){
+               ms_error("Could not get the date of message");
+               return;
+       }
+       sscanf(date->hvalue,"%3c,%d%s%d%d:%d:%d",tmp1,&ret.tm_mday,tmp2,
+                    &ret.tm_year,&ret.tm_hour,&ret.tm_min,&ret.tm_sec);
+       ret.tm_year-=1900;
+       for(i=0;i<7;i++) { 
+               if(strcmp(tmp1,days[i])==0) ret.tm_wday=i; 
+       }
+       for(j=0;j<12;j++) { 
+               if(strcmp(tmp2,months[j])==0) ret.tm_mon=j; 
+       }
        
        content_type= osip_message_get_content_type(ev->request);
        if (!content_type) {
@@ -1815,6 +1837,7 @@ static void text_received(Sal *sal, eXosip_event_t *ev){
        salmsg.text=msg;
        salmsg.url=external_body_size>0 ? unquoted_external_body_url : NULL;
        salmsg.message_id=message_id;
+       salmsg.time=mktime(&ret);
        sal->callbacks.text_received(sal,&salmsg);
        osip_free(from);
 }
index 078ec24b49e551f8b4d30f33a60c3de025c1e524..870d9670e31ac112f5c5b9b6bfe96b09b066fee3 100644 (file)
@@ -83,6 +83,9 @@ void sal_remove_in_subscribe(Sal *sal, SalOp *op){
 
 int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg){
        osip_message_t *sip=NULL;
+       time_t t;
+       time(&t);
+       char buf[26];
 
        if(op->cid == -1)
        {
@@ -97,6 +100,7 @@ int sal_message_send(SalOp *op, const char *from, const char *to, const char* co
                eXosip_message_build_request(&sip,"MESSAGE",sal_op_get_to(op),
                        sal_op_get_from(op),sal_op_get_route(op));
                if (sip!=NULL){
+                       osip_message_set_date(sip,ctime_r(&t,buf));
                        osip_message_set_content_type(sip,content_type);
                        if (msg) osip_message_set_body(sip,msg,strlen(msg));
                        sal_add_other(op->base.root,op,sip);
index 19bcc34297376dfc8349fb418bf603dc1ccacfa5..3eea9255c5491043335dbb5c8184830bc1ac992d 100644 (file)
@@ -90,7 +90,8 @@ void udpate_tab_chat_header(GtkWidget *chat_view,const LinphoneAddress *uri,Linp
 
 }
 
-void linphone_gtk_push_text(GtkWidget *w, const LinphoneAddress *from, const char *message, gboolean me,LinphoneChatRoom *cr){
+void linphone_gtk_push_text(GtkWidget *w, const LinphoneAddress *from, 
+                    const char *message, gboolean me,LinphoneChatRoom *cr, time_t t){
     GtkTextView *text=GTK_TEXT_VIEW(linphone_gtk_get_widget(w,"textview"));
     GtkTextBuffer *buffer=gtk_text_view_get_buffer(text);
     GtkTextIter iter,begin,end;
@@ -129,15 +130,19 @@ void linphone_gtk_push_text(GtkWidget *w, const LinphoneAddress *from, const cha
     }
        g_object_set_data(G_OBJECT(linphone_gtk_get_main_window()),"history",hash);
        
+
+       gtk_text_buffer_get_end_iter(buffer,&iter);
+       list=g_list_append(list,GINT_TO_POINTER(gtk_text_iter_get_line(&iter)));
        if(me){
-               gtk_text_buffer_get_end_iter(buffer,&iter);
-               list=g_list_append(list,GINT_TO_POINTER(gtk_text_iter_get_line(&iter)));
                gtk_text_buffer_insert_with_tags_by_name(buffer,&iter,"Message in progress.. ",-1,                                                                      
                                                         "italic","right","small","font_grey",NULL);
-               gtk_text_buffer_get_end_iter(buffer,&iter);
-               gtk_text_buffer_insert(buffer,&iter,"\n",-1);
-               g_object_set_data(G_OBJECT(w),"list",list);
+       } else {
+               gtk_text_buffer_insert_with_tags_by_name(buffer,&iter,ctime(&t),-1,                                                                     
+                                                        "italic","right","small","font_grey",NULL);
        }
+       gtk_text_buffer_get_end_iter(buffer,&iter);
+       gtk_text_buffer_insert(buffer,&iter,"\n",-1);
+       g_object_set_data(G_OBJECT(w),"list",list);
 
        GtkTextMark *mark=gtk_text_buffer_create_mark(buffer,NULL,&iter,FALSE);
        gtk_text_view_scroll_mark_onscreen(text,mark);
@@ -193,11 +198,6 @@ void update_chat_state_message(LinphoneChatMessageState state){
                                break;
                        default : result="Message in progress.. ";
                }
-
-               /*GDateTime *dt=g_date_time_new_now_local();
-               char *time=g_date_time_format(dt,"%k:%M");
-               gchar result2[80];
-               sprintf(result2,"%s %s",result,time);*/
                
                gtk_text_buffer_insert_with_tags_by_name(b,&iter,result,-1,
                                                                                                "italic","right","small","font_grey",NULL);
@@ -221,10 +221,10 @@ void linphone_gtk_send_text(){
        entered=gtk_entry_get_text(GTK_ENTRY(entry));
        if (strlen(entered)>0) {
                LinphoneChatMessage *msg;
+               msg=linphone_chat_room_create_message(cr,entered);
                linphone_gtk_push_text(w,
                                linphone_gtk_get_used_identity(),
-                               entered,TRUE,cr);
-               msg=linphone_chat_room_create_message(cr,entered);
+                               entered,TRUE,cr,linphone_chat_message_get_time(msg));
                linphone_chat_room_send_message2(cr,msg,on_chat_state_changed,NULL);
                gtk_entry_set_text(GTK_ENTRY(entry),"");
        }
@@ -338,25 +338,25 @@ void linphone_gtk_chat_close(GtkWidget *button){
 }
 
 
-void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message){
+void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, 
+                               LinphoneChatMessage *msg){
        GtkWidget *main_window=linphone_gtk_get_main_window();
        GtkWidget *friendlist=linphone_gtk_get_widget(main_window,"contact_list");
     GtkWidget *w;
-       /*GDateTime *dt=g_date_time_new_now_local();
-       char *time=g_date_time_format(dt,"%k:%M");*/
+                                                          
 
     w=(GtkWidget*)g_object_get_data(G_OBJECT(friendlist),"chatview");
     if(w!=NULL){
-        linphone_gtk_load_chatroom(room,from,w);
+        linphone_gtk_load_chatroom(room,linphone_chat_message_get_from(msg),w);
     } else {
-        w=linphone_gtk_init_chatroom(room,from);
+        w=linphone_gtk_init_chatroom(room,linphone_chat_message_get_from(msg));
         g_object_set_data(G_OBJECT(friendlist),"chatview",(gpointer)w);
-               g_object_set_data(G_OBJECT(friendlist),"from",(gpointer)from);
+               g_object_set_data(G_OBJECT(friendlist),"from",(gpointer)linphone_chat_message_get_from(msg));
     }
 
-       const char *display=linphone_address_get_display_name(from);
+       const char *display=linphone_address_get_display_name(linphone_chat_message_get_from(msg));
                if (display==NULL || display[0]=='\0') {
-                       display=linphone_address_get_username(from);
+                       display=linphone_address_get_username(linphone_chat_message_get_from(msg));
        }
        
        #ifdef HAVE_GTK_OSXs
@@ -365,16 +365,15 @@ void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const
        #else
        if(!gtk_window_is_active(GTK_WINDOW(main_window))){
                if(!GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"is_notified"))){
-                       /*gchar result2[80];
-                       sprintf(result2,"%s \n %s sent at %s",message,display,time);*/
-                       linphone_gtk_notify(NULL,message);
+                       linphone_gtk_notify(NULL,linphone_chat_message_get_text(msg));
                        g_object_set_data(G_OBJECT(w),"is_notified",GINT_TO_POINTER(TRUE));
                } else {
                        g_object_set_data(G_OBJECT(w),"is_notified",GINT_TO_POINTER(FALSE));
                }
        }
        #endif
-       linphone_gtk_push_text(w,from,message,FALSE,room);
+       linphone_gtk_push_text(w,linphone_chat_message_get_from(msg),
+                              linphone_chat_message_get_text(msg),FALSE,room,linphone_chat_message_get_time(msg));
        linphone_gtk_update_chat_picture();
        //gtk_window_present(GTK_WINDOW(w));
        /*gtk_window_set_urgency_hint(GTK_WINDOW(w),TRUE);*/
index ee584b0384f1693f8b010380cca887ba7b3f583c..55b30c8299fb96d597fd1be3dd2235022a3d8d89 100644 (file)
@@ -74,7 +74,7 @@ void linphone_gtk_fill_soundcards(GtkWidget *pb);
 void linphone_gtk_fill_webcams(GtkWidget *pb);
 void linphone_gtk_load_identities(void);
 LinphoneChatRoom * linphone_gtk_create_chatroom(const LinphoneAddress *with);
-void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message);
+void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *msg);
 void linphone_gtk_call_log_update(GtkWidget *w);
 void linphone_gtk_create_log_window(void);
 void linphone_gtk_log_show(void);
index bc333645b8de9fbf7704a98018df2de8349a940d..a2461269cfa030fc248f576e92424f99459fa5f0 100644 (file)
@@ -230,7 +230,8 @@ static void linphone_gtk_init_liblinphone(const char *config_file,
        vtable.display_warning=linphone_gtk_display_warning;
        vtable.display_url=linphone_gtk_display_url;
        vtable.call_log_updated=linphone_gtk_call_log_updated;
-       vtable.text_received=linphone_gtk_text_received;
+       //vtable.text_received=linphone_gtk_text_received;
+       vtable.message_received=linphone_gtk_text_received;
        vtable.refer_received=linphone_gtk_refer_received;
        vtable.buddy_info_updated=linphone_gtk_buddy_info_updated;
        vtable.call_encryption_changed=linphone_gtk_call_encryption_changed;
index 97e9b4701daa1c0aa86b8d1fcc4ded2ace40f288..76e96e808011ce1297476cd8afdb23c0e7bcf757 100644 (file)
                       <packing>
                         <property name="expand">True</property>
                         <property name="fill">True</property>
+                        <property name="padding">2</property>
                         <property name="position">0</property>
                       </packing>
                     </child>
                       <packing>
                         <property name="expand">False</property>
                         <property name="fill">True</property>
+                        <property name="padding">6</property>
                         <property name="position">2</property>
                       </packing>
                     </child>
                       <packing>
                         <property name="expand">False</property>
                         <property name="fill">False</property>
-                        <property name="padding">12</property>
+                        <property name="padding">6</property>
                         <property name="position">0</property>
                       </packing>
                     </child>
                       <packing>
                         <property name="expand">True</property>
                         <property name="fill">True</property>
+                        <property name="padding">6</property>
                         <property name="position">1</property>
                       </packing>
                     </child>