Skip to content

Commit

Permalink
Merge pull request #10 from sendbird/release/leo/v3.7.0
Browse files Browse the repository at this point in the history
Added 3.7.0
  • Loading branch information
leo-shin authored Aug 17, 2023
2 parents f2b0e22 + 635a9cc commit 6ceb8db
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
### v3.7.0 (Jul 17 2023) with Chat SDK `v4.11.0`
* Change the default authentication method for FeedChannel from WebSocket connection to API.
* Added `authenticatedFeed(AuthenticationHandler)` in `SendbirdUIKit`
* Added `moveToMessage(long, boolean)` in `ChannelFragment`

### v3.6.1 (Jul 12, 2023) with Chat SDK `v4.9.4`
* Improved stability

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ org.gradle.jvmargs=-Xmx1536m
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true

UIKIT_VERSION = 3.6.1
UIKIT_VERSION = 3.7.0
UIKIT_VERSION_CODE = 1
2 changes: 1 addition & 1 deletion uikit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

// Sendbird
api 'com.sendbird.sdk:sendbird-chat:4.9.4'
api 'com.sendbird.sdk:sendbird-chat:4.11.0'

implementation 'com.github.bumptech.glide:glide:4.13.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0'
Expand Down
92 changes: 72 additions & 20 deletions uikit/src/main/java/com/sendbird/uikit/SendbirdUIKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import androidx.appcompat.content.res.AppCompatResources;

import com.sendbird.android.AppInfo;
import com.sendbird.android.ConnectionState;
import com.sendbird.android.NotificationInfo;
import com.sendbird.android.SendbirdChat;
import com.sendbird.android.exception.SendbirdException;
import com.sendbird.android.handler.AuthenticationHandler;
import com.sendbird.android.handler.CompletionHandler;
import com.sendbird.android.handler.ConnectHandler;
import com.sendbird.android.handler.DisconnectHandler;
Expand Down Expand Up @@ -58,7 +58,6 @@
import org.jetbrains.annotations.TestOnly;

import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -264,8 +263,7 @@ synchronized static void init(
@NonNull SendbirdUIKitAdapter adapter,
@NonNull UIKitConfigRepository uikitConfigRepo,
@NonNull Context context,
boolean isForeground)
{
boolean isForeground) {
SendbirdUIKit.adapter = adapter;
SendbirdUIKit.uikitConfigRepo = uikitConfigRepo;

Expand Down Expand Up @@ -293,9 +291,9 @@ public void onInitSucceed() {
}
try {
SendbirdSdkInfo o = new SendbirdSdkInfo(
SendbirdProduct.UIKIT_CHAT,
SendbirdPlatform.ANDROID,
BuildConfig.VERSION_NAME
SendbirdProduct.UIKIT_CHAT,
SendbirdPlatform.ANDROID,
BuildConfig.VERSION_NAME
);
sendbirdChatWrapper.addSendbirdExtensions(Collections.singletonList(o), null);
} catch (Throwable ignored) {
Expand Down Expand Up @@ -534,20 +532,53 @@ public static ThreadReplySelectType getThreadReplySelectType() {
* @param handler Callback handler.
*/
public static void connect(@Nullable ConnectHandler handler) {
connect(new SendbirdChatImpl(), new TaskQueueImpl(), handler);
connectInternal(new SendbirdChatImpl(), new TaskQueueImpl(), handler);
}

/**
* Authenticate to Sendbird with given <code>UserInfo</code>.
* Unlike {@link #connect(ConnectHandler)}, it is used to issue the necessary credentials when using the API required for FeedNotification.
*
* @param handler Callback handler.
* since 3.7.0
*/
public static void authenticateFeed(@Nullable AuthenticationHandler handler) {
connectInternal(ConnectType.AUTHENTICATE_FEED, new SendbirdChatImpl(), new TaskQueueImpl(), (user, e1) -> {
if (handler != null) handler.onAuthenticated(user, e1);
});
}

private enum ConnectType {
CONNECT,
AUTHENTICATE_FEED
}

@VisibleForTesting
static void connect(@NonNull SendbirdChatWrapper sendbirdChat,
@NonNull TaskQueueWrapper taskQueueWrapper,
@Nullable ConnectHandler handler) {
static void connectInternal(@NonNull SendbirdChatWrapper sendbirdChat,
@NonNull TaskQueueWrapper taskQueueWrapper,
@Nullable ConnectHandler handler) {
connectInternal(ConnectType.CONNECT, sendbirdChat, taskQueueWrapper, handler);
}

private static void connectInternal(
@NonNull ConnectType connectType,
@NonNull SendbirdChatWrapper sendbirdChat,
@NonNull TaskQueueWrapper taskQueueWrapper,
@Nullable ConnectHandler handler) {
taskQueueWrapper.addTask(new JobResultTask<Pair<User, SendbirdException>>() {
@Override
public Pair<User, SendbirdException> call() throws Exception {
final Pair<User, SendbirdException> data = connect(sendbirdChat);
final Pair<User, SendbirdException> data;
if (connectType == ConnectType.AUTHENTICATE_FEED) {
data = authenticateFeedBlocking(sendbirdChat);
} else {
data = connectBlocking(sendbirdChat);
}

final User user = data.first;
final SendbirdException error = data.second;
if (sendbirdChat.getConnectionState() == ConnectionState.OPEN && user != null) {
Logger.d("++ user=%s, error=%s", user, error);
if (error == null && user != null) {
UserInfo userInfo = adapter.getUserInfo();
String userId = userInfo.getUserId();
String nickname = TextUtils.isEmpty(userInfo.getNickname()) ? user.getNickname() : userInfo.getNickname();
Expand All @@ -564,8 +595,9 @@ public Pair<User, SendbirdException> call() throws Exception {

final AppInfo appInfo = sendbirdChat.getAppInfo();
if (appInfo != null) {
if (appInfo.getUseReaction() &&
appInfo.needUpdateEmoji(EmojiManager.getInstance().getEmojiHash())) {
if (appInfo.getUseReaction()
&& appInfo.needUpdateEmoji(EmojiManager.getInstance().getEmojiHash())
&& connectType == ConnectType.CONNECT) {
updateEmojiList();
}

Expand Down Expand Up @@ -612,7 +644,7 @@ public void onResultForUiThread(@Nullable Pair<User, SendbirdException> data, @N
}

@NonNull
private static Pair<User, SendbirdException> connect(@NonNull SendbirdChatWrapper sendbirdChat) throws InterruptedException {
private static Pair<User, SendbirdException> connectBlocking(@NonNull SendbirdChatWrapper sendbirdChat) throws InterruptedException {
AtomicReference<User> result = new AtomicReference<>();
AtomicReference<SendbirdException> error = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
Expand All @@ -632,6 +664,27 @@ private static Pair<User, SendbirdException> connect(@NonNull SendbirdChatWrappe
return new Pair<>(result.get(), error.get());
}

@NonNull
private static Pair<User, SendbirdException> authenticateFeedBlocking(@NonNull SendbirdChatWrapper sendbirdChat) throws InterruptedException {
AtomicReference<User> result = new AtomicReference<>();
AtomicReference<SendbirdException> error = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
UserInfo userInfo = adapter.getUserInfo();
String userId = userInfo.getUserId();
String accessToken = adapter.getAccessToken();

sendbirdChat.authenticateFeed(userId, accessToken, null, (user, e) -> {
result.set(user);
if (e != null) {
error.set(e);
}

latch.countDown();
});
latch.await();
return new Pair<>(result.get(), error.get());
}

/**
* Disconnects from SendbirdChat. Call this when user logged out.
*
Expand All @@ -649,8 +702,8 @@ public static void disconnect(@Nullable DisconnectHandler handler) {
/**
* Updates current <code>UserInfo</code>.
*
* @param params Params for update current users.
* @param handler Callback handler.
* @param params Params for update current users.
* @param handler Callback handler.
*/
public static void updateUserInfo(@NonNull UserUpdateParams params, @Nullable CompletionHandler handler) {
SendbirdChat.updateCurrentUserInfo(params, handler);
Expand Down Expand Up @@ -688,7 +741,7 @@ public static void setCustomParamsHandler(@NonNull CustomParamsHandler handler)

/**
* Sets the factory that creates fragments generated by UIKit's basic activities.
*
* <p>
* since 3.0.0
*/
public static void setUIKitFragmentFactory(@NonNull UIKitFragmentFactory factory) {
Expand Down Expand Up @@ -812,7 +865,6 @@ public static void setMentionConfig(@NonNull UserMentionConfig config) {

/**
* @param level set the displaying log level. {@link LogLevel}
*
* since 1.0.2
*/
public static void setLogLevel(@NonNull LogLevel level) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,28 @@ protected void onThreadInfoClicked(@NonNull View view, int position, @NonNull Ba
startMessageThreadActivity(message);
}

/**
* Find the same message as the message ID and move it to the matching message.
*
* @param messageId the message id to move
* @param withAnimation {@code true} animate the message after focusing on it
* @return {@code true} if there is a message to move, {@code false} otherwise
* since 3.7.0
*/
public boolean moveToMessage(long messageId, boolean withAnimation) {
Logger.d(">> ChannelFragment::moveToMessage(%s), withAnimation=%s", messageId, withAnimation);
final MessageListComponent messageListComponent = getModule().getMessageListComponent();
final BaseMessage message = getViewModel().getMessageById(messageId);
if (message != null) {
final BaseMessage animateMessage = withAnimation ? message : null;
messageListComponent.moveToFocusedMessage(message.getCreatedAt(), animateMessage);
Logger.d("-- jumpToMessage return (true)");
return true;
}
Logger.d("-- return (couldn't find the message)");
return false;
}

private void onMessageTooltipClicked(@NonNull View view) {
scrollToFirst();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ internal abstract class BaseNotificationView @JvmOverloads internal constructor(
parentView.tag = message.messageId
val json = getExtendedSubData(message)
templateKey = json.getString(KeySet.template_key)
if (templateKey.isNullOrEmpty()) {
throw IllegalArgumentException("this message must have template key.")
}
var templateVariables: Map<String, String> = mapOf()
if (json.has(KeySet.template_variables)) {
templateVariables = json.getJSONObject(KeySet.template_variables).toStringMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.sendbird.uikit.internal.wrappers
import com.sendbird.android.AppInfo
import com.sendbird.android.ConnectionState
import com.sendbird.android.SendbirdChat
import com.sendbird.android.handler.AuthenticationHandler
import com.sendbird.android.handler.BaseChannelHandler
import com.sendbird.android.handler.CompletionHandler
import com.sendbird.android.handler.ConnectHandler
Expand Down Expand Up @@ -58,4 +59,13 @@ internal class SendbirdChatImpl : SendbirdChatWrapper {
override fun getUIKitConfiguration(handler: UIKitConfigurationHandler?) {
SendbirdChat.getUIKitConfiguration(handler)
}

override fun authenticateFeed(
userId: String,
accessToken: String?,
apiHost: String?,
handler: AuthenticationHandler?
) {
SendbirdChat.authenticateFeed(userId, accessToken, apiHost, handler)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.sendbird.uikit.internal.wrappers

import com.sendbird.android.AppInfo
import com.sendbird.android.ConnectionState
import com.sendbird.android.handler.AuthenticationHandler
import com.sendbird.android.handler.BaseChannelHandler
import com.sendbird.android.handler.CompletionHandler
import com.sendbird.android.handler.ConnectHandler
Expand All @@ -26,4 +27,6 @@ internal interface SendbirdChatWrapper {
fun getAppInfo(): AppInfo?
fun getConnectionState(): ConnectionState
fun getUIKitConfiguration(handler: UIKitConfigurationHandler?)

fun authenticateFeed(userId: String, accessToken: String?, apiHost: String?, handler: AuthenticationHandler?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.sendbird.android.handler.NotificationCollectionHandler;
import com.sendbird.android.message.BaseMessage;
import com.sendbird.android.params.MessageListParams;
import com.sendbird.uikit.SendbirdUIKit;
import com.sendbird.uikit.consts.StringSet;
import com.sendbird.uikit.interfaces.AuthenticateHandler;
import com.sendbird.uikit.interfaces.OnPagedDataLoader;
Expand Down Expand Up @@ -81,7 +82,7 @@ public FeedNotificationChannelViewModel(@NonNull String channelUrl, @Nullable Me
*/
@Override
public void authenticate(@NonNull AuthenticateHandler handler) {
connect((user, e) -> {
SendbirdUIKit.authenticateFeed((user, e) -> {
if (user != null) {
FeedChannel.getChannel(channelUrl, (channel, e1) -> {
FeedNotificationChannelViewModel.this.channel = channel;
Expand Down

0 comments on commit 6ceb8db

Please sign in to comment.