Pq 3 lat temu
rodzic
commit
884ca6ae08

+ 27 - 3
rong_im/kit/src/main/java/io/rong/imkit/IMCenter.java

@@ -10,6 +10,7 @@ import com.cooleshow.base.constanst.UploadConstants;
 import com.cooleshow.base.utils.FileUtils;
 import com.cooleshow.base.utils.LogUtils;
 import com.cooleshow.base.utils.helper.upload.UploadHelper;
+import com.cooleshow.usercenter.helper.UserHelper;
 
 import java.io.File;
 import java.text.SimpleDateFormat;
@@ -1554,12 +1555,35 @@ public class IMCenter {
      * @param message 待发送的消息
      */
     public void handleBeforeSend(Message message) {
-        if (RongUserInfoManager.getInstance().getUserInfoAttachedState()
-                && message.getContent() != null && message.getContent().getUserInfo() == null) {
+        if (message.getContent() != null && message.getContent().getUserInfo() == null) {
             UserInfo userInfo = RongUserInfoManager.getInstance().getCurrentUserInfo();
             if (userInfo != null) {
-                message.getContent().setUserInfo(userInfo);
+                try {
+                    //如果数据为空则取出自身缓存补上
+                    if (TextUtils.isEmpty(userInfo.getName())) {
+                        userInfo.setName(UserHelper.getUserName());
+                    }
+                    if (userInfo.getPortraitUri() != null) {
+                        if (TextUtils.isEmpty(userInfo.getPortraitUri().toString())) {
+                            userInfo.setPortraitUri(Uri.parse(UserHelper.getUserAvatar()));
+                        }
+                    } else {
+                        userInfo.setPortraitUri(Uri.parse(UserHelper.getUserAvatar()));
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            } else {
+                try {
+                    String userName = UserHelper.getUserName();
+                    String userId = UserHelper.getUserId();
+                    Uri parse = Uri.parse(UserHelper.getUserAvatar());
+                    userInfo = new UserInfo(userName, userId, parse);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
             }
+            message.getContent().setUserInfo(userInfo);
         }
     }