+static void linphone_gtk_chat_message_destroy(LinphoneChatMessage *msg){
+ linphone_chat_message_destroy(msg);
+}
+
+void linphone_gtk_free_list(MSList *messages){
+ ms_list_for_each(messages,(void (*)(void*))linphone_gtk_chat_message_destroy);
+ ms_list_free(messages);
+}
+
+void display_history_message(GtkWidget *chat_view,MSList *messages,const LinphoneAddress *with){
+ if(messages != NULL){
+ MSList *it;
+ char *from_str;
+ char *with_str;
+ gchar *tmp;
+ for(it=messages;it!=NULL;it=it->next){
+ LinphoneChatMessage *msg=(LinphoneChatMessage *)it->data;
+ from_str=linphone_address_as_string_uri_only(linphone_chat_message_get_from(msg));
+ with_str=linphone_address_as_string_uri_only(with);
+ linphone_gtk_push_text(chat_view,strcmp(from_str,with_str)==0? with :
+ linphone_chat_message_get_from(msg),
+ strcmp(from_str,with_str)==0? FALSE : TRUE,
+ linphone_chat_message_get_chat_room(msg),msg,TRUE);
+ }
+ tmp=g_object_get_data(G_OBJECT(chat_view),"from_message");
+ if (tmp){
+ g_object_set_data(G_OBJECT(chat_view),"from_message",NULL);
+ g_free(tmp);
+ }
+ ms_free(from_str);
+ ms_free(with_str);
+ linphone_gtk_free_list(messages);
+ }
+}
+
+void linphone_gtk_chat_add_contact(const LinphoneAddress *addr){
+ //LinphoneAddress *addr=(LinphoneAddress *)data;
+ LinphoneFriend *lf=NULL;
+ char *uri=linphone_address_as_string(addr);
+ lf=linphone_friend_new_with_addr(uri);
+ ms_free(uri);
+ char *fixed_uri=NULL;
+ gboolean show_presence=FALSE;
+
+ linphone_friend_set_inc_subscribe_policy(lf,LinphoneSPDeny);
+ linphone_friend_send_subscribe(lf,show_presence);
+
+ linphone_core_interpret_friend_uri(linphone_gtk_get_core(),uri,&fixed_uri);
+ if (fixed_uri==NULL){
+ linphone_gtk_display_something(GTK_MESSAGE_WARNING,_("Invalid sip contact !"));
+ return ;
+ }
+ linphone_friend_set_addr(lf,addr);
+ linphone_core_add_friend(linphone_gtk_get_core(),lf);
+ ms_free(fixed_uri);
+ linphone_gtk_show_friends();
+}
+