From e9338ea38c40f7bd572c1934f082532271264c70 Mon Sep 17 00:00:00 2001 From: Haris Dautovic Date: Thu, 20 Jun 2019 14:43:25 +0200 Subject: [PATCH] Added new upsert function with scroll param Ability to scroll list after adding new object. Existing upsert function has hardcoded value "addToStart(message, false);" --- .../chatkit/messages/MessagesListAdapter.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java index e0fcb8a2..51053178 100644 --- a/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java +++ b/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java @@ -240,6 +240,19 @@ public void upsert(MESSAGE message) { } } + + /** + * Updates message by its id if it exists, add to start if not + * + * @param message message object to insert or update. + * @param scroll {@code true} if need to scroll list to bottom when message added. + */ + public void upsert(MESSAGE message, Boolean scroll) { + if (!update(message)) { + addToStart(message, scroll); + } + } + /** * Updates and moves to start if message by its id exists and if specified move to start, if not * specified the item stays at current position and updated