From 11bee2e07183d39efe86112d2253686225d548fa Mon Sep 17 00:00:00 2001
From: Philippe Auriach <p.auriach@gmail.com>
Date: Wed, 9 Aug 2017 15:28:03 +0200
Subject: [PATCH 1/7] ability to have return a drawable for dialog / users

---
 .../stfalcon/chatkit/commons/ImageLoader.java |  3 ++-
 .../chatkit/commons/models/IDialog.java       |  4 ++++
 .../chatkit/commons/models/IUser.java         |  8 +++++++
 .../chatkit/dialogs/DialogsListAdapter.java   | 24 ++++++++++++-------
 .../features/demo/DemoDialogsActivity.java    |  8 +++++--
 5 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java
index 4d795854..402b48f8 100644
--- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java
+++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java
@@ -16,6 +16,7 @@
 
 package com.stfalcon.chatkit.commons;
 
+import android.graphics.drawable.Drawable;
 import android.widget.ImageView;
 
 /**
@@ -23,6 +24,6 @@
  */
 public interface ImageLoader {
 
-    void loadImage(ImageView imageView, String url);
+    void loadImage(ImageView imageView, Drawable drawable, String url);
 
 }
diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IDialog.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IDialog.java
index 661c76e8..cf6deaa7 100644
--- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IDialog.java
+++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IDialog.java
@@ -16,6 +16,8 @@
 
 package com.stfalcon.chatkit.commons.models;
 
+import android.graphics.drawable.Drawable;
+
 import java.util.List;
 
 /**
@@ -26,6 +28,8 @@ public interface IDialog<MESSAGE extends IMessage> {
 
     String getId();
 
+    Drawable getDialogPhotoDrawable();
+
     String getDialogPhoto();
 
     String getDialogName();
diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IUser.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IUser.java
index d51c2081..cff1ff94 100644
--- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IUser.java
+++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IUser.java
@@ -16,6 +16,8 @@
 
 package com.stfalcon.chatkit.commons.models;
 
+import android.graphics.drawable.Drawable;
+
 /**
  * For implementing by real user model
  */
@@ -35,6 +37,12 @@ public interface IUser {
      * */
     String getName();
 
+    /**
+     *
+     * @return the user's avatar drawable
+     */
+    Drawable getAvatarDrawable();
+
     /**
      * Returns the user's avatar image url
      *
diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
index 9638ff7e..7659fbb0 100644
--- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
+++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
@@ -32,6 +32,7 @@
 import com.stfalcon.chatkit.commons.ViewHolder;
 import com.stfalcon.chatkit.commons.models.IDialog;
 import com.stfalcon.chatkit.commons.models.IMessage;
+import com.stfalcon.chatkit.commons.models.IUser;
 import com.stfalcon.chatkit.utils.DateFormatter;
 
 import java.lang.reflect.Constructor;
@@ -297,6 +298,13 @@ public void sort(Comparator<DIALOG> comparator) {
         notifyDataSetChanged();
     }
 
+    /**
+     * @return registered image loader
+     */
+    public ImageLoader getImageLoader() {
+        return imageLoader;
+    }
+
     /**
      * Register a callback to be invoked when image need to load.
      *
@@ -306,13 +314,6 @@ public void setImageLoader(ImageLoader imageLoader) {
         this.imageLoader = imageLoader;
     }
 
-    /**
-     * @return registered image loader
-     */
-    public ImageLoader getImageLoader() {
-        return imageLoader;
-    }
-
     /**
      * @return the item click callback.
      */
@@ -592,12 +593,17 @@ public void onBind(final DIALOG dialog) {
 
             //Set Dialog avatar
             if (imageLoader != null) {
-                imageLoader.loadImage(ivAvatar, dialog.getDialogPhoto());
+                imageLoader.loadImage(ivAvatar, dialog.getDialogPhotoDrawable(), dialog.getDialogPhoto());
             }
 
             //Set Last message user avatar
             if (imageLoader != null) {
-                imageLoader.loadImage(ivLastMessageUser, dialog.getLastMessage().getUser().getAvatar());
+                if (dialog.getLastMessage() != null && dialog.getLastMessage().getUser() != null) {
+                    IUser user = dialog.getLastMessage().getUser();
+                    imageLoader.loadImage(ivLastMessageUser, user.getAvatarDrawable(), user.getAvatar());
+                } else {
+                    imageLoader.loadImage(ivLastMessageUser, null, null);
+                }
             }
             ivLastMessageUser.setVisibility(dialogStyle.isDialogMessageAvatarEnabled()
                     && dialog.getUsers().size() > 1 ? VISIBLE : GONE);
diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java
index f2848ba8..14ea004e 100644
--- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java
+++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java
@@ -1,5 +1,6 @@
 package com.stfalcon.chatkit.sample.features.demo;
 
+import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
@@ -27,8 +28,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
 
         imageLoader = new ImageLoader() {
             @Override
-            public void loadImage(ImageView imageView, String url) {
-                Picasso.with(DemoDialogsActivity.this).load(url).into(imageView);
+            public void loadImage(ImageView imageView, Drawable drawable, String url) {
+                Picasso.with(DemoDialogsActivity.this)
+                        .load(url)
+                        .placeholder(drawable)
+                        .into(imageView);
             }
         };
     }

From 8f34e3e0b1256d700861d48b1c3b312fabb8fcfc Mon Sep 17 00:00:00 2001
From: Philippe Auriach <p.auriach@gmail.com>
Date: Wed, 9 Aug 2017 16:32:52 +0200
Subject: [PATCH 2/7] Added ability to get context around image loading

Without breaking change : ImageLoader is now an abstract class implementing the new methods of ContextImageLoader with the values used previously : nothing change for existing implementations.
However, the user is now able to override other methods of ImageLoader if he wants to have additional data for say, the user.
---
 .../chatkit/commons/ContextImageLoader.java   | 16 +++++++++++
 .../stfalcon/chatkit/commons/ImageLoader.java | 24 ++++++++++++++--
 .../chatkit/commons/models/IDialog.java       |  4 ---
 .../chatkit/commons/models/IUser.java         |  8 ------
 .../chatkit/dialogs/DialogsListAdapter.java   | 28 ++++++++-----------
 .../chatkit/messages/MessageHolders.java      |  6 ++--
 sample/build.gradle                           |  2 ++
 .../features/demo/DemoDialogsActivity.java    | 23 +++++++++++++--
 8 files changed, 73 insertions(+), 38 deletions(-)
 create mode 100644 chatkit/src/main/java/com/stfalcon/chatkit/commons/ContextImageLoader.java

diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/ContextImageLoader.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/ContextImageLoader.java
new file mode 100644
index 00000000..d3f9249f
--- /dev/null
+++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/ContextImageLoader.java
@@ -0,0 +1,16 @@
+package com.stfalcon.chatkit.commons;
+
+import android.widget.ImageView;
+
+import com.stfalcon.chatkit.commons.models.IDialog;
+import com.stfalcon.chatkit.commons.models.IUser;
+import com.stfalcon.chatkit.commons.models.MessageContentType;
+
+public interface ContextImageLoader {
+
+    void loadImage(ImageView imageView, IDialog dialog);
+
+    void loadImage(ImageView imageView, IUser user);
+
+    void loadImage(ImageView imageView, MessageContentType.Image messageContent);
+}
diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java
index 402b48f8..073bb67f 100644
--- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java
+++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/ImageLoader.java
@@ -16,14 +16,32 @@
 
 package com.stfalcon.chatkit.commons;
 
-import android.graphics.drawable.Drawable;
 import android.widget.ImageView;
 
+import com.stfalcon.chatkit.commons.models.IDialog;
+import com.stfalcon.chatkit.commons.models.IUser;
+import com.stfalcon.chatkit.commons.models.MessageContentType;
+
 /**
  * Callback for implementing images loading in message list
  */
-public interface ImageLoader {
+public abstract class ImageLoader implements ContextImageLoader {
+
+    public abstract void loadImage(ImageView imageView, String url);
 
-    void loadImage(ImageView imageView, Drawable drawable, String url);
+    @Override
+    public void loadImage(ImageView imageView, IDialog dialog) {
+        loadImage(imageView, dialog.getDialogPhoto());
+    }
 
+    @Override
+    public void loadImage(ImageView imageView, IUser user) {
+        loadImage(imageView, user.getAvatar());
+    }
+
+    @Override
+    public void loadImage(ImageView imageView, MessageContentType.Image messageContent) {
+        loadImage(imageView, messageContent.getImageUrl());
+    }
 }
+
diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IDialog.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IDialog.java
index cf6deaa7..661c76e8 100644
--- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IDialog.java
+++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IDialog.java
@@ -16,8 +16,6 @@
 
 package com.stfalcon.chatkit.commons.models;
 
-import android.graphics.drawable.Drawable;
-
 import java.util.List;
 
 /**
@@ -28,8 +26,6 @@ public interface IDialog<MESSAGE extends IMessage> {
 
     String getId();
 
-    Drawable getDialogPhotoDrawable();
-
     String getDialogPhoto();
 
     String getDialogName();
diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IUser.java b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IUser.java
index cff1ff94..d51c2081 100644
--- a/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IUser.java
+++ b/chatkit/src/main/java/com/stfalcon/chatkit/commons/models/IUser.java
@@ -16,8 +16,6 @@
 
 package com.stfalcon.chatkit.commons.models;
 
-import android.graphics.drawable.Drawable;
-
 /**
  * For implementing by real user model
  */
@@ -37,12 +35,6 @@ public interface IUser {
      * */
     String getName();
 
-    /**
-     *
-     * @return the user's avatar drawable
-     */
-    Drawable getAvatarDrawable();
-
     /**
      * Returns the user's avatar image url
      *
diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
index 7659fbb0..53f6a848 100644
--- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
+++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
@@ -28,11 +28,10 @@
 import android.widget.TextView;
 
 import com.stfalcon.chatkit.R;
-import com.stfalcon.chatkit.commons.ImageLoader;
+import com.stfalcon.chatkit.commons.ContextImageLoader;
 import com.stfalcon.chatkit.commons.ViewHolder;
 import com.stfalcon.chatkit.commons.models.IDialog;
 import com.stfalcon.chatkit.commons.models.IMessage;
-import com.stfalcon.chatkit.commons.models.IUser;
 import com.stfalcon.chatkit.utils.DateFormatter;
 
 import java.lang.reflect.Constructor;
@@ -55,7 +54,7 @@ public class DialogsListAdapter<DIALOG extends IDialog>
     private List<DIALOG> items = new ArrayList<>();
     private int itemLayoutId;
     private Class<? extends BaseDialogViewHolder> holderClass;
-    private ImageLoader imageLoader;
+    private ContextImageLoader imageLoader;
     private OnDialogClickListener<DIALOG> onDialogClickListener;
     private OnDialogViewClickListener<DIALOG> onDialogViewClickListener;
     private OnDialogLongClickListener<DIALOG> onLongItemClickListener;
@@ -68,7 +67,7 @@ public class DialogsListAdapter<DIALOG extends IDialog>
      *
      * @param imageLoader image loading method
      */
-    public DialogsListAdapter(ImageLoader imageLoader) {
+    public DialogsListAdapter(ContextImageLoader imageLoader) {
         this(R.layout.item_dialog, DialogViewHolder.class, imageLoader);
     }
 
@@ -78,7 +77,7 @@ public DialogsListAdapter(ImageLoader imageLoader) {
      * @param itemLayoutId custom list item resource id
      * @param imageLoader  image loading method
      */
-    public DialogsListAdapter(@LayoutRes int itemLayoutId, ImageLoader imageLoader) {
+    public DialogsListAdapter(@LayoutRes int itemLayoutId, ContextImageLoader imageLoader) {
         this(itemLayoutId, DialogViewHolder.class, imageLoader);
     }
 
@@ -90,7 +89,7 @@ public DialogsListAdapter(@LayoutRes int itemLayoutId, ImageLoader imageLoader)
      * @param imageLoader  image loading method
      */
     public DialogsListAdapter(@LayoutRes int itemLayoutId, Class<? extends BaseDialogViewHolder> holderClass,
-                              ImageLoader imageLoader) {
+                              ContextImageLoader imageLoader) {
         this.itemLayoutId = itemLayoutId;
         this.holderClass = holderClass;
         this.imageLoader = imageLoader;
@@ -301,7 +300,7 @@ public void sort(Comparator<DIALOG> comparator) {
     /**
      * @return registered image loader
      */
-    public ImageLoader getImageLoader() {
+    public ContextImageLoader getImageLoader() {
         return imageLoader;
     }
 
@@ -310,7 +309,7 @@ public ImageLoader getImageLoader() {
      *
      * @param imageLoader image loading method
      */
-    public void setImageLoader(ImageLoader imageLoader) {
+    public void setImageLoader(ContextImageLoader imageLoader) {
         this.imageLoader = imageLoader;
     }
 
@@ -415,7 +414,7 @@ public interface OnDialogViewLongClickListener<DIALOG extends IDialog> {
     public abstract static class BaseDialogViewHolder<DIALOG extends IDialog>
             extends ViewHolder<DIALOG> {
 
-        protected ImageLoader imageLoader;
+        protected ContextImageLoader imageLoader;
         protected OnDialogClickListener<DIALOG> onDialogClickListener;
         protected OnDialogLongClickListener<DIALOG> onLongItemClickListener;
         protected OnDialogViewClickListener<DIALOG> onDialogViewClickListener;
@@ -426,7 +425,7 @@ public BaseDialogViewHolder(View itemView) {
             super(itemView);
         }
 
-        void setImageLoader(ImageLoader imageLoader) {
+        void setImageLoader(ContextImageLoader imageLoader) {
             this.imageLoader = imageLoader;
         }
 
@@ -593,17 +592,12 @@ public void onBind(final DIALOG dialog) {
 
             //Set Dialog avatar
             if (imageLoader != null) {
-                imageLoader.loadImage(ivAvatar, dialog.getDialogPhotoDrawable(), dialog.getDialogPhoto());
+                imageLoader.loadImage(ivAvatar, dialog);
             }
 
             //Set Last message user avatar
             if (imageLoader != null) {
-                if (dialog.getLastMessage() != null && dialog.getLastMessage().getUser() != null) {
-                    IUser user = dialog.getLastMessage().getUser();
-                    imageLoader.loadImage(ivLastMessageUser, user.getAvatarDrawable(), user.getAvatar());
-                } else {
-                    imageLoader.loadImage(ivLastMessageUser, null, null);
-                }
+                imageLoader.loadImage(ivLastMessageUser, dialog.getLastMessage().getUser());
             }
             ivLastMessageUser.setVisibility(dialogStyle.isDialogMessageAvatarEnabled()
                     && dialog.getUsers().size() > 1 ? VISIBLE : GONE);
diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java
index 8f126cd3..0dfa119b 100644
--- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java
+++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java
@@ -630,7 +630,7 @@ public IncomingImageMessageViewHolder(View itemView) {
         public void onBind(MESSAGE message) {
             super.onBind(message);
             if (image != null && imageLoader != null) {
-                imageLoader.loadImage(image, message.getImageUrl());
+                imageLoader.loadImage(image, message);
             }
 
             if (imageOverlay != null) {
@@ -681,7 +681,7 @@ public OutcomingImageMessageViewHolder(View itemView) {
         public void onBind(MESSAGE message) {
             super.onBind(message);
             if (image != null && imageLoader != null) {
-                imageLoader.loadImage(image, message.getImageUrl());
+                imageLoader.loadImage(image, message);
             }
 
             if (imageOverlay != null) {
@@ -770,7 +770,7 @@ public void onBind(MESSAGE message) {
 
                 userAvatar.setVisibility(isAvatarExists ? View.VISIBLE : View.GONE);
                 if (isAvatarExists) {
-                    imageLoader.loadImage(userAvatar, message.getUser().getAvatar());
+                    imageLoader.loadImage(userAvatar, message.getUser());
                 }
             }
         }
diff --git a/sample/build.gradle b/sample/build.gradle
index 13d52cae..c900fae8 100644
--- a/sample/build.gradle
+++ b/sample/build.gradle
@@ -30,6 +30,7 @@ ext {
     circleImageViewVersion = '2.1.0'
     shapeImageViewVersion = '0.9.3'
     circleindicatorVersion = '1.2.2@aar'
+    textDrawableVersion = '1.0.1'
 }
 
 dependencies {
@@ -51,6 +52,7 @@ dependencies {
     //ImageViews
     compile "de.hdodenhof:circleimageview:$circleImageViewVersion"
     compile "com.github.siyamed:android-shape-imageview:$shapeImageViewVersion"
+    compile "com.amulyakhare:com.amulyakhare.textdrawable:$textDrawableVersion"
 
     //Utils
     compile "me.relex:circleindicator:$circleindicatorVersion"
diff --git a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java
index 14ea004e..461f326d 100644
--- a/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java
+++ b/sample/src/main/java/com/stfalcon/chatkit/sample/features/demo/DemoDialogsActivity.java
@@ -1,17 +1,20 @@
 package com.stfalcon.chatkit.sample.features.demo;
 
-import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
 import android.widget.ImageView;
 
+import com.amulyakhare.textdrawable.TextDrawable;
 import com.squareup.picasso.Picasso;
 import com.stfalcon.chatkit.commons.ImageLoader;
+import com.stfalcon.chatkit.commons.models.IUser;
 import com.stfalcon.chatkit.dialogs.DialogsListAdapter;
 import com.stfalcon.chatkit.sample.common.data.model.Dialog;
 import com.stfalcon.chatkit.sample.utils.AppUtils;
 
+import java.util.Random;
+
 /*
  * Created by troy379 on 05.04.17.
  */
@@ -27,13 +30,27 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         imageLoader = new ImageLoader() {
+
             @Override
-            public void loadImage(ImageView imageView, Drawable drawable, String url) {
+            public void loadImage(ImageView imageView, String url) {
                 Picasso.with(DemoDialogsActivity.this)
                         .load(url)
-                        .placeholder(drawable)
                         .into(imageView);
             }
+
+            @Override
+            public void loadImage(ImageView imageView, IUser user) {
+                if(new Random().nextInt(2) == 1) {
+                    Picasso.with(DemoDialogsActivity.this)
+                            .load(user.getAvatar())
+                            .into(imageView);
+                } else {
+                    TextDrawable drawable = TextDrawable.builder().buildRound(
+                            user.getName().substring(0, 2),
+                            DemoDialogsActivity.this.getResources().getColor(android.R.color.holo_red_dark));
+                    imageView.setImageDrawable(drawable);
+                }
+            }
         };
     }
 

From f6107b10872134f006b0e0cf41e82f7686cd17df Mon Sep 17 00:00:00 2001
From: Mathieu Rul <mathroule@gmail.com>
Date: Tue, 28 Aug 2018 10:58:22 +0200
Subject: [PATCH 3/7] Bump to version 0.3.2

---
 chatkit/build.gradle | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/chatkit/build.gradle b/chatkit/build.gradle
index f970a58f..b8561ee8 100644
--- a/chatkit/build.gradle
+++ b/chatkit/build.gradle
@@ -8,7 +8,7 @@ android {
     defaultConfig {
         minSdkVersion 14
         versionCode 1
-        versionName "0.3.1"
+        versionName "0.3.2"
 
         consumerProguardFiles 'proguard.txt'
     }
@@ -20,9 +20,9 @@ android {
 }
 
 publish {
-    groupId = 'com.github.stfalcon'
+    groupId = 'com.github.mathroule'
     artifactId = 'chatkit'
-    publishVersion = '0.3.1'
+    publishVersion = '0.3.2'
     desc = 'ChatKit - is a library designed to simplify the development of UI for such a trivial task as chat. It have flexible possibilities for styling, customizing and data management'
     licences = ['Apache-2.0']
     uploadName = 'ChatKit'

From 1a9a67faf5d0094e3fe4edfe687046adfaf1e952 Mon Sep 17 00:00:00 2001
From: Mathieu Rul <mathroule@gmail.com>
Date: Tue, 28 Aug 2018 14:20:05 +0200
Subject: [PATCH 4/7] Fix NPE if last message is null

---
 .../java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
index 52405b49..d8af68fa 100644
--- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
+++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
@@ -661,7 +661,7 @@ public void onBind(final DIALOG dialog) {
             }
 
             //Set Last message user avatar
-            if (imageLoader != null) {
+            if (imageLoader != null && dialog.getLastMessage() != null) {
                 imageLoader.loadImage(ivLastMessageUser, dialog.getLastMessage().getUser());
             }
             ivLastMessageUser.setVisibility(dialogStyle.isDialogMessageAvatarEnabled()

From 9a348b9fa4d4aad6350c59f5ca984bd3ccd5a7c8 Mon Sep 17 00:00:00 2001
From: Mathieu Rul <mathroule@gmail.com>
Date: Tue, 28 Aug 2018 14:20:16 +0200
Subject: [PATCH 5/7] Bump to version 0.3.3

---
 chatkit/build.gradle | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/chatkit/build.gradle b/chatkit/build.gradle
index b8561ee8..cb3675d8 100644
--- a/chatkit/build.gradle
+++ b/chatkit/build.gradle
@@ -8,7 +8,7 @@ android {
     defaultConfig {
         minSdkVersion 14
         versionCode 1
-        versionName "0.3.2"
+        versionName "0.3.3"
 
         consumerProguardFiles 'proguard.txt'
     }
@@ -22,7 +22,7 @@ android {
 publish {
     groupId = 'com.github.mathroule'
     artifactId = 'chatkit'
-    publishVersion = '0.3.2'
+    publishVersion = '0.3.3'
     desc = 'ChatKit - is a library designed to simplify the development of UI for such a trivial task as chat. It have flexible possibilities for styling, customizing and data management'
     licences = ['Apache-2.0']
     uploadName = 'ChatKit'

From 7269abf4ae43b92f690c5f7917baaae471568e98 Mon Sep 17 00:00:00 2001
From: Mathieu Rul <mathroule@gmail.com>
Date: Tue, 28 Aug 2018 14:34:41 +0200
Subject: [PATCH 6/7] Update comment

---
 .../java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
index d8af68fa..88d7ca33 100644
--- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
+++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java
@@ -660,7 +660,7 @@ public void onBind(final DIALOG dialog) {
                 imageLoader.loadImage(ivAvatar, dialog);
             }
 
-            //Set Last message user avatar
+            //Set Last message user avatar with check if there is last message
             if (imageLoader != null && dialog.getLastMessage() != null) {
                 imageLoader.loadImage(ivLastMessageUser, dialog.getLastMessage().getUser());
             }

From b20340428ff390c758042eb0bf88c1557d017f87 Mon Sep 17 00:00:00 2001
From: Mathieu Rul <mathroule@gmail.com>
Date: Sun, 30 Sep 2018 22:07:55 +0200
Subject: [PATCH 7/7] Update documentation to add upsertItem method

---
 docs/COMPONENT_DIALOGS_LIST.MD | 1 +
 1 file changed, 1 insertion(+)

diff --git a/docs/COMPONENT_DIALOGS_LIST.MD b/docs/COMPONENT_DIALOGS_LIST.MD
index 61bea52d..e219fc1a 100644
--- a/docs/COMPONENT_DIALOGS_LIST.MD
+++ b/docs/COMPONENT_DIALOGS_LIST.MD
@@ -115,6 +115,7 @@ When your models are ready to be used by adapter, you can simply add them to the
 * adapter.addItems(List<DIALOG> items) - adds a new dialog list to the end of the list;
 * adapter.addItem(DIALOG dialog) - adds one dialog to the end of the list
 * adapter.addItem(int position, DIALOG dialog) -  adds a new dialog to the specified position.
+* adapter.upsertItem(DIALOG dialog) - adds one dialog to the end of the list if not exists, otherwise updates the existing dialog.
 
 #### Updating dialogs
 If dialog has changed, you can update it by position in list by calling `adapter.updateItem(int position, DIALOG item)` or update it by dialog id by calling `adapter.updateItemById(DIALOG item)`