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 eaa8b47f..2ebdbfa7 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/dialogs/DialogsListAdapter.java @@ -257,6 +257,26 @@ public void updateItemById(DIALOG item) { } } + /** + * Upsert dialog in dialogs list or add it to then end of dialogs list + * + * @param item dialog item + */ + public void upsertItem(DIALOG item) { + boolean updated = false; + for (int i = 0; i < items.size(); i++) { + if (items.get(i).getId().equals(item.getId())) { + items.set(i, item); + notifyItemChanged(i); + updated = true; + break; + } + } + if (!updated) { + addItem(item); + } + } + /** * Find an item by its id *