Skip to content

Commit

Permalink
Not show admin message if it's one one chat
Browse files Browse the repository at this point in the history
  • Loading branch information
tien-awair committed May 25, 2022
1 parent 44ff132 commit e8507c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.sendbird.android.AdminMessage;
import com.sendbird.android.BaseMessage;
import com.sendbird.android.GroupChannel;
import com.sendbird.android.SendBird;
Expand Down Expand Up @@ -37,6 +38,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Predicate;

import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import androidx.recyclerview.widget.RecyclerView;

import com.devlomi.record_view.OnRecordListener;
import com.sendbird.android.AdminMessage;
import com.sendbird.android.BaseChannel;
import com.sendbird.android.BaseMessage;
import com.sendbird.android.Emoji;
Expand Down Expand Up @@ -521,6 +522,14 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
final String traceName = receivedMessageData.getTraceName();
// The callback coming from setItems is worked asynchronously. So `isInitCallFinished` flag has to mark in advance.
final boolean isInitCallEnded = isInitCallFinished.get();

boolean isOneOneChat = channel.getMemberCount() <= 2;
if (isOneOneChat) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
messageList.removeIf(message -> message instanceof AdminMessage);
}
}

adapter.setItems(channel, messageList, messages -> {
if (traceName != null && isActive()) {
Logger.d("++ Message action : %s", traceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import androidx.annotation.Keep;

import com.sendbird.android.shadow.com.google.gson.annotations.SerializedName;
import com.sendbird.uikit.utils.TextUtils;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -42,9 +43,12 @@ public String joinUserNames() {
List<String> names = getUserNames();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < names.size(); i++) {
builder.append(names.get(i));
if (i != names.size() - 1) {
builder.append(", ");
String name = names.get(i);
if (!TextUtils.isEmpty(name)) {
builder.append(name);
if (i != names.size() - 1) {
builder.append(", ");
}
}
}
return builder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ public void setMetaData(AdminMessageMetaData metaData) {

public String getName() {
String phone = metaData.getPhone();
String username = metaData.getUsername();

String phonebookName = SendBirdUIKit.findPhoneBookName(phone);
return TextUtils.isEmpty(phonebookName) ? username : phonebookName;
return TextUtils.isEmpty(phonebookName) ? phone : phonebookName;
}
}

0 comments on commit e8507c1

Please sign in to comment.