This commit is contained in:
2025-10-20 10:16:44 +08:00
commit 437a623f81
3089 changed files with 1418412 additions and 0 deletions

81
tuichat/build.gradle Normal file
View File

@@ -0,0 +1,81 @@
import org.gradle.util.VersionNumber
plugins {
id 'com.android.library'
}
apply plugin: 'kotlin-android'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
namespace "com.tencent.qcloud.tuikit.tuichat"
defaultConfig {
minSdkVersion 19
targetSdkVersion 35
renderscriptSupportModeEnabled false
renderscriptTargetApi 30
javaCompileOptions {
annotationProcessorOptions {
arguments = [
AROUTER_MODULE_NAME: project.getName()
]
}
}
}
buildFeatures {
buildConfig = false
}
buildTypes {
release {
minifyEnabled false
}
}
def chatSourceJavaVersion = JavaVersion.VERSION_1_8
VersionNumber currentGradleVersion = VersionNumber.parse(gradle.gradleVersion)
if (currentGradleVersion.major >= 8) {
chatSourceJavaVersion = JavaVersion.VERSION_17
}
compileOptions {
sourceCompatibility chatSourceJavaVersion
targetCompatibility chatSourceJavaVersion
}
sourceSets {
main {
res.srcDirs += "src/main/res-minimalistui"
res.srcDirs += "src/main/res-light"
res.srcDirs += "src/main/res-lively"
res.srcDirs += "src/main/res-serious"
}
}
}
dependencies {
/*plugin-build-Begin
compileOnly fileTree(include: ['*.jar','*.aar'], dir: '../../../../tuikit/android/libs')
plugin-build-End*/
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'com.google.code.gson:gson:2.9.1'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'androidx.datastore:datastore-preferences:1.0.0'
implementation 'androidx.datastore:datastore-preferences-rxjava3:1.0.0'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
annotationProcessor 'com.google.auto.service:auto-service:1.1.1'
implementation(libs.arouter.api.v150)
//annotationProcessor
annotationProcessor libs.arouter.compiler
api(libs.greenrobot.eventbus)
api project(':timcommon')
}
apply plugin: 'com.alibaba.arouter' //

View File

@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<application>
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.component.imagevideobrowse.ImageVideoBrowseActivity"
android:launchMode="singleTask"
android:configChanges="screenSize|keyboardHidden|orientation" />
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.classicui.page.FriendProfileActivity"
android:screenOrientation="portrait" />
<!-- **************** Classic UI Start **************** -->
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.classicui.page.MessageReplyDetailActivity"
android:windowSoftInputMode="adjustResize|stateHidden"
android:screenOrientation="portrait" />
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIForwardChatActivity"
android:screenOrientation="portrait" />
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIC2CChatActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing|stateHidden" />
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIGroupChatActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing|stateHidden"/>
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.classicui.page.MessageReceiptDetailActivity"
android:screenOrientation="portrait" />
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.component.camera.CameraActivity"
android:screenOrientation="portrait" />
<activity android:name="com.tencent.qcloud.tuikit.tuichat.classicui.page.GroupInfoActivity"
android:screenOrientation="portrait" />
<activity android:name="com.tencent.qcloud.tuikit.tuichat.classicui.page.GroupNoticeActivity"
android:screenOrientation="portrait" />
<!-- **************** Classic UI End **************** -->
<!-- **************** Minimalist UI Start **************** -->
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.minimalistui.widget.messagepopmenu.ChatPopActivity"
android:theme="@style/ChatTransparentPopActivityStyle"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustNothing|stateHidden" />
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.minimalistui.page.TUIC2CChatMinimalistActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing|stateHidden" />
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.minimalistui.page.TUIGroupChatMinimalistActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing|stateHidden" />
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.minimalistui.page.MessageDetailMinimalistActivity"
android:screenOrientation="portrait" />
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.minimalistui.page.TUIForwardChatMinimalistActivity"
android:screenOrientation="portrait" />
<activity android:name="com.tencent.qcloud.tuikit.tuichat.minimalistui.page.GroupInfoMinimalistActivity"
android:screenOrientation="portrait" />
<activity
android:name="com.tencent.qcloud.tuikit.tuichat.minimalistui.page.FriendProfileMinimalistActivity"
android:screenOrientation="portrait" />
<activity android:name="com.tencent.qcloud.tuikit.tuichat.minimalistui.page.GroupNoticeMinimalistActivity"
android:screenOrientation="portrait" />
<!-- **************** Minimalist UI End **************** -->
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@@ -0,0 +1,98 @@
package com.tencent.qcloud.tuikit.tuichat;
import com.tencent.imsdk.BaseConstants;
public class TUIChatConstants {
public static final int ERR_SVR_COMM_SENSITIVE_IMAGE = BaseConstants.ERR_SVR_COMM_SENSITIVE_IMAGE;
public static final int ERR_SVR_COMM_SENSITIVE_TEXT = BaseConstants.ERR_SVR_COMM_SENSITIVE_TEXT;
public static final int ERR_LOCAL_COMM_SENSITIVE_TEXT = BaseConstants.ERR_SDK_BLOCKED_BY_SENSITIVE_WORD;
public static final String CAMERA_TYPE = "camera_type";
public static final String BUSINESS_ID_CUSTOM_HELLO = "text_link";
public static final String BUSINESS_ID_CUSTOM_EVALUATION = "evaluation";
public static final String BUSINESS_ID_CUSTOM_ORDER = "order";
public static final String BUSINESS_ID_CUSTOM_TYPING = "user_typing_status";
public static final String BUSINESS_ID_QUICK_TAP = "quick_tap";
public static final String BUSINESS_ID_LOCAL_TIPS = "local_tips";
public static final String FORWARD_SELECT_CONVERSATION_KEY = "forward_select_conversation_key";
public static final String FORWARD_MERGE_MESSAGE_KEY = "forward_merge_message_key";
public static final int GET_MESSAGE_FORWARD = 0;
public static final int GET_MESSAGE_BACKWARD = 1;
public static final int GET_MESSAGE_TWO_WAY = 2;
public static final int GET_MESSAGE_LOCATE = 3;
public static final String CHAT_INFO = "chatInfo";
public static final String MESSAGE_BEAN = "messageBean";
public static final String DATA_CHANGE_TYPE = "dataChangeType";
public static final String OPEN_MESSAGE_SCAN = "open_message_scan";
public static final String OPEN_MESSAGES_SCAN_FORWARD = "open_messages_scan_forward";
public static final String FORWARD_MODE = "forward_mode"; // 0,onebyone; 1,merge; 2,new message;
public static final int FORWARD_MODE_ONE_BY_ONE = 0;
public static final int FORWARD_MODE_MERGE = 1;
public static final int FORWARD_MODE_NEW_MESSAGE = 2;
public static final String SELECT_FRIENDS = "select_friends";
public static final String GROUP_ID = "group_id";
public static final String SELECT_FOR_CALL = "isSelectForCall";
public static final int TYPING_SEND_MESSAGE_INTERVAL = 4;
public static final int TYPING_PARSE_MESSAGE_INTERVAL = 5;
public static final int TYPING_TRIGGER_CHAT_TIME = 30; // second
public static final String EVENT_KEY_MESSAGE_STATUS_CHANGED = "eventKeyMessageStatusChanged";
public static final String EVENT_SUB_KEY_MESSAGE_SEND = "eventSubKeyMessageSend";
public static final String EVENT_KEY_OFFLINE_MESSAGE_PRIVATE_RING = "eventKeyOfflineMessagePrivteRing";
public static final String EVENT_SUB_KEY_OFFLINE_MESSAGE_PRIVATE_RING = "eventSubKeyOfflineMessagePrivteRing";
public static final String OFFLINE_MESSAGE_PRIVATE_RING = "offlineMessagePrivateRing";
/**
*
* 1: Just a text message with a link
* 2: The video calling version supported by iOS is no longer compatible
* 3: unreleased version
* 4: Android/iOS/Web interoperable version for video call
*/
public static final int JSON_VERSION_UNKNOWN = 0;
public static final int JSON_VERSION_1 = 1;
public static final int JSON_VERSION_4 = 4;
public static int version = JSON_VERSION_4;
public static final String CHAT_SETTINGS_SP_NAME = "chat_settings_sp";
public static final String CHAT_SP_KEY_SPEAKER_MODE_ON = "chat_sp_key_speaker_mode_on";
public static final class Group {
public static final String GROUP_ID = "group_id";
public static final String GROUP_INFO = "groupInfo";
}
public static class Selection {
public static final String TITLE = "title";
public static final String LIST = "list";
public static final String USER_ID_SELECT = "user_id_select";
public static final String USER_NAMECARD_SELECT = "user_namecard_select";
}
public static class DataStore {
public static final String DATA_STORE_NAME = "tuichat_datastore";
}
// Background
public static final String CHAT_CONVERSATION_BACKGROUND_URL =
"https://im.sdk.qcloud.com/download/tuikit-resource/conversation-backgroundImage/backgroundImage_%s_full.png";
public static final String CHAT_CONVERSATION_BACKGROUND_THUMBNAIL_URL =
"https://im.sdk.qcloud.com/download/tuikit-resource/conversation-backgroundImage/backgroundImage_%s.png";
public static final int CHAT_CONVERSATION_BACKGROUND_COUNT = 7;
public static final String CHAT_CONVERSATION_BACKGROUND_DEFAULT_URL = "chat/conversation/background/default/url";
public static final int CHAT_REQUEST_BACKGROUND_CODE = 1001;
public static final String CHAT_BACKGROUND_URI = "chatBackgroundUri";
public static final String GROUP_FACE_URL = "https://im.sdk.qcloud.com/download/tuikit-resource/group-avatar/group_avatar_%s.png";
public static final int GROUP_FACE_COUNT = 24;
}

View File

@@ -0,0 +1,876 @@
package com.tencent.qcloud.tuikit.tuichat;
import android.content.Context;
import android.text.TextUtils;
import com.google.auto.service.AutoService;
import com.tencent.imsdk.v2.V2TIMAdvancedMsgListener;
import com.tencent.imsdk.v2.V2TIMFriendInfo;
import com.tencent.imsdk.v2.V2TIMFriendshipListener;
import com.tencent.imsdk.v2.V2TIMGroupChangeInfo;
import com.tencent.imsdk.v2.V2TIMGroupListener;
import com.tencent.imsdk.v2.V2TIMGroupMemberInfo;
import com.tencent.imsdk.v2.V2TIMManager;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.imsdk.v2.V2TIMMessageReceipt;
import com.tencent.imsdk.v2.V2TIMSDKListener;
import com.tencent.imsdk.v2.V2TIMUserFullInfo;
import com.tencent.qcloud.tuicore.TUIConstants;
import com.tencent.qcloud.tuicore.TUICore;
import com.tencent.qcloud.tuicore.TUILogin;
import com.tencent.qcloud.tuicore.annotations.TUIInitializerDependency;
import com.tencent.qcloud.tuicore.annotations.TUIInitializerID;
import com.tencent.qcloud.tuicore.interfaces.ITUINotification;
import com.tencent.qcloud.tuicore.interfaces.ITUIService;
import com.tencent.qcloud.tuicore.interfaces.TUIInitializer;
import com.tencent.qcloud.tuikit.timcommon.bean.Emoji;
import com.tencent.qcloud.tuikit.timcommon.bean.FaceGroup;
import com.tencent.qcloud.tuikit.timcommon.bean.MessageReceiptInfo;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.UserBean;
import com.tencent.qcloud.tuikit.timcommon.component.face.FaceManager;
import com.tencent.qcloud.tuikit.timcommon.component.interfaces.IUIKitCallback;
import com.tencent.qcloud.tuikit.timcommon.util.ThreadUtils;
import com.tencent.qcloud.tuikit.tuichat.bean.C2CChatInfo;
import com.tencent.qcloud.tuikit.tuichat.bean.GroupChatInfo;
import com.tencent.qcloud.tuikit.tuichat.bean.message.CustomEvaluationMessageBean;
import com.tencent.qcloud.tuikit.tuichat.bean.message.CustomLinkMessageBean;
import com.tencent.qcloud.tuikit.tuichat.bean.message.CustomOrderMessageBean;
import com.tencent.qcloud.tuikit.tuichat.bean.message.MessageTypingBean;
import com.tencent.qcloud.tuikit.tuichat.bean.message.TipsMessageBean;
import com.tencent.qcloud.tuikit.tuichat.config.TUIChatConfigs;
import com.tencent.qcloud.tuikit.tuichat.interfaces.C2CChatEventListener;
import com.tencent.qcloud.tuikit.tuichat.interfaces.GroupChatEventListener;
import com.tencent.qcloud.tuikit.tuichat.interfaces.IBaseMessageSender;
import com.tencent.qcloud.tuikit.tuichat.interfaces.IMessageRecyclerView;
import com.tencent.qcloud.tuikit.tuichat.interfaces.NetworkConnectionListener;
import com.tencent.qcloud.tuikit.tuichat.interfaces.TotalUnreadCountListener;
import com.tencent.qcloud.tuikit.tuichat.presenter.C2CChatPresenter;
import com.tencent.qcloud.tuikit.tuichat.presenter.ChatPresenter;
import com.tencent.qcloud.tuikit.tuichat.presenter.GroupChatPresenter;
import com.tencent.qcloud.tuikit.tuichat.util.ChatMessageBuilder;
import com.tencent.qcloud.tuikit.tuichat.util.ChatMessageParser;
import com.tencent.qcloud.tuikit.tuichat.util.DataStoreUtil;
import com.tencent.qcloud.tuikit.tuichat.util.OfflinePushInfoUtils;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatUtils;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@AutoService(TUIInitializer.class)
@TUIInitializerDependency("TIMCommon")
@TUIInitializerID("TUIChat")
public class TUIChatService implements TUIInitializer, ITUIService, ITUINotification {
public static final String TAG = TUIChatService.class.getSimpleName();
private static TUIChatService instance;
public static TUIChatService getInstance() {
return instance;
}
private Context appContext;
private final List<WeakReference<GroupChatEventListener>> groupChatEventListenerList = new ArrayList<>();
private final List<WeakReference<C2CChatEventListener>> c2CChatEventListenerList = new ArrayList<>();
private WeakReference<IBaseMessageSender> messageSender;
private final List<WeakReference<TotalUnreadCountListener>> unreadCountListenerList = new ArrayList<>();
private final List<WeakReference<NetworkConnectionListener>> connectListenerList = new ArrayList<>();
private final Map<String, Class<? extends TUIMessageBean>> customMessageMap = new HashMap<>();
private final Set<Class<? extends TUIMessageBean>> extensionMessageClass = new HashSet<>();
@Override
public void init(Context context) {
instance = this;
appContext = context;
initMessageType();
initService();
initEvent();
initIMListener();
}
private void initService() {
TUICore.registerService(TUIConstants.TUIChat.SERVICE_NAME, this);
}
private void initEvent() {
TUICore.registerEvent(TUIConstants.TUIContact.EVENT_GROUP, TUIConstants.TUIContact.EVENT_SUB_KEY_GROUP_INFO_CHANGED, this);
TUICore.registerEvent(TUIConstants.TUIContact.EVENT_GROUP, TUIConstants.TUIContact.EVENT_SUB_KEY_EXIT_GROUP, this);
TUICore.registerEvent(TUIConstants.TUIContact.EVENT_GROUP, TUIConstants.TUIContact.EVENT_SUB_KEY_MEMBER_KICKED_GROUP, this);
TUICore.registerEvent(TUIConstants.TUIContact.EVENT_GROUP, TUIConstants.TUIContact.EVENT_SUB_KEY_GROUP_DISMISS, this);
TUICore.registerEvent(TUIConstants.TUIContact.EVENT_GROUP, TUIConstants.TUIContact.EVENT_SUB_KEY_JOIN_GROUP, this);
TUICore.registerEvent(TUIConstants.TUIContact.EVENT_GROUP, TUIConstants.TUIContact.EVENT_SUB_KEY_INVITED_GROUP, this);
TUICore.registerEvent(TUIConstants.TUIContact.EVENT_GROUP, TUIConstants.TUIContact.EVENT_SUB_KEY_GROUP_RECYCLE, this);
TUICore.registerEvent(TUIConstants.TUIContact.EVENT_FRIEND_INFO_CHANGED, TUIConstants.TUIContact.EVENT_SUB_KEY_FRIEND_REMARK_CHANGED, this);
TUICore.registerEvent(TUIConstants.TUIContact.EVENT_GROUP, TUIConstants.TUIContact.EVENT_SUB_KEY_CLEAR_GROUP_MESSAGE, this);
TUICore.registerEvent(TUIConstants.TUIContact.EVENT_USER, TUIConstants.TUIContact.EVENT_SUB_KEY_CLEAR_C2C_MESSAGE, this);
TUICore.registerEvent(TUIConstants.TUIConversation.EVENT_UNREAD, TUIConstants.TUIConversation.EVENT_SUB_KEY_UNREAD_CHANGED, this);
TUICore.registerEvent(TUIConstants.TUILogin.EVENT_LOGIN_STATE_CHANGED, TUIConstants.TUILogin.EVENT_SUB_KEY_USER_LOGIN_SUCCESS, this);
TUICore.registerEvent(TUIConstants.TUILogin.EVENT_IMSDK_INIT_STATE_CHANGED, TUIConstants.TUILogin.EVENT_SUB_KEY_START_INIT, this);
TUICore.registerEvent(TUIChatConstants.EVENT_KEY_MESSAGE_STATUS_CHANGED, TUIChatConstants.EVENT_SUB_KEY_MESSAGE_SEND, this);
TUICore.registerEvent(TUIChatConstants.EVENT_KEY_OFFLINE_MESSAGE_PRIVATE_RING, TUIChatConstants.EVENT_SUB_KEY_OFFLINE_MESSAGE_PRIVATE_RING, this);
TUICore.registerEvent(TUIConstants.TUIChat.EVENT_KEY_MESSAGE_EVENT, TUIConstants.TUIChat.EVENT_SUB_KEY_MESSAGE_INFO_CHANGED, this);
TUICore.registerEvent(TUIConstants.TUIContact.Event.GroupApplication.KEY_GROUP_APPLICATION,
TUIConstants.TUIContact.Event.GroupApplication.SUB_KEY_GROUP_APPLICATION_NUM_CHANGED, this);
}
@Override
public Object onCall(String method, Map<String, Object> param) {
if (TextUtils.equals(TUIConstants.TUIChat.METHOD_SEND_MESSAGE, method)) {
String chatId = (String) param.get(TUIConstants.TUIChat.CHAT_ID);
int chatType = (int) getOrDefault(param.get(TUIConstants.TUIChat.CHAT_TYPE), 0);
String content = (String) getOrDefault(param.get(TUIConstants.TUIChat.MESSAGE_CONTENT), "");
String description = (String) getOrDefault(param.get(TUIConstants.TUIChat.MESSAGE_DESCRIPTION), "");
String extension = (String) getOrDefault(param.get(TUIConstants.TUIChat.MESSAGE_EXTENSION), "");
IBaseMessageSender messageSender = getMessageSender();
if (messageSender != null) {
TUIMessageBean message = ChatMessageBuilder.buildCustomMessage(content, description, extension.getBytes());
return messageSender.sendMessage(message, chatId, TUIChatUtils.isGroupChat(chatType), false);
}
} else if (TextUtils.equals(TUIConstants.TUIChat.METHOD_EXIT_CHAT, method)) {
String chatId = (String) param.get(TUIConstants.TUIChat.CHAT_ID);
boolean isGroupChat = (boolean) param.get(TUIConstants.TUIChat.IS_GROUP_CHAT);
if (isGroupChat) {
List<GroupChatEventListener> groupChatEventListenerList = getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.exitGroupChat(chatId);
}
} else {
List<C2CChatEventListener> c2CChatEventListenerList = getC2CChatEventListenerList();
for (C2CChatEventListener c2CChatEventListener : c2CChatEventListenerList) {
c2CChatEventListener.exitC2CChat(chatId);
}
}
} else if (TextUtils.equals(TUIConstants.TUIChat.METHOD_GET_DISPLAY_STRING, method)) {
if (param != null) {
V2TIMMessage v2TIMMessage = (V2TIMMessage) param.get(TUIConstants.TUIChat.V2TIMMESSAGE);
if (v2TIMMessage != null) {
return ChatMessageParser.getDisplayString(v2TIMMessage);
}
}
} else if (TextUtils.equals(TUIConstants.TUIChat.METHOD_ADD_MESSAGE_TO_CHAT, method)) {
TUIMessageBean messageBean = (TUIMessageBean) param.get(TUIConstants.TUIChat.MESSAGE_BEAN);
String chatId = (String) param.get(TUIConstants.TUIChat.CHAT_ID);
boolean isGroupChat = (boolean) param.get(TUIConstants.TUIChat.IS_GROUP_CHAT);
if (isGroupChat) {
List<GroupChatEventListener> groupChatEventListenerList = getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.addMessage(messageBean, chatId);
}
} else {
List<C2CChatEventListener> c2CChatEventListenerList = getC2CChatEventListenerList();
for (C2CChatEventListener c2CChatEventListener : c2CChatEventListenerList) {
c2CChatEventListener.addMessage(messageBean, chatId);
}
}
} else if (TextUtils.equals(TUIConstants.TUIChat.Method.GetMessagesDisplayString.METHOD_NAME, method)) {
getMessagesDisplayString(param);
} else if (TextUtils.equals(TUIConstants.TUIChat.Method.GetTUIMessageBean.METHOD_NAME, method)) {
return getTUIMessagesBean(param);
}
return null;
}
public void setChatBackground(String chatID, String backgroundUrl) {
if (!TextUtils.isEmpty(backgroundUrl) && !TextUtils.isEmpty(chatID)) {
DataStoreUtil.getInstance().putValue(chatID, backgroundUrl);
}
}
@Override
public void onNotifyEvent(String key, String subKey, Map<String, Object> param) {
if (TextUtils.equals(key, TUIConstants.TUIContact.EVENT_GROUP)) {
handleGroupEvent(subKey, param);
} else if (key.equals(TUIConstants.TUIContact.EVENT_USER)) {
handleContactUserEvent(subKey, param);
} else if (key.equals(TUIConstants.TUIContact.EVENT_FRIEND_INFO_CHANGED)) {
handleFriendInfChangedEvent(subKey, param);
} else if (key.equals(TUIConstants.TUIConversation.EVENT_UNREAD)) {
handleUnreadChangedEvent(subKey, param);
} else if (TextUtils.equals(key, TUIConstants.TUILogin.EVENT_IMSDK_INIT_STATE_CHANGED)) {
handleInitStatusEvent(subKey);
} else if (TextUtils.equals(key, TUIConstants.TUILogin.EVENT_LOGIN_STATE_CHANGED)) {
handleLoginStatusEvent(subKey);
} else if (TextUtils.equals(key, TUIChatConstants.EVENT_KEY_MESSAGE_STATUS_CHANGED)) {
handleMessageStatusChangedEvent(subKey, param);
} else if (TextUtils.equals(key, TUIChatConstants.EVENT_KEY_OFFLINE_MESSAGE_PRIVATE_RING)) {
handleOfflineRingEvent(subKey, param);
} else if (TextUtils.equals(key, TUIConstants.TUIChat.EVENT_KEY_MESSAGE_EVENT)) {
handleMessageChangedEvent(subKey, param);
} else if (TextUtils.equals(TUIConstants.TUIContact.Event.GroupApplication.KEY_GROUP_APPLICATION, key)) {
handleGroupApplicationEvent(subKey, param);
}
}
private void handleOfflineRingEvent(String subKey, Map<String, Object> param) {
if (TextUtils.equals(subKey, TUIChatConstants.EVENT_SUB_KEY_OFFLINE_MESSAGE_PRIVATE_RING)) {
Boolean isPrivateRing = (Boolean) param.get(TUIChatConstants.OFFLINE_MESSAGE_PRIVATE_RING);
TUIChatConfigs.getConfigs().getGeneralConfig().setEnableAndroidPrivateRing(isPrivateRing);
Map<String, Object> paramRing = new HashMap<>();
paramRing.put(TUIConstants.TIMPush.CONFIG_FCM_CHANNEL_ID_KEY, OfflinePushInfoUtils.FCM_PUSH_CHANNEL_ID);
paramRing.put(TUIConstants.TIMPush.CONFIG_FCM_PRIVATE_RING_NAME_KEY, OfflinePushInfoUtils.PRIVATE_RING_NAME);
paramRing.put(TUIConstants.TIMPush.CONFIG_ENABLE_FCM_PRIVATE_RING_KEY, isPrivateRing);
TUICore.callService(TUIConstants.TIMPush.SERVICE_NAME, TUIConstants.TIMPush.METHOD_SET_CUSTOM_FCM_RING, paramRing);
}
}
private void handleMessageStatusChangedEvent(String subKey, Map<String, Object> param) {
if (TextUtils.equals(subKey, TUIChatConstants.EVENT_SUB_KEY_MESSAGE_SEND)) {
Object msgBeanObj = param.get(TUIChatConstants.MESSAGE_BEAN);
if (msgBeanObj instanceof TUIMessageBean) {
List<GroupChatEventListener> groupChatEventListenerList = getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onMessageChanged((TUIMessageBean) msgBeanObj, IMessageRecyclerView.DATA_CHANGE_TYPE_UPDATE);
}
List<C2CChatEventListener> c2CChatEventListenerList = getC2CChatEventListenerList();
for (C2CChatEventListener c2CChatEventListener : c2CChatEventListenerList) {
c2CChatEventListener.onMessageChanged((TUIMessageBean) msgBeanObj, IMessageRecyclerView.DATA_CHANGE_TYPE_UPDATE);
}
}
}
}
public void refreshMessage(TUIMessageBean messageBean) {
List<GroupChatEventListener> groupChatEventListenerList = getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onMessageChanged(messageBean, IMessageRecyclerView.DATA_CHANGE_TYPE_UPDATE);
}
List<C2CChatEventListener> c2CChatEventListenerList = getC2CChatEventListenerList();
for (C2CChatEventListener c2CChatEventListener : c2CChatEventListenerList) {
c2CChatEventListener.onMessageChanged(messageBean, IMessageRecyclerView.DATA_CHANGE_TYPE_UPDATE);
}
}
private void handleUnreadChangedEvent(String subKey, Map<String, Object> param) {
if (subKey.equals(TUIConstants.TUIConversation.EVENT_SUB_KEY_UNREAD_CHANGED)) {
long unreadCount = (long) param.get(TUIConstants.TUIConversation.TOTAL_UNREAD_COUNT);
List<TotalUnreadCountListener> totalUnreadCountListenerList = getUnreadCountListenerList();
for (TotalUnreadCountListener totalUnreadCountListener : totalUnreadCountListenerList) {
totalUnreadCountListener.onTotalUnreadCountChanged(unreadCount);
}
}
}
private void handleFriendInfChangedEvent(String subKey, Map<String, Object> param) {
if (subKey.equals(TUIConstants.TUIContact.EVENT_SUB_KEY_FRIEND_REMARK_CHANGED)) {
if (param == null || param.isEmpty()) {
return;
}
String id = (String) param.get(TUIConstants.TUIContact.FRIEND_ID);
String remark = (String) param.get(TUIConstants.TUIContact.FRIEND_REMARK);
List<C2CChatEventListener> c2CChatEventListenerList = getC2CChatEventListenerList();
for (C2CChatEventListener c2CChatEventListener : c2CChatEventListenerList) {
c2CChatEventListener.onFriendNameChanged(id, remark);
}
}
}
private void handleContactUserEvent(String subKey, Map<String, Object> param) {
if (subKey.equals(TUIConstants.TUIContact.EVENT_SUB_KEY_CLEAR_C2C_MESSAGE)) {
if (param == null || param.isEmpty()) {
return;
}
String userID = (String) getOrDefault(param.get(TUIConstants.TUIContact.FRIEND_ID), "");
List<C2CChatEventListener> c2CChatEventListenerList = getC2CChatEventListenerList();
for (C2CChatEventListener c2CChatEventListener : c2CChatEventListenerList) {
c2CChatEventListener.clearC2CMessage(userID);
}
}
}
private void handleMessageChangedEvent(String subKey, Map<String, Object> param) {
if (TextUtils.equals(subKey, TUIConstants.TUIChat.EVENT_SUB_KEY_MESSAGE_INFO_CHANGED)) {
TUIMessageBean messageBean = (TUIMessageBean) param.get(TUIConstants.TUIChat.MESSAGE_BEAN);
int dataChangeType = (int) param.get(TUIChatConstants.DATA_CHANGE_TYPE);
List<C2CChatEventListener> c2CChatEventListenerList = getInstance().getC2CChatEventListenerList();
for (C2CChatEventListener c2CChatEventListener : c2CChatEventListenerList) {
c2CChatEventListener.onMessageChanged(messageBean, dataChangeType);
}
List<GroupChatEventListener> groupChatEventListenerList = getInstance().getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onMessageChanged(messageBean, dataChangeType);
}
}
}
private void handleLoginStatusEvent(String subKey) {
if (TextUtils.equals(subKey, TUIConstants.TUILogin.EVENT_SUB_KEY_USER_LOGIN_SUCCESS)) {
// Set whether to open the floating window for voice and video calls
Map<String, Object> enableFloatWindowParam = new HashMap<>();
enableFloatWindowParam.put(
TUIConstants.TUICalling.PARAM_NAME_ENABLE_FLOAT_WINDOW, TUIChatConfigs.getGeneralConfig().isEnableFloatWindowForCall());
TUICore.callService(TUIConstants.TUICalling.SERVICE_NAME, TUIConstants.TUICalling.METHOD_NAME_ENABLE_FLOAT_WINDOW, enableFloatWindowParam);
// Set Whether to enable multi-terminal login function for audio and video calls
Map<String, Object> enableMultiDeviceParam = new HashMap<>();
enableMultiDeviceParam.put(
TUIConstants.TUICalling.PARAM_NAME_ENABLE_MULTI_DEVICE, TUIChatConfigs.getGeneralConfig().isEnableMultiDeviceForCall());
TUICore.callService(TUIConstants.TUICalling.SERVICE_NAME, TUIConstants.TUICalling.METHOD_NAME_ENABLE_MULTI_DEVICE, enableMultiDeviceParam);
// Set whether to enable incoming banner when user received audio and video calls
Map<String, Object> incomingBannerParam = new HashMap<>();
incomingBannerParam.put(
TUIConstants.TUICalling.PARAM_NAME_ENABLE_INCOMING_BANNER, TUIChatConfigs.getGeneralConfig().isEnableIncomingBanner());
TUICore.callService(TUIConstants.TUICalling.SERVICE_NAME, TUIConstants.TUICalling.METHOD_NAME_ENABLE_INCOMING_BANNER, incomingBannerParam);
// Set whether to enable the virtual background function for video calls.
Map<String, Object> virtualBackgroundForCallParams = new HashMap<>();
virtualBackgroundForCallParams.put(
TUIConstants.TUICalling.PARAM_NAME_ENABLE_VIRTUAL_BACKGROUND, TUIChatConfigs.getGeneralConfig().isEnableVirtualBackgroundForCall());
TUICore.callService(
TUIConstants.TUICalling.SERVICE_NAME, TUIConstants.TUICalling.METHOD_NAME_ENABLE_VIRTUAL_BACKGROUND, virtualBackgroundForCallParams);
}
}
private void handleInitStatusEvent(String subKey) {
if (TextUtils.equals(subKey, TUIConstants.TUILogin.EVENT_SUB_KEY_START_INIT)) {
loadBuildInFaces();
}
}
private void loadBuildInFaces() {
ThreadUtils.execute(() -> {
FaceGroup<Emoji> emojiFaceGroup = new FaceGroup<>();
// load chat default emojis
String[] emojiKeys = getAppContext().getResources().getStringArray(R.array.chat_buildin_emoji_key);
String[] emojiNames = getAppContext().getResources().getStringArray(R.array.chat_buildin_emoji_name);
String[] emojiPath = getAppContext().getResources().getStringArray(R.array.chat_buildin_emoji_file_name);
int emojiSize = getAppContext().getResources().getDimensionPixelSize(com.tencent.qcloud.tuikit.tuichat.R.dimen.chat_default_load_emoji_size);
for (int i = 0; i < emojiKeys.length; i++) {
String emojiKey = emojiKeys[i];
String emojiFilePath = "chatbuildinemojis/" + emojiPath[i];
Emoji emoji = FaceManager.loadAssetEmoji(emojiKey, emojiFilePath, emojiSize);
if (emoji != null) {
emoji.setFaceName(emojiNames[i]);
emojiFaceGroup.addFace(emojiKey, emoji);
}
}
emojiFaceGroup.setPageColumnCount(FaceManager.EMOJI_COLUMN_COUNT);
emojiFaceGroup.setPageRowCount(FaceManager.EMOJI_ROW_COUNT);
emojiFaceGroup.setFaceGroupIconUrl(com.tencent.qcloud.tuikit.tuichat.R.drawable.tuiemoji_default_emoji_group_icon);
FaceManager.addFaceGroup(FaceManager.EMOJI_GROUP_ID, emojiFaceGroup);
});
}
private void handleGroupEvent(String subKey, Map<String, Object> param) {
if (TextUtils.equals(subKey, TUIConstants.TUIContact.EVENT_SUB_KEY_EXIT_GROUP)
|| TextUtils.equals(subKey, TUIConstants.TUIContact.EVENT_SUB_KEY_GROUP_DISMISS)
|| TextUtils.equals(subKey, TUIConstants.TUIContact.EVENT_SUB_KEY_GROUP_RECYCLE)) {
List<GroupChatEventListener> groupChatEventListenerList = getGroupChatEventListenerList();
String groupId = null;
if (param != null) {
groupId = (String) getOrDefault(param.get(TUIConstants.TUIContact.GROUP_ID), "");
}
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onGroupForceExit(groupId);
}
} else if (TextUtils.equals(subKey, TUIConstants.TUIContact.EVENT_SUB_KEY_GROUP_INFO_CHANGED)) {
if (param == null) {
return;
}
String newGroupName = (String) getOrDefault(param.get(TUIConstants.TUIContact.GROUP_NAME), null);
String groupId = (String) getOrDefault(param.get(TUIConstants.TUIContact.GROUP_ID), "");
String groupFaceUrl = (String) getOrDefault(param.get(TUIConstants.TUIContact.GROUP_FACE_URL), null);
if (TextUtils.isEmpty(groupId)) {
return;
}
if (!TextUtils.isEmpty(newGroupName)) {
List<GroupChatEventListener> groupChatEventListenerList = getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onGroupNameChanged(groupId, newGroupName);
}
}
if (!TextUtils.isEmpty(groupFaceUrl)) {
List<GroupChatEventListener> groupChatEventListenerList = getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onGroupFaceUrlChanged(groupId, groupFaceUrl);
}
}
} else if (TextUtils.equals(subKey, TUIConstants.TUIContact.EVENT_SUB_KEY_MEMBER_KICKED_GROUP)) {
if (param == null) {
return;
}
String groupId = (String) getOrDefault(param.get(TUIConstants.TUIContact.GROUP_ID), "");
ArrayList<String> memberList = (ArrayList<String>) param.get(TUIConstants.TUIContact.GROUP_MEMBER_ID_LIST);
if (TextUtils.isEmpty(groupId) || memberList == null || memberList.isEmpty()) {
return;
}
String selfId = TUILogin.getLoginUser();
if (memberList.contains(selfId)) {
List<GroupChatEventListener> groupChatEventListenerList = getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onGroupForceExit(groupId);
}
}
} else if (TextUtils.equals(subKey, TUIConstants.TUIContact.EVENT_SUB_KEY_CLEAR_GROUP_MESSAGE)) {
String groupId = (String) getOrDefault(param.get(TUIConstants.TUIContact.GROUP_ID), "");
List<GroupChatEventListener> groupChatEventListenerList = getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.clearGroupMessage(groupId);
}
}
}
private void handleGroupApplicationEvent(String subKey, Map<String, Object> param) {
if (TextUtils.equals(subKey, TUIConstants.TUIContact.Event.GroupApplication.SUB_KEY_GROUP_APPLICATION_NUM_CHANGED)) {
List<GroupChatEventListener> groupChatEventListenerList = getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onApplied();
}
}
}
private Object getOrDefault(Object value, Object defaultValue) {
if (value != null) {
return value;
}
return defaultValue;
}
private <T> T getOrDefault(Map map, Object key, T defaultValue) {
if (map == null || map.isEmpty()) {
return defaultValue;
}
Object object = map.get(key);
try {
if (object != null) {
return (T) object;
}
} catch (ClassCastException e) {
return defaultValue;
}
return defaultValue;
}
private void initIMListener() {
V2TIMManager.getMessageManager().addAdvancedMsgListener(new V2TIMAdvancedMsgListener() {
@Override
public void onRecvNewMessage(V2TIMMessage msg) {
TUIMessageBean message = ChatMessageParser.parsePresentMessage(msg);
if (message == null) {
return;
}
HashMap<String, Object> param = new HashMap<>();
String conversationID;
if (TextUtils.isEmpty(msg.getGroupID())) {
List<C2CChatEventListener> c2CChatEventListenerList = getInstance().getC2CChatEventListenerList();
for (C2CChatEventListener c2CChatEventListener : c2CChatEventListenerList) {
c2CChatEventListener.onRecvNewMessage(message);
}
conversationID = TUIConstants.TUIConversation.CONVERSATION_C2C_PREFIX + msg.getUserID();
if (message instanceof MessageTypingBean) {
param.put(TUIConstants.TUIChat.IS_TYPING_MESSAGE, true);
} else {
param.put(TUIConstants.TUIChat.IS_TYPING_MESSAGE, false);
}
} else {
List<GroupChatEventListener> groupChatEventListenerList = getInstance().getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onRecvNewMessage(message);
}
conversationID = TUIConstants.TUIConversation.CONVERSATION_GROUP_PREFIX + msg.getGroupID();
}
param.put(TUIConstants.TUIChat.CONVERSATION_ID, conversationID);
TUICore.notifyEvent(TUIConstants.TUIChat.EVENT_KEY_RECEIVE_MESSAGE, TUIConstants.TUIChat.EVENT_SUB_KEY_CONVERSATION_ID, param);
}
@Override
public void onRecvMessageReadReceipts(List<V2TIMMessageReceipt> receiptList) {
List<C2CChatEventListener> c2CChatEventListenerList = getInstance().getC2CChatEventListenerList();
List<GroupChatEventListener> groupChatEventListenerList = getInstance().getGroupChatEventListenerList();
List<MessageReceiptInfo> messageReceiptInfos = new ArrayList<>();
for (V2TIMMessageReceipt messageReceipt : receiptList) {
MessageReceiptInfo messageReceiptInfo = new MessageReceiptInfo();
messageReceiptInfo.setMessageReceipt(messageReceipt);
messageReceiptInfos.add(messageReceiptInfo);
}
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onReadReport(messageReceiptInfos);
}
for (C2CChatEventListener c2CChatEventListener : c2CChatEventListenerList) {
c2CChatEventListener.onReadReport(messageReceiptInfos);
}
}
@Override
public void onRecvMessageRevoked(String msgID, V2TIMUserFullInfo operateUser, String reason) {
UserBean userBean = new UserBean();
userBean.setUserId(operateUser.getUserID());
userBean.setNickName(operateUser.getNickName());
userBean.setFaceUrl(operateUser.getFaceUrl());
List<C2CChatEventListener> c2CChatEventListenerList = getInstance().getC2CChatEventListenerList();
for (C2CChatEventListener c2CChatEventListener : c2CChatEventListenerList) {
c2CChatEventListener.onRecvMessageRevoked(msgID, userBean, reason);
}
List<GroupChatEventListener> groupChatEventListenerList = getInstance().getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onRecvMessageRevoked(msgID, userBean, reason);
}
}
@Override
public void onRecvMessageModified(V2TIMMessage msg) {
TUIMessageBean message = ChatMessageParser.parsePresentMessage(msg);
if (message == null) {
return;
}
List<C2CChatEventListener> c2CChatEventListenerList = getInstance().getC2CChatEventListenerList();
for (C2CChatEventListener c2CChatEventListener : c2CChatEventListenerList) {
c2CChatEventListener.onRecvMessageModified(message);
}
List<GroupChatEventListener> groupChatEventListenerList = getInstance().getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onRecvMessageModified(message);
}
TUIChatLog.i(TAG, "onRecvMessageModified msgID:" + msg.getMsgID());
}
@Override
public void onGroupMessagePinned(String groupID, V2TIMMessage v2TIMMessage, boolean isPinned, V2TIMGroupMemberInfo opUser) {
UserBean userBean = new UserBean();
userBean.setUserId(opUser.getUserID());
userBean.setNickName(opUser.getNickName());
userBean.setFaceUrl(opUser.getFaceUrl());
userBean.setFriendRemark(opUser.getFriendRemark());
userBean.setNameCard(opUser.getNameCard());
List<GroupChatEventListener> groupChatEventListenerList = getInstance().getGroupChatEventListenerList();
if (isPinned) {
TUIMessageBean messageBean = ChatMessageParser.parseMessage(v2TIMMessage);
if (messageBean == null) {
return;
}
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onGroupMessagePinned(groupID, messageBean, userBean);
}
} else {
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onGroupMessageUnPinned(groupID, v2TIMMessage.getMsgID(), userBean);
}
}
}
});
V2TIMManager.getFriendshipManager().addFriendListener(new V2TIMFriendshipListener() {
@Override
public void onFriendInfoChanged(List<V2TIMFriendInfo> infoList) {
List<C2CChatEventListener> c2CChatEventListenerList = getInstance().getC2CChatEventListenerList();
for (C2CChatEventListener c2CChatEventListener : c2CChatEventListenerList) {
for (V2TIMFriendInfo info : infoList) {
if (TextUtils.isEmpty(info.getFriendRemark())) {
String nickName = info.getUserProfile().getNickName();
if (TextUtils.isEmpty(nickName)) {
c2CChatEventListener.onFriendNameChanged(info.getUserID(), info.getUserID());
} else {
c2CChatEventListener.onFriendNameChanged(info.getUserID(), nickName);
}
} else {
c2CChatEventListener.onFriendNameChanged(info.getUserID(), info.getFriendRemark());
}
c2CChatEventListener.onFriendFaceUrlChanged(info.getUserID(), info.getUserProfile().getFaceUrl());
}
}
}
});
V2TIMManager.getInstance().addGroupListener(new V2TIMGroupListener() {
@Override
public void onGrantAdministrator(String groupID, V2TIMGroupMemberInfo opUser, List<V2TIMGroupMemberInfo> memberList) {
List<String> userIDs = new ArrayList<>();
for (V2TIMGroupMemberInfo info : memberList) {
userIDs.add(info.getUserID());
}
List<GroupChatEventListener> groupChatEventListenerList = getInstance().getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onGrantGroupAdmin(groupID, userIDs);
}
}
@Override
public void onRevokeAdministrator(String groupID, V2TIMGroupMemberInfo opUser, List<V2TIMGroupMemberInfo> memberList) {
List<String> userIDs = new ArrayList<>();
for (V2TIMGroupMemberInfo info : memberList) {
userIDs.add(info.getUserID());
}
List<GroupChatEventListener> groupChatEventListenerList = getInstance().getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onRevokeGroupAdmin(groupID, userIDs);
}
}
@Override
public void onGroupInfoChanged(String groupID, List<V2TIMGroupChangeInfo> changeInfos) {
for (V2TIMGroupChangeInfo changeInfo : changeInfos) {
if (changeInfo.getType() == V2TIMGroupChangeInfo.V2TIM_GROUP_INFO_CHANGE_TYPE_OWNER) {
List<GroupChatEventListener> groupChatEventListenerList = getInstance().getGroupChatEventListenerList();
for (GroupChatEventListener groupChatEventListener : groupChatEventListenerList) {
groupChatEventListener.onGrantGroupOwner(groupID, changeInfo.getValue());
}
}
}
}
});
V2TIMManager.getInstance().addIMSDKListener(new V2TIMSDKListener() {
@Override
public void onConnectSuccess() {
for (WeakReference<NetworkConnectionListener> listenerWeakReference : connectListenerList) {
NetworkConnectionListener listener = listenerWeakReference.get();
if (listener != null) {
listener.onConnected();
}
}
}
});
}
public void registerNetworkListener(NetworkConnectionListener listener) {
if (listener == null) {
return;
}
for (WeakReference<NetworkConnectionListener> weakReference : connectListenerList) {
NetworkConnectionListener networkConnectionListener = weakReference.get();
if (networkConnectionListener == listener) {
return;
}
}
WeakReference<NetworkConnectionListener> weakReference = new WeakReference<>(listener);
connectListenerList.add(weakReference);
}
// Initialize custom message types
private void initMessageType() {
addCustomMessageType(TUIChatConstants.BUSINESS_ID_CUSTOM_HELLO, CustomLinkMessageBean.class);
addCustomMessageType(TUIChatConstants.BUSINESS_ID_CUSTOM_EVALUATION, CustomEvaluationMessageBean.class);
addCustomMessageType(TUIChatConstants.BUSINESS_ID_CUSTOM_ORDER, CustomOrderMessageBean.class);
addCustomMessageType(TUIChatConstants.BUSINESS_ID_CUSTOM_TYPING, MessageTypingBean.class);
addCustomMessageType(TUIChatConstants.BUSINESS_ID_LOCAL_TIPS, TipsMessageBean.class);
}
/**
*
* Register a custom message type
* @param businessId Custom message unique identifiercannot be repeated
* @param beanClass MessageBean type
*/
public void addCustomMessageType(String businessId, Class<? extends TUIMessageBean> beanClass, boolean isDefault) {
if (customMessageMap.containsKey(businessId)) {
TUIChatLog.i(TAG, "addCustomMessageType: businessID already exists: " + businessId);
return;
}
customMessageMap.put(businessId, beanClass);
if (!isDefault) {
extensionMessageClass.add(beanClass);
}
}
/**
*
* Register a custom message type
* @param businessId Custom message unique identifiercannot be repeated
* @param beanClass MessageBean type
*/
public void addCustomMessageType(String businessId, Class<? extends TUIMessageBean> beanClass) {
addCustomMessageType(businessId, beanClass, true);
}
public Class<? extends TUIMessageBean> getMessageBeanClass(String businessId) {
return customMessageMap.get(businessId);
}
public Set<Class<? extends TUIMessageBean>> getExtensionMessageClassSet() {
return extensionMessageClass;
}
private List<GroupChatEventListener> getGroupChatEventListenerList() {
List<GroupChatEventListener> listeners = new ArrayList<>();
Iterator<WeakReference<GroupChatEventListener>> iterator = groupChatEventListenerList.listIterator();
while (iterator.hasNext()) {
WeakReference<GroupChatEventListener> listenerWeakReference = iterator.next();
GroupChatEventListener listener = listenerWeakReference.get();
if (listener == null) {
iterator.remove();
} else {
listeners.add(listener);
}
}
return listeners;
}
public void addGroupChatEventListener(GroupChatEventListener groupChatListener) {
if (groupChatListener == null) {
return;
}
for (WeakReference<GroupChatEventListener> listenerWeakReference : groupChatEventListenerList) {
if (listenerWeakReference.get() == groupChatListener) {
return;
}
}
groupChatEventListenerList.add(new WeakReference<>(groupChatListener));
}
private List<C2CChatEventListener> getC2CChatEventListenerList() {
List<C2CChatEventListener> listeners = new ArrayList<>();
Iterator<WeakReference<C2CChatEventListener>> iterator = c2CChatEventListenerList.listIterator();
while (iterator.hasNext()) {
WeakReference<C2CChatEventListener> listenerWeakReference = iterator.next();
C2CChatEventListener listener = listenerWeakReference.get();
if (listener == null) {
iterator.remove();
} else {
listeners.add(listener);
}
}
return listeners;
}
public void addC2CChatEventListener(C2CChatEventListener c2cChatEventListener) {
if (c2cChatEventListener == null) {
return;
}
for (WeakReference<C2CChatEventListener> listenerWeakReference : c2CChatEventListenerList) {
if (listenerWeakReference.get() == c2cChatEventListener) {
return;
}
}
c2CChatEventListenerList.add(new WeakReference<>(c2cChatEventListener));
}
public void removeC2CChatEventListener(C2CChatEventListener c2cChatEventListener) {
Iterator<WeakReference<C2CChatEventListener>> iterator = c2CChatEventListenerList.listIterator();
while (iterator.hasNext()) {
WeakReference<C2CChatEventListener> listenerWeakReference = iterator.next();
C2CChatEventListener listener = listenerWeakReference.get();
if (listener == c2cChatEventListener) {
iterator.remove();
}
}
}
public void setMessageSender(IBaseMessageSender baseMessageSender) {
messageSender = new WeakReference<>(baseMessageSender);
}
public void addUnreadCountListener(TotalUnreadCountListener unreadCountListener) {
if (unreadCountListener == null) {
return;
}
for (WeakReference<TotalUnreadCountListener> listenerWeakReference : unreadCountListenerList) {
if (listenerWeakReference.get() == unreadCountListener) {
return;
}
}
unreadCountListenerList.add(new WeakReference<>(unreadCountListener));
}
private List<TotalUnreadCountListener> getUnreadCountListenerList() {
List<TotalUnreadCountListener> listeners = new ArrayList<>();
Iterator<WeakReference<TotalUnreadCountListener>> iterator = unreadCountListenerList.listIterator();
while (iterator.hasNext()) {
WeakReference<TotalUnreadCountListener> listenerWeakReference = iterator.next();
TotalUnreadCountListener listener = listenerWeakReference.get();
if (listener == null) {
iterator.remove();
} else {
listeners.add(listener);
}
}
return listeners;
}
private IBaseMessageSender getMessageSender() {
if (messageSender != null) {
return messageSender.get();
}
return null;
}
public String sendMessage(TUIMessageBean messageBean, String chatId, int chatType, boolean onlineUserOnly) {
IBaseMessageSender messageSender = getMessageSender();
if (messageSender != null) {
return messageSender.sendMessage(messageBean, chatId, TUIChatUtils.isGroupChat(chatType), onlineUserOnly);
} else {
return null;
}
}
public static Context getAppContext() {
return instance.appContext;
}
private TUIMessageBean getTUIMessagesBean(Map<String, Object> param) {
Object v2TIMMessageObj = param.get(TUIConstants.TUIChat.Method.GetTUIMessageBean.V2TIM_MESSAGE);
if (v2TIMMessageObj instanceof V2TIMMessage) {
return ChatMessageParser.parsePresentMessage((V2TIMMessage) v2TIMMessageObj);
}
return null;
}
private void getMessagesDisplayString(Map<String, Object> param) {
Map<String, TUIMessageBean> conversationMessageBeanMap =
(Map<String, TUIMessageBean>) param.get(TUIConstants.TUIChat.Method.GetMessagesDisplayString.MESSAGE_MAP);
for (Map.Entry<String, TUIMessageBean> entry : conversationMessageBeanMap.entrySet()) {
String conversationID = entry.getKey();
TUIMessageBean tuiMessageBean = entry.getValue();
Set<String> userIDSet = tuiMessageBean.getAdditionalUserIDList();
if (userIDSet.isEmpty()) {
notifyMessageDisplayStringUpdated(conversationID, tuiMessageBean);
continue;
}
ChatPresenter chatPresenter;
if (conversationID.startsWith(TUIConstants.TUIConversation.CONVERSATION_C2C_PREFIX)) {
chatPresenter = new C2CChatPresenter();
C2CChatInfo c2CChatInfo = new C2CChatInfo();
c2CChatInfo.setId(conversationID.substring(TUIConstants.TUIConversation.CONVERSATION_C2C_PREFIX.length()));
((C2CChatPresenter) chatPresenter).setChatInfo(c2CChatInfo);
} else {
chatPresenter = new GroupChatPresenter();
GroupChatInfo groupChatInfo = new GroupChatInfo();
groupChatInfo.setId(conversationID.substring(TUIConstants.TUIConversation.CONVERSATION_GROUP_PREFIX.length()));
((GroupChatPresenter) chatPresenter).setGroupInfo(groupChatInfo);
}
chatPresenter.getUserBean(userIDSet, new IUIKitCallback<Map<String, UserBean>>() {
@Override
public void onSuccess(Map<String, UserBean> userBeanMap) {
for (String userID : userIDSet) {
UserBean userBean = userBeanMap.get(userID);
tuiMessageBean.setUserBean(userID, userBean);
}
notifyMessageDisplayStringUpdated(conversationID, tuiMessageBean);
}
@Override
public void onError(String module, int errCode, String errMsg) {
TUIChatLog.e(TAG, "getUserBean failed, errCode: " + errCode + ", errMsg: " + errMsg);
}
});
}
}
private void notifyMessageDisplayStringUpdated(String conversationID, TUIMessageBean messageBean) {
ThreadUtils.postOnUiThread(() -> {
Map<String, Object> param = new HashMap<>();
param.put(TUIConstants.TUIChat.Event.MessageDisplayString.CONVERSATION_ID, conversationID);
param.put(TUIConstants.TUIChat.Event.MessageDisplayString.MESSAGE_BEAN, messageBean);
TUICore.notifyEvent(
TUIConstants.TUIChat.Event.MessageDisplayString.KEY, TUIConstants.TUIChat.Event.MessageDisplayString.SUB_KEY_PROCESS_MESSAGE, param);
});
}
}

View File

@@ -0,0 +1,8 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
public class C2CChatInfo extends ChatInfo {
public C2CChatInfo() {
setType(ChatInfo.TYPE_C2C);
}
}

View File

@@ -0,0 +1,580 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import android.content.Context;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.tencent.imsdk.v2.V2TIMManager;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.imsdk.v2.V2TIMSignalingInfo;
import com.tencent.qcloud.tuicore.TUIConstants;
import com.tencent.qcloud.tuicore.TUILogin;
import com.tencent.qcloud.tuikit.timcommon.bean.UserBean;
import com.tencent.qcloud.tuikit.timcommon.util.DateTimeUtil;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class CallModel implements Cloneable, Serializable {
private static final String TAG = CallModel.class.getSimpleName();
/**
*
* The protocol type of calls
*/
public static final int CALL_PROTOCOL_TYPE_UNKNOWN = 0;
public static final int CALL_PROTOCOL_TYPE_SEND = 1;
public static final int CALL_PROTOCOL_TYPE_ACCEPT = 2;
public static final int CALL_PROTOCOL_TYPE_REJECT = 3;
public static final int CALL_PROTOCOL_TYPE_CANCEL = 4;
public static final int CALL_PROTOCOL_TYPE_HANGUP = 5;
public static final int CALL_PROTOCOL_TYPE_TIMEOUT = 6;
public static final int CALL_PROTOCOL_TYPE_LINE_BUSY = 7;
public static final int CALL_PROTOCOL_TYPE_SWITCH_TO_AUDIO = 8;
public static final int CALL_PROTOCOL_TYPE_SWITCH_TO_AUDIO_COMFIRM = 9;
/**
*
* The stream media type of calls
*/
public static final int CALL_STREAM_MEDIA_TYPE_UNKNOWN = 0;
public static final int CALL_STREAM_MEDIA_TYPE_VOICE = 1;
public static final int CALL_STREAM_MEDIA_TYPE_VIDEO = 2;
/**
*
* The participant style of calls
*/
public static final int CALL_PARTICIPANT_TYPE_UNKNOWN = 0;
public static final int CALL_PARTICIPANT_TYPE_C2C = 1;
public static final int CALL_PARTICIPANT_TYPE_GROUP = 2;
/**
*
* The role of participant
*/
public static final int CALL_PARTICIPANT_ROLE_UNKNOWN = 0;
public static final int CALL_PARTICIPANT_ROLE_CALLER = 1;
public static final int CALL_PARTICIPANT_ROLE_CALLEE = 2;
/**
* The direction of voice-video-call message
*/
public static final int CALL_MESSAGE_DIRECTION_INCOMING = 0;
public static final int CALL_MESSAGE_DIRECTION_OUTGOING = 1;
/**
* The style of voice-video-call message in TUIChat
*/
public static final int CHAT_CALLING_MESSAGE_APPEARANCE_DETAILS = 0;
public static final int CHAT_CALLING_MESSAGE_APPEARANCE_SIMPLIFY = 1;
public int style = CHAT_CALLING_MESSAGE_APPEARANCE_SIMPLIFY;
private Map jsonData;
public void setJsonData(Map jsonData) {
this.jsonData = jsonData;
}
private V2TIMSignalingInfo signalingInfo;
public void setSignalingInfo(V2TIMSignalingInfo signalingInfo) {
this.signalingInfo = signalingInfo;
}
private V2TIMMessage innerMessage;
public void setInnerMessage(V2TIMMessage innerMessage) {
this.innerMessage = innerMessage;
}
private int protocolType = CALL_PROTOCOL_TYPE_UNKNOWN;
private int streamMediaType = CALL_STREAM_MEDIA_TYPE_UNKNOWN;
private int participantType = CALL_PARTICIPANT_TYPE_UNKNOWN;
private int participantRole = CALL_PARTICIPANT_ROLE_UNKNOWN;
private String caller = "";
private Map<String, UserBean> participantsMap = new LinkedHashMap<>();
private int duration = 0;
public int getParticipantRole() {
return participantRole;
}
public int getParticipantType() {
return participantType;
}
public int getStreamMediaType() {
return streamMediaType;
}
public int getProtocolType() {
return protocolType;
}
public String getCaller() {
return caller;
}
public void setParticipant(String userId, UserBean userBean) {
if (participantsMap.containsKey(userId)) {
participantsMap.put(userId, userBean);
}
}
public static CallModel convert2VideoCallData(V2TIMMessage msg) {
V2TIMSignalingInfo signalingInfo = V2TIMManager.getSignalingManager().getSignalingInfo(msg);
if (signalingInfo == null) {
return null;
}
String businessId = null;
Double businessIdForTimeout = 0.0;
Object businessIdObj = null;
Gson gson = new Gson();
HashMap signalDataMap = null;
try {
signalDataMap = gson.fromJson(signalingInfo.getData(), HashMap.class);
if (signalDataMap != null) {
businessIdObj = signalDataMap.get(TUIConstants.Message.CUSTOM_BUSINESS_ID_KEY);
}
} catch (JsonSyntaxException e) {
TUIChatLog.e(TAG, " get signalingInfoCustomJsonMap error ");
}
if (businessIdObj instanceof String) {
businessId = (String) businessIdObj;
} else if (businessIdObj instanceof Double) {
businessIdForTimeout = (Double) businessIdObj;
}
boolean isV2CallBusinessId = TextUtils.equals(businessId, TUIConstants.TUICalling.CUSTOM_MESSAGE_BUSINESS_ID);
boolean isV3CallBusinessId = TextUtils.equals(businessId, TUIConstants.TUICalling.V3_CALL_BUSINESS_ID);
if (!isV2CallBusinessId && !isV3CallBusinessId
&& Math.abs(businessIdForTimeout - TUIConstants.TUICalling.CALL_TIMEOUT_BUSINESS_ID) >= 0.000001) {
return null;
}
CallModel callModel = new CallModel();
callModel.jsonData = signalDataMap;
callModel.signalingInfo = signalingInfo;
callModel.innerMessage = msg;
callModel.style = CHAT_CALLING_MESSAGE_APPEARANCE_SIMPLIFY;
callModel.caller = callModel.parseCaller();
callModel.protocolType = callModel.parseProtocolType();
callModel.streamMediaType = callModel.parseStreamMediaType();
callModel.participantType = callModel.parseParticipantType();
callModel.participantRole = callModel.parseParticipantRole();
callModel.duration = callModel.parseDuration();
for (String invitee : signalingInfo.getInviteeList()) {
callModel.participantsMap.put(invitee, null);
}
return callModel;
}
// ************** Parser for content ****************
private int parseProtocolType() {
if (this.jsonData == null || this.signalingInfo == null || this.innerMessage == null) {
return CALL_PROTOCOL_TYPE_UNKNOWN;
}
int type = CALL_PROTOCOL_TYPE_UNKNOWN;
switch (this.signalingInfo.getActionType()) {
case V2TIMSignalingInfo.SIGNALING_ACTION_TYPE_INVITE: {
Map data = (Map) this.jsonData.get("data");
if (data != null && data instanceof Map) {
// New version for calling
String cmd = (String) data.get("cmd");
if (cmd != null && cmd instanceof String) {
if (TextUtils.equals(cmd, "switchToAudio")) {
type = CALL_PROTOCOL_TYPE_SWITCH_TO_AUDIO;
} else if (TextUtils.equals(cmd, "hangup")) {
type = CALL_PROTOCOL_TYPE_HANGUP;
} else if (TextUtils.equals(cmd, "videoCall")) {
type = CALL_PROTOCOL_TYPE_SEND;
} else if (TextUtils.equals(cmd, "audioCall")) {
type = CALL_PROTOCOL_TYPE_SEND;
} else {
type = CALL_PROTOCOL_TYPE_UNKNOWN;
}
} else {
TUIChatLog.e(TAG, "calling protocol error, invalid cmd");
type = CALL_PROTOCOL_TYPE_UNKNOWN;
}
} else {
// Compatiable
if (this.jsonData.containsKey("call_end")) {
type = CALL_PROTOCOL_TYPE_HANGUP;
} else {
type = CALL_PROTOCOL_TYPE_SEND;
}
}
} break;
case V2TIMSignalingInfo.SIGNALING_ACTION_TYPE_CANCEL_INVITE: {
type = CALL_PROTOCOL_TYPE_CANCEL;
} break;
case V2TIMSignalingInfo.SIGNALING_ACTION_TYPE_ACCEPT_INVITE: {
Map data = (Map) this.jsonData.get("data");
if (data != null && data instanceof Map) {
// New version for calling
String cmd = (String) data.get("cmd");
if (cmd != null && cmd instanceof String) {
if (TextUtils.equals(cmd, "switchToAudio")) {
type = CALL_PROTOCOL_TYPE_SWITCH_TO_AUDIO_COMFIRM;
} else {
type = CALL_PROTOCOL_TYPE_ACCEPT;
}
} else {
TUIChatLog.e(TAG, "calling protocol error, invalid cmd");
type = CALL_PROTOCOL_TYPE_ACCEPT;
}
} else {
// Compatiable
type = CALL_PROTOCOL_TYPE_ACCEPT;
}
} break;
case V2TIMSignalingInfo.SIGNALING_ACTION_TYPE_REJECT_INVITE: {
if (this.jsonData.containsKey("line_busy")) {
type = CALL_PROTOCOL_TYPE_LINE_BUSY;
} else {
type = CALL_PROTOCOL_TYPE_REJECT;
}
} break;
case V2TIMSignalingInfo.SIGNALING_ACTION_TYPE_INVITE_TIMEOUT: {
type = CALL_PROTOCOL_TYPE_TIMEOUT;
} break;
default:
type = CALL_PROTOCOL_TYPE_UNKNOWN;
break;
}
return type;
}
private int parseStreamMediaType() {
if (protocolType == CALL_PROTOCOL_TYPE_UNKNOWN) {
return CALL_STREAM_MEDIA_TYPE_UNKNOWN;
}
// Default type
int type = CALL_STREAM_MEDIA_TYPE_UNKNOWN;
if (jsonData.containsKey("call_type")) {
double callType = (double) jsonData.get("call_type");
if (callType == 1) {
type = CALL_STREAM_MEDIA_TYPE_VOICE;
} else if (callType == 2) {
type = CALL_STREAM_MEDIA_TYPE_VIDEO;
}
}
// Read from special protocol
if (protocolType == CALL_PROTOCOL_TYPE_SEND) {
Map data = (Map) this.jsonData.get("data");
if (data != null && data instanceof Map) {
String cmd = (String) data.get("cmd");
if (cmd != null && cmd instanceof String) {
if (TextUtils.equals(cmd, "audioCall")) {
type = CALL_STREAM_MEDIA_TYPE_VOICE;
} else if (TextUtils.equals(cmd, "videoCall")) {
type = CALL_STREAM_MEDIA_TYPE_VIDEO;
}
}
}
} else if (protocolType == CALL_PROTOCOL_TYPE_SWITCH_TO_AUDIO || protocolType == CALL_PROTOCOL_TYPE_SWITCH_TO_AUDIO_COMFIRM) {
type = CALL_STREAM_MEDIA_TYPE_VIDEO;
}
return type;
}
private int parseParticipantType() {
if (this.protocolType == CALL_PROTOCOL_TYPE_UNKNOWN) {
return CALL_PARTICIPANT_TYPE_UNKNOWN;
}
if (this.signalingInfo.getGroupID().length() > 0) {
return CALL_PARTICIPANT_TYPE_GROUP;
} else {
return CALL_PARTICIPANT_TYPE_C2C;
}
}
private String parseCaller() {
String callerID = null;
Map data = (Map) this.jsonData.get("data");
if (data != null && data instanceof Map) {
String inviter = (String) data.get("inviter");
if (!TextUtils.isEmpty(inviter) && inviter instanceof String) {
callerID = inviter;
}
}
if (callerID == null) {
callerID = TUILogin.getLoginUser();
}
return callerID;
}
private int parseParticipantRole() {
if (TextUtils.equals(caller, TUILogin.getLoginUser())) {
return CALL_PARTICIPANT_ROLE_CALLER;
} else {
return CALL_PARTICIPANT_ROLE_CALLEE;
}
}
public boolean isExcludeFromHistory() {
if (style == CHAT_CALLING_MESSAGE_APPEARANCE_SIMPLIFY) {
return protocolType != CALL_PROTOCOL_TYPE_UNKNOWN && innerMessage.isExcludedFromLastMessage() && innerMessage.isExcludedFromUnreadCount();
} else {
return false;
}
}
public String getContent() {
if (style == CHAT_CALLING_MESSAGE_APPEARANCE_SIMPLIFY) {
return getContentForSimplifyAppearance();
} else {
return getContentForDetailsAppearance();
}
}
public int getDirection() {
if (style == CHAT_CALLING_MESSAGE_APPEARANCE_SIMPLIFY) {
return getDirectionForSimplifyAppearance();
} else {
return getDirectionForDetailsAppearance();
}
}
public boolean isUseReceiverAvatar() {
if (style == CHAT_CALLING_MESSAGE_APPEARANCE_SIMPLIFY) {
return isUseReceiverAvatarForSimplifyAppearance();
} else {
return isUseReceiverAvatarForDetailsAppearance();
}
}
public boolean isShowUnreadPoint() {
if (isExcludeFromHistory()) {
return false;
}
return (innerMessage.getLocalCustomInt() == 0) && (participantRole == CALL_PARTICIPANT_ROLE_CALLEE)
&& (participantType == CALL_PARTICIPANT_TYPE_C2C)
&& (protocolType == CALL_PROTOCOL_TYPE_CANCEL || protocolType == CALL_PROTOCOL_TYPE_TIMEOUT
|| protocolType == CALL_PROTOCOL_TYPE_LINE_BUSY);
}
public String getDisplayName() {
String displayName;
if (innerMessage == null) {
return null;
}
if (!TextUtils.isEmpty(innerMessage.getNameCard())) {
displayName = innerMessage.getNameCard();
} else if (!TextUtils.isEmpty(innerMessage.getFriendRemark())) {
displayName = innerMessage.getFriendRemark();
} else if (!TextUtils.isEmpty(innerMessage.getNickName())) {
displayName = innerMessage.getNickName();
} else {
displayName = innerMessage.getSender();
}
return displayName;
}
// ******* Details style ********
public String getContentForDetailsAppearance() {
Context context = TUIChatService.getAppContext();
boolean isGroup = (participantType == CALL_PARTICIPANT_TYPE_GROUP);
if (protocolType == CALL_PROTOCOL_TYPE_UNKNOWN) {
return context.getString(R.string.invalid_command);
}
String content = context.getString(R.string.invalid_command);
String senderShowName = getDisplayName();
if (protocolType == CALL_PROTOCOL_TYPE_SEND) {
// Launch call
content = isGroup ? ("\"" + senderShowName + "\"" + context.getString(R.string.start_group_call)) : (context.getString(R.string.start_call));
} else if (protocolType == CALL_PROTOCOL_TYPE_ACCEPT) {
// Accept call
content = isGroup ? ("\"" + senderShowName + "\"" + context.getString(R.string.accept_call)) : context.getString(R.string.accept_call);
} else if (protocolType == CALL_PROTOCOL_TYPE_REJECT) {
// Reject call
content = isGroup ? ("\"" + senderShowName + "\"" + context.getString(R.string.reject_group_calls)) : context.getString(R.string.reject_calls);
} else if (protocolType == CALL_PROTOCOL_TYPE_CANCEL) {
// Cancel pending call
content = isGroup ? context.getString(R.string.cancle_group_call) : context.getString(R.string.cancle_call);
} else if (protocolType == CALL_PROTOCOL_TYPE_HANGUP) {
content =
isGroup ? context.getString(R.string.stop_group_call) : context.getString(R.string.stop_call_tip) + DateTimeUtil.formatSecondsTo00(duration);
} else if (protocolType == CALL_PROTOCOL_TYPE_TIMEOUT) {
// Call timeout
StringBuilder mutableContent = new StringBuilder();
if (isGroup) {
for (String invitee : getParticipants()) {
mutableContent.append("\"");
mutableContent.append(invitee);
mutableContent.append("\"");
}
if (mutableContent.length() > 0) {
mutableContent.delete(mutableContent.length() - 1, mutableContent.length());
}
}
mutableContent.append(context.getString(R.string.no_response_call));
content = mutableContent.toString();
} else if (protocolType == CALL_PROTOCOL_TYPE_LINE_BUSY) {
// Hang up with line busy
content = isGroup ? ("\"" + senderShowName + "\"" + context.getString(R.string.line_busy)) : context.getString(R.string.other_line_busy);
} else if (protocolType == CALL_PROTOCOL_TYPE_SWITCH_TO_AUDIO) {
// Change video-call to voice-call
content = context.getString(R.string.chat_calling_switch_to_audio);
} else if (protocolType == CALL_PROTOCOL_TYPE_SWITCH_TO_AUDIO_COMFIRM) {
// Confirm the change of video-voice-call
content = context.getString(R.string.chat_calling_switch_to_audio_accept);
}
return content;
}
public List<String> getParticipants() {
List<String> participants = new ArrayList<>();
for (Map.Entry<String, UserBean> entry : participantsMap.entrySet()) {
UserBean userBean = entry.getValue();
if (userBean != null) {
participants.add(userBean.getDisplayName());
} else {
participants.add(entry.getKey());
}
}
return participants;
}
public List<String> getParticipantIDs() {
return signalingInfo.getInviteeList();
}
private int parseDuration() {
if (protocolType == CALL_PROTOCOL_TYPE_HANGUP) {
// Hang up
Object duration = jsonData.get("call_end");
if (duration == null) {
return 0;
}
return (int) Double.parseDouble(String.valueOf(duration));
}
return 0;
}
public int getDirectionForDetailsAppearance() {
if (innerMessage.isSelf()) {
return CALL_MESSAGE_DIRECTION_OUTGOING;
} else {
return CALL_MESSAGE_DIRECTION_INCOMING;
}
}
public boolean isUseReceiverAvatarForDetailsAppearance() {
return false;
}
// ******* Simplify style ********
public String getContentForSimplifyAppearance() {
if (isExcludeFromHistory()) {
return null;
}
boolean isCaller = (participantRole == CALL_PARTICIPANT_ROLE_CALLER);
Context context = TUIChatService.getAppContext();
String display = null;
String showName = getDisplayName();
if (participantType == CALL_PARTICIPANT_TYPE_C2C) {
// C2C shown: reject、cancel、hangup、timeout、line_busy
if (protocolType == CALL_PROTOCOL_TYPE_REJECT) {
display = isCaller ? context.getString(R.string.chat_call_reject_caller) : context.getString(R.string.chat_call_reject_callee);
} else if (protocolType == CALL_PROTOCOL_TYPE_CANCEL) {
display = isCaller ? context.getString(R.string.chat_call_cancel_caller) : context.getString(R.string.chat_call_cancel_callee);
} else if (protocolType == CALL_PROTOCOL_TYPE_HANGUP) {
display = context.getString(R.string.stop_call_tip) + DateTimeUtil.formatSecondsTo00(duration);
} else if (protocolType == CALL_PROTOCOL_TYPE_TIMEOUT) {
display = isCaller ? context.getString(R.string.chat_call_timeout_caller) : context.getString(R.string.chat_call_timeout_callee);
} else if (protocolType == CALL_PROTOCOL_TYPE_LINE_BUSY) {
display = isCaller ? context.getString(R.string.chat_call_line_busy_caller) : context.getString(R.string.chat_call_line_busy_callee);
}
// C2C compatiable
else if (protocolType == CALL_PROTOCOL_TYPE_SEND) {
display = context.getString(R.string.start_call);
} else if (protocolType == CALL_PROTOCOL_TYPE_ACCEPT) {
display = context.getString(R.string.accept_call);
} else if (protocolType == CALL_PROTOCOL_TYPE_SWITCH_TO_AUDIO) {
display = context.getString(R.string.chat_calling_switch_to_audio);
} else if (protocolType == CALL_PROTOCOL_TYPE_SWITCH_TO_AUDIO_COMFIRM) {
display = context.getString(R.string.chat_calling_switch_to_audio_accept);
} else {
display = context.getString(R.string.invalid_command);
}
} else if (participantType == CALL_PARTICIPANT_TYPE_GROUP) {
// Group shown: invite、cancel、hangup、timeout、line_busy
if (protocolType == CALL_PROTOCOL_TYPE_SEND) {
display = ("\"" + showName + "\"" + context.getString(R.string.chat_group_call_send));
} else if (protocolType == CALL_PROTOCOL_TYPE_CANCEL) {
display = context.getString(R.string.chat_group_call_end);
} else if (protocolType == CALL_PROTOCOL_TYPE_HANGUP) {
display = context.getString(R.string.chat_group_call_end);
} else if (protocolType == CALL_PROTOCOL_TYPE_TIMEOUT || protocolType == CALL_PROTOCOL_TYPE_LINE_BUSY) {
StringBuilder mutableContent = new StringBuilder();
if (participantType == CALL_PARTICIPANT_TYPE_GROUP) {
for (String invitee : getParticipants()) {
mutableContent.append("\"");
mutableContent.append(invitee);
mutableContent.append("\"");
}
if (mutableContent.length() > 0) {
mutableContent.delete(mutableContent.length() - 1, mutableContent.length());
}
}
if (protocolType == CALL_PROTOCOL_TYPE_LINE_BUSY) {
mutableContent.append(context.getString(R.string.chat_call_line_busy_callee));
} else {
mutableContent.append(context.getString(R.string.chat_group_call_no_answer));
}
display = mutableContent.toString();
}
// Group compatiable
else if (protocolType == CALL_PROTOCOL_TYPE_REJECT) {
display = context.getString(R.string.chat_group_call_reject_format, showName);
} else if (protocolType == CALL_PROTOCOL_TYPE_ACCEPT) {
display = context.getString(R.string.chat_group_call_accept_format, showName);
} else if (protocolType == CALL_PROTOCOL_TYPE_SWITCH_TO_AUDIO) {
display = context.getString(R.string.chat_group_call_switch_to_audio_format, showName);
} else if (protocolType == CALL_PROTOCOL_TYPE_SWITCH_TO_AUDIO_COMFIRM) {
display = context.getString(R.string.chat_group_call_confirm_switch_to_audio_format, showName);
} else {
display = context.getString(R.string.invalid_command);
}
} else {
display = context.getString(R.string.invalid_command);
}
return display;
}
public int getDirectionForSimplifyAppearance() {
if (participantRole == CALL_PARTICIPANT_ROLE_CALLER) {
return CALL_MESSAGE_DIRECTION_OUTGOING;
} else {
return CALL_MESSAGE_DIRECTION_INCOMING;
}
}
public boolean isUseReceiverAvatarForSimplifyAppearance() {
if (getDirection() == CallModel.CALL_MESSAGE_DIRECTION_OUTGOING) {
return !innerMessage.isSelf();
} else {
return innerMessage.isSelf();
}
}
}

View File

@@ -0,0 +1,245 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import com.tencent.imsdk.v2.V2TIMConversation;
import com.tencent.imsdk.v2.V2TIMGroupAtInfo;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class ChatInfo implements Serializable {
public static final int TYPE_C2C = V2TIMConversation.V2TIM_C2C;
public static final int TYPE_GROUP = V2TIMConversation.V2TIM_GROUP;
public static final int TYPE_INVALID = V2TIMConversation.CONVERSATION_TYPE_INVALID;
private static List<V2TIMGroupAtInfo> atInfoList;
protected String chatName;
protected String faceUrl;
private List<Object> iconUrlList = new ArrayList<>();
private int type;
private String id;
private boolean isTopChat;
private TUIMessageBean locateMessage;
boolean enableAudioCall = true;
boolean enableVideoCall = true;
boolean enableRoom = true;
boolean enableCustomHelloMessage = true;
boolean enablePoll = true;
boolean enableGroupNote = true;
private boolean enableTakePhoto = true;
private boolean enableRecordVideo = true;
private boolean enableFile = true;
private boolean enableAlbum = true;
boolean needReadReceipt = true;
private DraftInfo draft;
/**
*
* Get the title of the chat, usually the name of the other party for a single chat, and the group name for a group chat
*
* @return
*/
public String getChatName() {
return chatName;
}
public void setFaceUrl(String faceUrl) {
this.faceUrl = faceUrl;
}
public String getFaceUrl() {
return faceUrl;
}
/**
*
* Set the title of the chat, usually the name of the other party for a single chat, and the group name for a group chat
*
* @param chatName
*/
public void setChatName(String chatName) {
this.chatName = chatName;
}
/**
*
* Get the chat type, C2C is a single chat, Group is a group chat
*
* @return
*/
public int getType() {
return type;
}
/**
*
* Set the chat type, C2C is a single chat, Group is a group chat
*
* @param type
*/
public void setType(int type) {
this.type = type;
}
/**
*
* get chat id
*
* @return
*/
public String getId() {
return id;
}
/**
*
* set chat id
*
* @param id
*/
public void setId(String id) {
this.id = id;
}
/**
*
* Is it a pinned conversation
*
* @return
*/
public boolean isTopChat() {
return isTopChat;
}
/**
*
* Set whether the conversation is sticky
*
* @param topChat
*/
public void setTopChat(boolean topChat) {
isTopChat = topChat;
}
public List<V2TIMGroupAtInfo> getAtInfoList() {
return atInfoList;
}
public void setAtInfoList(List<V2TIMGroupAtInfo> atInfoList) {
this.atInfoList = atInfoList;
}
public void setLocateMessage(TUIMessageBean locateMessage) {
this.locateMessage = locateMessage;
}
public TUIMessageBean getLocateMessage() {
return locateMessage;
}
public void setDraft(DraftInfo draft) {
this.draft = draft;
}
public DraftInfo getDraft() {
return this.draft;
}
public List<Object> getIconUrlList() {
return iconUrlList;
}
public void setIconUrlList(List<Object> iconUrlList) {
this.iconUrlList = iconUrlList;
}
public boolean isEnableAudioCall() {
return enableAudioCall;
}
public void setEnableAudioCall(boolean enableAudioCall) {
this.enableAudioCall = enableAudioCall;
}
public boolean isEnableRoom() {
return enableRoom;
}
public void setEnableRoom(boolean enableRoom) {
this.enableRoom = enableRoom;
}
public boolean isEnableVideoCall() {
return enableVideoCall;
}
public void setEnableVideoCall(boolean enableVideoCall) {
this.enableVideoCall = enableVideoCall;
}
public boolean isEnableCustomHelloMessage() {
return enableCustomHelloMessage;
}
public void setEnableCustomHelloMessage(boolean enableCustomHelloMessage) {
this.enableCustomHelloMessage = enableCustomHelloMessage;
}
public void setEnablePoll(boolean enablePoll) {
this.enablePoll = enablePoll;
}
public boolean isEnablePoll() {
return enablePoll;
}
public void setEnableGroupNote(boolean enableGroupNote) {
this.enableGroupNote = enableGroupNote;
}
public boolean isEnableGroupNote() {
return enableGroupNote;
}
public void setEnableRecordVideo(boolean enableRecordVideo) {
this.enableRecordVideo = enableRecordVideo;
}
public boolean isEnableRecordVideo() {
return enableRecordVideo;
}
public void setEnableTakePhoto(boolean enableTakePhoto) {
this.enableTakePhoto = enableTakePhoto;
}
public boolean isEnableTakePhoto() {
return enableTakePhoto;
}
public void setEnableAlbum(boolean enableAlbum) {
this.enableAlbum = enableAlbum;
}
public boolean isEnableAlbum() {
return enableAlbum;
}
public void setEnableFile(boolean enableFile) {
this.enableFile = enableFile;
}
public boolean isEnableFile() {
return enableFile;
}
public boolean isNeedReadReceipt() {
return needReadReceipt;
}
public void setNeedReadReceipt(boolean needReadReceipt) {
this.needReadReceipt = needReadReceipt;
}
}

View File

@@ -0,0 +1,17 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.TUIChatConstants;
import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
import java.io.Serializable;
public class CustomHelloMessage implements Serializable {
public static final int CUSTOM_HELLO_ACTION_ID = 3;
public String businessID = TUIChatConstants.BUSINESS_ID_CUSTOM_HELLO;
public String text = TUIChatService.getAppContext().getString(R.string.welcome_tip);
public String link = "https://cloud.tencent.com/document/product/269/3794";
public int version = TUIChatConstants.JSON_VERSION_UNKNOWN;
}

View File

@@ -0,0 +1,30 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import java.io.Serializable;
public class DraftInfo implements Serializable {
private String draftText;
private long draftTime;
public String getDraftText() {
return draftText;
}
public void setDraftText(String draftText) {
this.draftText = draftText;
}
public long getDraftTime() {
return draftTime;
}
public void setDraftTime(long draftTime) {
this.draftTime = draftTime;
}
@Override
public String toString() {
return "DraftInfo{"
+ "draftText='" + draftText + '\'' + ", draftTime=" + draftTime + '}';
}
}

View File

@@ -0,0 +1,25 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import com.tencent.imsdk.v2.V2TIMGroupApplication;
import java.io.Serializable;
public class GroupApplyInfo implements Serializable {
private V2TIMGroupApplication timGroupApplication;
public GroupApplyInfo(V2TIMGroupApplication timGroupApplication) {
this.timGroupApplication = timGroupApplication;
}
public V2TIMGroupApplication getGroupApplication() {
return timGroupApplication;
}
public boolean isStatusHandled() {
if (timGroupApplication != null) {
return timGroupApplication.getHandleStatus() != V2TIMGroupApplication.V2TIM_GROUP_APPLICATION_HANDLE_STATUS_UNHANDLED;
}
return false;
}
}

View File

@@ -0,0 +1,81 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import com.tencent.imsdk.v2.V2TIMManager;
public class GroupChatInfo extends ChatInfo {
public static final String GROUP_TYPE_PUBLIC = V2TIMManager.GROUP_TYPE_PUBLIC;
public static final String GROUP_TYPE_WORK = V2TIMManager.GROUP_TYPE_WORK;
public static final String GROUP_TYPE_AVCHATROOM = V2TIMManager.GROUP_TYPE_AVCHATROOM;
public static final String GROUP_TYPE_MEETING = V2TIMManager.GROUP_TYPE_MEETING;
public static final String GROUP_TYPE_COMMUNITY = V2TIMManager.GROUP_TYPE_COMMUNITY;
private String groupType;
private String groupName;
private String notice;
public GroupChatInfo() {
setType(ChatInfo.TYPE_GROUP);
}
/**
*
* Get the group name
*
* @return
*/
public String getGroupName() {
return groupName;
}
/**
*
* Set the group name
*
* @param groupName
*/
public void setGroupName(String groupName) {
this.groupName = groupName;
}
/**
*
* Get the group notice
*
* @return
*/
public String getNotice() {
return notice;
}
/**
*
* Set the group notice
*
* @param signature
*/
public void setNotice(String signature) {
this.notice = signature;
}
/**
*
* Get the group type
*
* @return
*/
public String getGroupType() {
return groupType;
}
/**
*
* Set the group type
*
* @param groupType
*/
public void setGroupType(String groupType) {
this.groupType = groupType;
}
}

View File

@@ -0,0 +1,15 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import com.tencent.qcloud.tuikit.timcommon.bean.UserBean;
public class GroupMemberBean extends UserBean {
private int role;
public int getRole() {
return role;
}
public void setRole(int role) {
this.role = role;
}
}

View File

@@ -0,0 +1,123 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import android.text.TextUtils;
import com.tencent.imsdk.v2.V2TIMGroupMemberFullInfo;
import com.tencent.imsdk.v2.V2TIMGroupMemberInfo;
import java.io.Serializable;
public class GroupMemberInfo implements Serializable {
public static final int ROLE_MEMBER = V2TIMGroupMemberFullInfo.V2TIM_GROUP_MEMBER_ROLE_MEMBER;
public static final int ROLE_ADMIN = V2TIMGroupMemberFullInfo.V2TIM_GROUP_MEMBER_ROLE_ADMIN;
public static final int ROLE_OWNER = V2TIMGroupMemberFullInfo.V2TIM_GROUP_MEMBER_ROLE_OWNER;
private String iconUrl;
private String account;
private String signature;
private String location;
private String birthday;
private String nameCard;
private String friendRemark;
private String nickName;
private boolean isTopChat;
private boolean isFriend;
private long joinTime;
private long tinyId;
private int memberType;
private int role;
public String getIconUrl() {
return iconUrl;
}
public void setIconUrl(String iconUrl) {
this.iconUrl = iconUrl;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public void setNameCard(String nameCard) {
this.nameCard = nameCard;
}
public String getNameCard() {
return nameCard;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public String getNickName() {
return this.nickName;
}
public long getJoinTime() {
return joinTime;
}
public void setJoinTime(long joinTime) {
this.joinTime = joinTime;
}
public int getMemberType() {
return memberType;
}
public void setMemberType(int memberType) {
this.memberType = memberType;
}
public String getFriendRemark() {
return friendRemark;
}
public void setFriendRemark(String friendRemark) {
this.friendRemark = friendRemark;
}
public void setRole(int role) {
this.role = role;
}
public int getRole() {
return role;
}
public String getDisplayName() {
String displayName;
if (!TextUtils.isEmpty(nameCard)) {
displayName = nameCard;
} else if (!TextUtils.isEmpty(friendRemark)) {
displayName = friendRemark;
} else if (!TextUtils.isEmpty(nickName)) {
displayName = nickName;
} else {
displayName = account;
}
return displayName;
}
public GroupMemberInfo covertTIMGroupMemberInfo(V2TIMGroupMemberInfo info) {
if (info instanceof V2TIMGroupMemberFullInfo) {
V2TIMGroupMemberFullInfo v2TIMGroupMemberFullInfo = (V2TIMGroupMemberFullInfo) info;
setJoinTime(v2TIMGroupMemberFullInfo.getJoinTime());
setMemberType(v2TIMGroupMemberFullInfo.getRole());
setRole(v2TIMGroupMemberFullInfo.getRole());
}
setAccount(info.getUserID());
setNameCard(info.getNameCard());
setIconUrl(info.getFaceUrl());
setFriendRemark(info.getFriendRemark());
setNickName(info.getNickName());
return this;
}
}

View File

@@ -0,0 +1,37 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import com.tencent.imsdk.v2.V2TIMGroupMemberInfo;
import com.tencent.imsdk.v2.V2TIMGroupMessageReadMemberList;
import com.tencent.qcloud.tuikit.tuichat.bean.GroupMemberInfo;
import java.util.ArrayList;
import java.util.List;
public class GroupMessageReadMembersInfo {
private List<GroupMemberInfo> groupMemberInfoList;
private V2TIMGroupMessageReadMemberList readMembers;
public void setReadMembers(V2TIMGroupMessageReadMemberList readMembers) {
this.readMembers = readMembers;
groupMemberInfoList = new ArrayList<>();
List<V2TIMGroupMemberInfo> readMemberList = readMembers.getMemberInfoList();
for (V2TIMGroupMemberInfo v2TIMGroupMemberInfo : readMemberList) {
GroupMemberInfo memberInfo = new GroupMemberInfo();
memberInfo.covertTIMGroupMemberInfo(v2TIMGroupMemberInfo);
groupMemberInfoList.add(memberInfo);
}
}
public boolean isFinished() {
return readMembers.isFinished();
}
public long getNextSeq() {
readMembers.getMemberInfoList();
return readMembers.getNextSeq();
}
public List<GroupMemberInfo> getGroupMemberInfoList() {
return groupMemberInfoList;
}
}

View File

@@ -0,0 +1,111 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import android.view.View;
public class InputMoreItem {
private ChatInfo chatInfo;
private int iconResId;
private String name;
private int actionId;
private View unitView;
// 0, not need onActivityResult; 1, need onActivityResult
private int actionType = 0;
// The lower the number, the higher the priority
private int priority = 0;
private OnActionClickListener onClickListener = new OnActionClickListener();
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public int getChatType() {
if (chatInfo != null) {
return chatInfo.getType();
} else {
return 0;
}
}
public String getChatId() {
if (chatInfo != null) {
return chatInfo.getId();
} else {
return null;
}
}
public void setChatInfo(ChatInfo chatInfo) {
this.chatInfo = chatInfo;
}
public int getIconResId() {
return iconResId;
}
public void setIconResId(int iconResId) {
this.iconResId = iconResId;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public int getActionId() {
return actionId;
}
public void setActionId(int actionId) {
this.actionId = actionId;
}
public OnActionClickListener getOnClickListener() {
return onClickListener;
}
public void setOnClickListener(OnActionClickListener onClickListener) {
this.onClickListener = onClickListener;
}
public void setUnitView(View unitView) {
this.unitView = unitView;
}
public View getUnitView() {
return unitView;
}
public boolean isEnable(int chatType) {
return true;
}
public void onAction(String chatInfoId, int chatType) {}
public int getActionType() {
return actionType;
}
public void setActionType(int actionType) {
this.actionType = actionType;
}
public class OnActionClickListener {
public void onClick() {
onAction(getChatId(), getChatType());
}
}
}

View File

@@ -0,0 +1,8 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import com.tencent.qcloud.tuikit.tuichat.TUIChatConstants;
public class LocalTipsMessage {
public String businessID = TUIChatConstants.BUSINESS_ID_LOCAL_TIPS;
public String tips = "";
}

View File

@@ -0,0 +1,12 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
public class MessageCustom {
public static final String BUSINESS_ID_GROUP_CREATE = "group_create";
public int version = 0;
public String businessID;
public String opUser;
public String content;
public String data;
public int cmd = -1;
}

View File

@@ -0,0 +1,35 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import com.tencent.qcloud.tuikit.tuichat.TUIChatConstants;
import java.io.Serializable;
public class MessageTyping implements Serializable {
public String businessID = TUIChatConstants.BUSINESS_ID_CUSTOM_TYPING;
public int typingStatus = 0;
public int version = TUIChatConstants.JSON_VERSION_UNKNOWN;
public static final int TYPE_TYPING = 14;
public static final String EDIT_START = "EIMAMSG_InputStatus_Ing";
public static final String EDIT_END = "EIMAMSG_InputStatus_End";
public int userAction = 0;
public String actionParam = "";
public void setTypingStatus(boolean isTyping) {
if (isTyping) {
typingStatus = 1;
// old version
userAction = 14;
actionParam = "EIMAMSG_InputStatus_Ing";
} else {
typingStatus = 0;
// old version
userAction = 0;
actionParam = "EIMAMSG_InputStatus_End";
}
}
}

View File

@@ -0,0 +1,182 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import com.tencent.imsdk.message.MessageOfflinePushInfo;
import java.io.Serializable;
public class OfflinePushInfo implements Serializable {
private String title;
private String description;
private byte[] extension;
private String iosSoundFilePath;
private int pushFlag;
private int badgeMode;
private int notifyMode;
private String oppoChannelID;
private int vivoClassification = 1;
private String androidSoundFilePath;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public byte[] getExtension() {
return extension;
}
public void setExtension(byte[] extension) {
this.extension = extension;
}
public String getIOSSoundFilePath() {
return iosSoundFilePath;
}
public int getPushFlag() {
return pushFlag;
}
public void setPushFlag(int pushFlag) {
this.pushFlag = pushFlag;
}
public int getBadgeMode() {
return badgeMode;
}
public void setBadgeMode(int badgeMode) {
this.badgeMode = badgeMode;
}
public int getNotifyMode() {
return notifyMode;
}
public void setNotifyMode(int notifyMode) {
this.notifyMode = notifyMode;
}
public String getOppoChannelID() {
return oppoChannelID;
}
public void setOppoChannelID(String oppoChannelID) {
this.oppoChannelID = oppoChannelID;
}
public int getVivoClassification() {
return vivoClassification;
}
public void setVivoClassification(int vivoClassification) {
this.vivoClassification = vivoClassification;
}
public String getAndroidSound() {
return androidSoundFilePath;
}
/**
*
* Whether to disable push (push enabled by default)
*
* @param disable true: disable; false: enable
*/
public void disablePush(boolean disable) {
if (disable) {
setPushFlag(MessageOfflinePushInfo.OFFLINE_PUSH_FLAG_NO_PUSH);
} else {
setPushFlag(MessageOfflinePushInfo.OFFLINE_PUSH_FLAG_DEFAULT);
}
}
/**
*
* Get the offline push disablement status
*
* @return Disabled. true: disabled; false: enabled
*/
public boolean isDisablePush() {
if (getPushFlag() == MessageOfflinePushInfo.OFFLINE_PUSH_FLAG_NO_PUSH) {
return true;
} else {
return false;
}
}
/**
*
* Offline push sound setting (valid only for iOS)
* When sound is IOS_OFFLINE_PUSH_NO_SOUND, no sound is played when a message is received.
* When sound is IOS_OFFLINE_PUSH_DEFAULT_SOUND, the system alert sound is played when a message is received.
* To customize iOSSound, link the audio file to the Xcode project and set iOSSound to the audio filename (with the extension name).
*
* @param sound iOS Sound path
*/
public void setIOSSound(String sound) {
this.iosSoundFilePath = sound;
}
/**
*
* Offline push sound setting (valid only for Android, supported only in imsdk 6.1 and later versions)
* Only Huawei and Google phones support setting ringtone. And Xiaomi needs refer to https://dev.mi.com/console/doc/detail?pId=1278%23_3_0 .
*
* @param sound: The ringtone file name in the raw directory of the Android project, no suffix is required.
*/
public void setAndroidSound(String sound) {
this.androidSoundFilePath = sound;
}
/**
*
* Whether to ignore the badge count for offline push (valid only for iOS)
* If this parameter is set to true, the unread message count on the app badge will not increase when the message is received by the iOS device.
*
* @param ignoreIOSBadge iOS Status of the unread message count on the app badge. true: ignore; false: enable
*/
public void setIgnoreIOSBadge(boolean ignoreIOSBadge) {
if (ignoreIOSBadge) {
setBadgeMode(MessageOfflinePushInfo.OFFLINE_APNS_BADGE_MODE_IGNORE);
} else {
setBadgeMode(MessageOfflinePushInfo.OFFLINE_APNS_BADGE_MODE_DEFAULT);
}
}
public boolean isIgnoreIOSBadge() {
return badgeMode == MessageOfflinePushInfo.OFFLINE_APNS_BADGE_MODE_IGNORE;
}
/**
*
* Offline push channel ID for OPPO phones that run Android 8.0 or later
*
* @param channelID OPPO phone channel ID
*/
public void setAndroidOPPOChannelID(String channelID) {
setOppoChannelID(channelID);
}
/**
*
* Offline push setting for vivo phones
*
* @param classification Offline push message classification for vivo phones. 0: operation message; 1: system message. The default value is 1.
*/
public void setAndroidVIVOClassification(int classification) {
setVivoClassification(classification);
}
}

View File

@@ -0,0 +1,111 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import android.text.TextUtils;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import java.io.Serializable;
public class ReplyPreviewBean implements Serializable {
public static final int VERSION = 1;
private String messageID;
private String messageRootID;
private String messageAbstract;
private String messageSender;
private transient String messageSenderName;
private int messageType;
private long messageTime;
private long messageSequence;
private int version = VERSION;
private transient TUIMessageBean originalMessageBean;
public String getMessageID() {
return messageID;
}
public void setMessageID(String messageID) {
this.messageID = messageID;
}
public String getMessageAbstract() {
return messageAbstract;
}
public void setMessageAbstract(String messageAbstract) {
this.messageAbstract = messageAbstract;
}
public String getMessageSender() {
return messageSender;
}
public void setMessageSender(String messageSender) {
this.messageSender = messageSender;
}
public String getMessageSenderName() {
return messageSenderName;
}
public void setMessageSenderName(String messageSenderName) {
this.messageSenderName = messageSenderName;
}
public int getMessageType() {
return messageType;
}
public void setMessageType(int messageType) {
this.messageType = messageType;
}
public TUIMessageBean getOriginalMessageBean() {
return originalMessageBean;
}
public void setOriginalMessageBean(TUIMessageBean originalMessageBean) {
this.originalMessageBean = originalMessageBean;
}
public void setVersion(int version) {
this.version = version;
}
public int getVersion() {
return version;
}
public long getMessageSequence() {
return messageSequence;
}
public long getMessageTime() {
return messageTime;
}
public void setMessageSequence(long messageSequence) {
this.messageSequence = messageSequence;
}
public void setMessageTime(long messageTime) {
this.messageTime = messageTime;
}
public String getMessageRootID() {
return messageRootID;
}
public void setMessageRootID(String messageRootID) {
this.messageRootID = messageRootID;
}
/**
* @return true if it's replayMessage, or false it's quoteMessage
*/
public boolean isReplyMessage() {
return !TextUtils.isEmpty(messageRootID);
}
}

View File

@@ -0,0 +1,29 @@
package com.tencent.qcloud.tuikit.tuichat.bean;
import com.tencent.imsdk.v2.V2TIMUserStatus;
import java.io.Serializable;
public class UserStatusBean implements Serializable {
public static final int STATUS_ONLINE = V2TIMUserStatus.V2TIM_USER_STATUS_ONLINE;
public static final int STATUS_OFFLINE = V2TIMUserStatus.V2TIM_USER_STATUS_ONLINE;
private String userID;
private int onlineStatus = STATUS_OFFLINE;
public void setOnlineStatus(int onlineStatus) {
this.onlineStatus = onlineStatus;
}
public int getOnlineStatus() {
return onlineStatus;
}
public void setUserID(String userID) {
this.userID = userID;
}
public String getUserID() {
return userID;
}
}

View File

@@ -0,0 +1,96 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import android.text.TextUtils;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.timcommon.bean.UserBean;
import com.tencent.qcloud.tuikit.tuichat.bean.CallModel;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.TextReplyQuoteBean;
import java.util.List;
import java.util.Set;
public class CallingMessageBean extends TextMessageBean {
private CallModel callModel;
private int callType; // 1audio; 2:video
private boolean isCaller;
private String sender;
private boolean isShowUnreadPoint;
public static final int ACTION_ID_AUDIO_CALL = 1;
public static final int ACTION_ID_VIDEO_CALL = 2;
@Override
public String onGetDisplayString() {
if (callModel != null) {
return callModel.getContent();
}
return "";
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
}
@Override
public String getText() {
if (callModel != null) {
return callModel.getContent();
}
return "";
}
@Override
public String getExtra() {
if (callModel != null) {
return callModel.getContent();
}
return "";
}
public int getCallType() {
return callType;
}
public void setCallType(int callType) {
this.callType = callType;
}
public void setCaller(boolean isCaller) {
this.isCaller = isCaller;
}
public void setSender(String sender) {
this.sender = sender;
}
public void setShowUnreadPoint(boolean show) {
this.isShowUnreadPoint = show;
}
public boolean isShowUnreadPoint() {
return isShowUnreadPoint;
}
@Override
public boolean isSelf() {
return isCaller;
}
@Override
public String getSender() {
if (!TextUtils.isEmpty(sender)) {
return this.sender;
}
return super.getSender();
}
public void setCallModel(CallModel callModel) {
this.callModel = callModel;
}
@Override
public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
return TextReplyQuoteBean.class;
}
}

View File

@@ -0,0 +1,72 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.timcommon.bean.UserBean;
import com.tencent.qcloud.tuikit.tuichat.bean.CallModel;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.TextReplyQuoteBean;
import java.util.Set;
public class CallingTipsMessageBean extends TipsMessageBean {
private CallModel callModel;
@Override
public String onGetDisplayString() {
return getText();
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
}
@Override
public String getText() {
if (callModel != null) {
return callModel.getContent();
}
return "";
}
@Override
public String getExtra() {
if (callModel != null) {
return callModel.getContent();
}
return "";
}
@Override
public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
return TextReplyQuoteBean.class;
}
public void setCallModel(CallModel callModel) {
this.callModel = callModel;
}
public void setUserBean(String userID, UserBean userBean) {
if (callModel != null) {
callModel.setParticipant(userID, userBean);
}
}
@Override
public Set<String> getAdditionalUserIDList() {
Set<String> userIDSet = super.getAdditionalUserIDList();
if (callModel != null) {
userIDSet.addAll(callModel.getParticipantIDs());
}
return userIDSet;
}
@Override
public boolean needAsyncGetDisplayString() {
if (callModel != null) {
return callModel.getProtocolType() == CallModel.CALL_PROTOCOL_TYPE_TIMEOUT
&& callModel.getParticipantIDs() != null && !callModel.getParticipantIDs().isEmpty();
}
return false;
}
}

View File

@@ -0,0 +1,70 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.TUIChatConstants;
import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.CustomEvaluationMessageReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
import java.io.Serializable;
public class CustomEvaluationMessageBean extends TUIMessageBean {
public class CustomEvaluationMessage implements Serializable {
// public static final int CUSTOM_EVALUATION_ACTION_ID = 4;
public String businessID = TUIChatConstants.BUSINESS_ID_CUSTOM_EVALUATION;
public int score = 0;
public String comment = "";
public int version = TUIChatConstants.JSON_VERSION_UNKNOWN;
}
private CustomEvaluationMessage customEvaluationMessage;
@Override
public String onGetDisplayString() {
return getExtra();
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
String data = new String(v2TIMMessage.getCustomElem().getData());
TUIChatLog.d("CustomEvaluationMessageBean", "data = " + data);
if (!TextUtils.isEmpty(data)) {
try {
customEvaluationMessage = new Gson().fromJson(data, CustomEvaluationMessage.class);
} catch (Exception e) {
TUIChatLog.e("CustomEvaluationMessage", "exception e = " + e);
}
}
if (customEvaluationMessage != null) {
setExtra(TUIChatService.getAppContext().getString(R.string.custom_msg));
} else {
String text = TUIChatService.getAppContext().getString(R.string.no_support_msg);
setExtra(text);
}
}
public int getScore() {
if (customEvaluationMessage != null) {
return customEvaluationMessage.score;
}
return 0;
}
public String getContent() {
if (customEvaluationMessage != null) {
return customEvaluationMessage.comment;
}
return "";
}
@Override
public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
return CustomEvaluationMessageReplyQuoteBean.class;
}
}

View File

@@ -0,0 +1,58 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
import com.tencent.qcloud.tuikit.tuichat.bean.CustomHelloMessage;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.CustomLinkReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
public class CustomLinkMessageBean extends TUIMessageBean {
private CustomHelloMessage customHelloMessage;
@Override
public String onGetDisplayString() {
return getText();
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
String data = new String(v2TIMMessage.getCustomElem().getData());
if (!TextUtils.isEmpty(data)) {
try {
customHelloMessage = new Gson().fromJson(data, CustomHelloMessage.class);
} catch (Exception e) {
TUIChatLog.e("CustomLinkMessageBean", "exception e = " + e);
}
}
if (customHelloMessage != null) {
setExtra(customHelloMessage.text);
} else {
String text = TUIChatService.getAppContext().getString(R.string.no_support_msg);
setExtra(text);
}
}
public String getText() {
if (customHelloMessage != null) {
return customHelloMessage.text;
}
return getExtra();
}
public String getLink() {
if (customHelloMessage != null) {
return customHelloMessage.link;
}
return "";
}
@Override
public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
return CustomLinkReplyQuoteBean.class;
}
}

View File

@@ -0,0 +1,94 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.TUIChatConstants;
import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.CustomOrderMessageReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
import java.io.Serializable;
public class CustomOrderMessageBean extends TUIMessageBean {
public class CustomOrderMessage implements Serializable {
// public static final int CUSTOM_EVALUATION_ACTION_ID = 5;
public String businessID = TUIChatConstants.BUSINESS_ID_CUSTOM_ORDER;
public String imageUrl = "";
public String title = "";
public String description = "";
public String price = "";
public String link = "";
public int version = TUIChatConstants.JSON_VERSION_UNKNOWN;
}
private CustomOrderMessage orderMessage;
@Override
public String onGetDisplayString() {
return getExtra();
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
String data = new String(v2TIMMessage.getCustomElem().getData());
TUIChatLog.d("CustomOrderMessageBean", "data = " + data);
if (!TextUtils.isEmpty(data)) {
try {
orderMessage = new Gson().fromJson(data, CustomOrderMessage.class);
} catch (Exception e) {
TUIChatLog.e("CustomOrderMessageBean", "exception e = " + e);
}
}
if (orderMessage != null) {
setExtra(TUIChatService.getAppContext().getString(R.string.custom_msg));
} else {
String text = TUIChatService.getAppContext().getString(R.string.no_support_msg);
setExtra(text);
}
}
public String getImageUrl() {
if (orderMessage != null) {
return orderMessage.imageUrl;
}
return "";
}
public String getDescription() {
if (orderMessage != null) {
return orderMessage.description;
}
return "";
}
public String getTitle() {
if (orderMessage != null) {
return orderMessage.title;
}
return "";
}
public String getPrice() {
if (orderMessage != null) {
return orderMessage.price;
}
return "";
}
public String getLink() {
if (orderMessage != null) {
return orderMessage.link;
}
return "";
}
@Override
public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
return CustomOrderMessageReplyQuoteBean.class;
}
}

View File

@@ -0,0 +1,16 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
public class EmptyMessageBean extends TUIMessageBean {
@Override
public String onGetDisplayString() {
return "";
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
}
}

View File

@@ -0,0 +1,50 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import com.tencent.imsdk.v2.V2TIMFaceElem;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.FaceReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
public class FaceMessageBean extends TUIMessageBean {
private V2TIMFaceElem faceElem;
@Override
public String onGetDisplayString() {
return getExtra();
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
faceElem = v2TIMMessage.getFaceElem();
if (faceElem.getIndex() < 1 || faceElem.getData() == null) {
TUIChatLog.e("FaceMessageBean", "faceElem data is null or index<1");
return;
}
setExtra(TUIChatService.getAppContext().getString(R.string.custom_emoji));
}
public byte[] getData() {
if (faceElem != null) {
return faceElem.getData();
} else {
return new byte[0];
}
}
public int getIndex() {
if (faceElem != null) {
return faceElem.getIndex();
} else {
return 0;
}
}
@Override
public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
return FaceReplyQuoteBean.class;
}
}

View File

@@ -0,0 +1,55 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import com.tencent.imsdk.v2.V2TIMFileElem;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.FileReplyQuoteBean;
public class FileMessageBean extends TUIMessageBean {
private V2TIMFileElem fileElem;
private boolean isDownloading = false;
@Override
public String onGetDisplayString() {
return getExtra();
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
if (getStatus() == TUIMessageBean.MSG_STATUS_REVOKE) {
return;
}
fileElem = v2TIMMessage.getFileElem();
setExtra(TUIChatService.getAppContext().getString(R.string.file_extra));
}
public void setDownloading(boolean downloading) {
isDownloading = downloading;
}
public boolean isDownloading() {
return isDownloading;
}
public String getFileName() {
if (fileElem != null) {
return fileElem.getFileName();
}
return "";
}
public int getFileSize() {
if (fileElem != null) {
return fileElem.getFileSize();
}
return 0;
}
@Override
public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
return FileReplyQuoteBean.class;
}
}

View File

@@ -0,0 +1,158 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import com.tencent.imsdk.v2.V2TIMImageElem;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.ImageReplyQuoteBean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class ImageMessageBean extends TUIMessageBean {
/**
*
* original image
*/
public static final int IMAGE_TYPE_ORIGIN = V2TIMImageElem.V2TIM_IMAGE_TYPE_ORIGIN;
/**
*
* thumbnail
*/
public static final int IMAGE_TYPE_THUMB = V2TIMImageElem.V2TIM_IMAGE_TYPE_THUMB;
/**
*
* big picture
*/
public static final int IMAGE_TYPE_LARGE = V2TIMImageElem.V2TIM_IMAGE_TYPE_LARGE;
private int imgWidth;
private int imgHeight;
private V2TIMImageElem imageElem;
private List<ImageBean> imageBeanList;
@Override
public String onGetDisplayString() {
return getExtra();
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
imageElem = v2TIMMessage.getImageElem();
List<V2TIMImageElem.V2TIMImage> imageList = imageElem.getImageList();
if (imageList != null) {
List<ImageBean> imageBeans = new ArrayList<>();
for (V2TIMImageElem.V2TIMImage v2TIMImage : imageList) {
ImageBean imageBean = new ImageBean();
imageBean.setV2TIMImage(v2TIMImage);
imageBeans.add(imageBean);
if (imageBean.getType() == IMAGE_TYPE_THUMB) {
imgWidth = imageBean.getWidth();
imgHeight = imageBean.getHeight();
}
}
this.imageBeanList = imageBeans;
}
setExtra(TUIChatService.getAppContext().getString(R.string.picture_extra));
}
public void setImgHeight(int imgHeight) {
this.imgHeight = imgHeight;
}
public void setImgWidth(int imgWidth) {
this.imgWidth = imgWidth;
}
public int getImgHeight() {
return imgHeight;
}
public int getImgWidth() {
return imgWidth;
}
public List<ImageBean> getImageBeanList() {
return imageBeanList;
}
public ImageBean getImageBean(int type) {
for (ImageBean imageBean : imageBeanList) {
if (imageBean.getType() == type) {
return imageBean;
}
}
return null;
}
public String getPath() {
if (imageElem != null) {
return imageElem.getPath();
}
return "";
}
public static class ImageBean implements Serializable {
private V2TIMImageElem.V2TIMImage v2TIMImage;
public void setV2TIMImage(V2TIMImageElem.V2TIMImage v2TIMImage) {
this.v2TIMImage = v2TIMImage;
}
public V2TIMImageElem.V2TIMImage getV2TIMImage() {
return v2TIMImage;
}
public String getUUID() {
if (v2TIMImage != null) {
return v2TIMImage.getUUID();
}
return "";
}
public String getUrl() {
if (v2TIMImage != null) {
return v2TIMImage.getUrl();
}
return "";
}
public int getType() {
if (v2TIMImage != null) {
return v2TIMImage.getType();
}
return IMAGE_TYPE_THUMB;
}
public int getSize() {
if (v2TIMImage != null) {
return v2TIMImage.getSize();
}
return 0;
}
public int getHeight() {
if (v2TIMImage != null) {
return v2TIMImage.getHeight();
}
return 0;
}
public int getWidth() {
if (v2TIMImage != null) {
return v2TIMImage.getWidth();
}
return 0;
}
}
@Override
public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
return ImageReplyQuoteBean.class;
}
}

View File

@@ -0,0 +1,41 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.LocationReplyQuoteBean;
public class LocationMessageBean extends TUIMessageBean {
private String desc;
private double latitude;
private double longitude;
@Override
public String onGetDisplayString() {
return desc;
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
desc = v2TIMMessage.getLocationElem().getDesc();
longitude = v2TIMMessage.getLocationElem().getLongitude();
latitude = v2TIMMessage.getLocationElem().getLatitude();
}
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
public String getDesc() {
return desc;
}
@Override
public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
return LocationReplyQuoteBean.class;
}
}

View File

@@ -0,0 +1,57 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import com.tencent.imsdk.v2.V2TIMMergerElem;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.MergeReplyQuoteBean;
import java.util.ArrayList;
import java.util.List;
public class MergeMessageBean extends TUIMessageBean {
private V2TIMMergerElem mergerElem;
@Override
public String onGetDisplayString() {
return getExtra();
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
mergerElem = v2TIMMessage.getMergerElem();
setExtra(TUIChatService.getAppContext().getString(R.string.forward_extra));
}
public V2TIMMergerElem getMergerElem() {
return mergerElem;
}
public String getTitle() {
if (mergerElem != null) {
return mergerElem.getTitle();
}
return "";
}
public List<String> getAbstractList() {
if (mergerElem != null) {
return mergerElem.getAbstractList();
}
return new ArrayList<>();
}
public boolean isLayersOverLimit() {
if (mergerElem != null) {
return mergerElem.isLayersOverLimit();
}
return false;
}
@Override
public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
return MergeReplyQuoteBean.class;
}
}

View File

@@ -0,0 +1,40 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.tuichat.bean.MessageTyping;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
public class MessageTypingBean extends TUIMessageBean {
public MessageTyping messageTyping;
@Override
public String onGetDisplayString() {
return null;
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
String data = new String(v2TIMMessage.getCustomElem().getData());
TUIChatLog.d("messageTypingBean", "data = " + data);
if (!TextUtils.isEmpty(data)) {
try {
messageTyping = new Gson().fromJson(data, MessageTyping.class);
} catch (Exception e) {
TUIChatLog.e("messageTyping", "exception e = " + e);
}
}
if (messageTyping == null) {
TUIChatLog.e("messageTypingBean", "messageTyping is null");
}
}
public int getTypingStatus() {
if (messageTyping != null) {
return messageTyping.typingStatus;
}
return 0;
}
}

View File

@@ -0,0 +1,152 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.timcommon.bean.UserBean;
import com.tencent.qcloud.tuikit.tuichat.bean.ReplyPreviewBean;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.ReplyReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.TextReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.util.ChatMessageParser;
import java.util.Set;
/**
* Quote Message
*/
public class QuoteMessageBean extends TUIMessageBean {
// quote content
private TUIMessageBean contentMessageBean;
// origin message
private TUIMessageBean originMessageBean;
private final String originMsgId;
private final String originMsgAbstract;
private final String originMsgSender;
private final int originMsgType;
private final int version;
private boolean abstractEnable = false;
private TUIReplyQuoteBean replyQuoteBean;
public QuoteMessageBean(ReplyPreviewBean replyPreviewBean) {
originMsgId = replyPreviewBean.getMessageID();
originMsgAbstract = replyPreviewBean.getMessageAbstract();
originMsgSender = replyPreviewBean.getMessageSender();
originMsgType = replyPreviewBean.getMessageType();
version = replyPreviewBean.getVersion();
originMessageBean = replyPreviewBean.getOriginalMessageBean();
}
@Override
public String onGetDisplayString() {
if (contentMessageBean != null) {
return contentMessageBean.onGetDisplayString();
} else {
return "";
}
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
contentMessageBean = ChatMessageParser.parseMessageIgnoreReply(v2TIMMessage);
generateReplyQuoteBean();
setExtra(contentMessageBean.getExtra());
}
private void generateReplyQuoteBean() {
generateDefaultReplyQuoteBean();
if (originMessageBean == null) {
return;
}
Class<? extends TUIReplyQuoteBean> quoteReplyBeanClass = originMessageBean.getReplyQuoteBeanClass();
if (quoteReplyBeanClass != null) {
try {
replyQuoteBean = quoteReplyBeanClass.newInstance();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
}
if (replyQuoteBean != null) {
replyQuoteBean.onProcessReplyQuoteBean(originMessageBean);
replyQuoteBean.setMessageBean(originMessageBean);
replyQuoteBean.setMessageType(originMsgType);
replyQuoteBean.setDefaultAbstract(originMsgAbstract);
}
}
private void generateDefaultReplyQuoteBean() {
replyQuoteBean = new TextReplyQuoteBean();
replyQuoteBean.setDefaultAbstract(originMsgAbstract);
replyQuoteBean.setMessageType(originMsgType);
}
public TUIMessageBean getContentMessageBean() {
return contentMessageBean;
}
public void setOriginMessageBean(TUIMessageBean originMessageBean) {
this.originMessageBean = originMessageBean;
generateReplyQuoteBean();
}
public void setReplyQuoteBean(TUIReplyQuoteBean replyQuoteBean) {
this.replyQuoteBean = replyQuoteBean;
}
public TUIMessageBean getOriginMessageBean() {
return originMessageBean;
}
public String getOriginMsgId() {
return originMsgId;
}
public String getOriginMsgAbstract() {
return originMsgAbstract;
}
public String getOriginMsgSender() {
UserBean userBean = getUserBean(originMsgSender);
if (userBean != null) {
return userBean.getDisplayName();
}
return originMsgSender;
}
public int getOriginMsgType() {
return originMsgType;
}
public int getVersion() {
return version;
}
public TUIReplyQuoteBean getReplyQuoteBean() {
return replyQuoteBean;
}
public void setAbstractEnable(boolean abstractEnable) {
this.abstractEnable = abstractEnable;
}
public boolean isAbstractEnable() {
return abstractEnable;
}
@Override
public Set<String> getAdditionalUserIDList() {
Set<String> userIDList = super.getAdditionalUserIDList();
userIDList.add(originMsgSender);
return userIDList;
}
@Override
public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
return ReplyReplyQuoteBean.class;
}
}

View File

@@ -0,0 +1,19 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import com.tencent.qcloud.tuikit.tuichat.bean.ReplyPreviewBean;
/**
* Reply Message
*/
public class ReplyMessageBean extends QuoteMessageBean {
private final String msgRootId;
public ReplyMessageBean(ReplyPreviewBean replyPreviewBean) {
super(replyPreviewBean);
msgRootId = replyPreviewBean.getMessageRootID();
}
public String getMsgRootId() {
return msgRootId;
}
}

View File

@@ -0,0 +1,77 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.imsdk.v2.V2TIMSoundElem;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.SoundReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.presenter.ChatFileDownloadPresenter;
import java.io.File;
public class SoundMessageBean extends TUIMessageBean {
private static final int SOUND_HAS_NOT_PLAYED = 0;
private static final int SOUND_PLAYED = 1;
private V2TIMSoundElem soundElem;
private boolean isPlaying = false;
@Override
public String onGetDisplayString() {
return getExtra();
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
soundElem = v2TIMMessage.getSoundElem();
File soundFile = ChatFileDownloadPresenter.getSoundMessageFile(this);
if (soundFile == null) {
ChatFileDownloadPresenter.downloadSound(this, null);
}
setExtra(TUIChatService.getAppContext().getString(R.string.audio_extra));
}
public void setPlayed() {
if (getV2TIMMessage() != null) {
getV2TIMMessage().setLocalCustomInt(SOUND_PLAYED);
}
}
public boolean hasPlayed() {
if (getV2TIMMessage() != null) {
int customInt = getV2TIMMessage().getLocalCustomInt();
return customInt == SOUND_PLAYED;
}
return false;
}
public String getUUID() {
if (soundElem != null) {
return soundElem.getUUID();
}
return "";
}
public int getDuration() {
if (soundElem != null) {
return soundElem.getDuration();
}
return 0;
}
public void setPlaying(boolean playing) {
isPlaying = playing;
}
public boolean isPlaying() {
return isPlaying;
}
@Override
public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
return SoundReplyQuoteBean.class;
}
}

View File

@@ -0,0 +1,3 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
public class TextAtMessageBean extends TextMessageBean {}

View File

@@ -0,0 +1,36 @@
package com.tencent.qcloud.tuikit.tuichat.bean.message;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.TextReplyQuoteBean;
public class TextMessageBean extends TUIMessageBean {
private String text;
@Override
public String onGetDisplayString() {
return text;
}
@Override
public void onProcessMessage(V2TIMMessage v2TIMMessage) {
if (v2TIMMessage.getTextElem() != null) {
text = v2TIMMessage.getTextElem().getText();
}
setExtra(text);
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
@Override
public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
return TextReplyQuoteBean.class;
}
}

Some files were not shown because too many files have changed in this diff Show More