Unverified Commit 41f617c5 authored by Yang Libin's avatar Yang Libin Committed by GitHub

feat: update IMClient and message entities (#43)

* feat: update message entities * feat: update imclient
parent 633c5b6a
...@@ -12,11 +12,17 @@ import java.util.concurrent.ThreadLocalRandom; ...@@ -12,11 +12,17 @@ import java.util.concurrent.ThreadLocalRandom;
* @since 2021/07/29 16:11 * @since 2021/07/29 16:11
*/ */
public class IMClient { public class IMClient {
private final Long sdkAppId;
private final String userId;
private final String key;
private String userSig;
private long userSigExpireTs;
private static final String VERSION = "v4";
private static final long EXPIRE_TIME = 24 * 60 * 60L;
private static final ConcurrentHashMap<String, IMClient> IM_CLIENT = new ConcurrentHashMap<>(); private static final ConcurrentHashMap<String, IMClient> IM_CLIENT = new ConcurrentHashMap<>();
private static final String FORMAT_URL = "https://console.tim.qq.com/%s/%s/%s?sdkappid=%d&identifier=%s&usersig=%s&random=%d&contenttype=json"; private static final String FORMAT_URL = "https://console.tim.qq.com/%s/%s/%s?sdkappid=%d&identifier=%s&usersig=%s&random=%d&contenttype=json";
/**
* core methods
*/
public final Account account; public final Account account;
public final Message message; public final Message message;
public final Member member; public final Member member;
...@@ -25,17 +31,6 @@ public class IMClient { ...@@ -25,17 +31,6 @@ public class IMClient {
public final SNS sns; public final SNS sns;
public final Operation operation; public final Operation operation;
public final RecentContact recentContact; public final RecentContact recentContact;
/**
* init property
*/
private String userSig;
private long userSigExpireTs;
private final Long sdkAppId;
private final String userId;
private final String key;
private static final String VERSION = "v4";
private static final long EXPIRE_TIME = 24 * 60 * 60L;
public static IMClient getInstance(Long sdkAppId, String userId, String key) { public static IMClient getInstance(Long sdkAppId, String userId, String key) {
String identify = sdkAppId + "_" + userId; String identify = sdkAppId + "_" + userId;
...@@ -51,6 +46,7 @@ public class IMClient { ...@@ -51,6 +46,7 @@ public class IMClient {
this.key = key; this.key = key;
this.userSig = SigUtil.genUserSig(sdkAppId, key, userId, EXPIRE_TIME); this.userSig = SigUtil.genUserSig(sdkAppId, key, userId, EXPIRE_TIME);
this.userSigExpireTs = System.currentTimeMillis() / 1000 + EXPIRE_TIME - 100; this.userSigExpireTs = System.currentTimeMillis() / 1000 + EXPIRE_TIME - 100;
account = new Account(this); account = new Account(this);
message = new Message(this); message = new Message(this);
member = new Member(this); member = new Member(this);
...@@ -81,12 +77,4 @@ public class IMClient { ...@@ -81,12 +77,4 @@ public class IMClient {
} }
return userSig; return userSig;
} }
@Override
public String toString() {
return "IMClient{" +
"sdkAppId=" + sdkAppId +
", userId='" + userId + '\'' +
'}';
}
} }
...@@ -7,8 +7,14 @@ package io.github.doocs.im.constant; ...@@ -7,8 +7,14 @@ package io.github.doocs.im.constant;
* @since 2021/10/30 16:08 * @since 2021/10/30 16:08
*/ */
public class DeleteType { public class DeleteType {
/**
* 单向删除好友
*/
public static final String SINGLE = "Delete_Type_Single"; public static final String SINGLE = "Delete_Type_Single";
/**
* 双向删除好友
*/
public static final String BOTH = "Delete_Type_Both"; public static final String BOTH = "Delete_Type_Both";
private DeleteType() { private DeleteType() {
......
package io.github.doocs.im.constant;
/**
* 关系链
*
* @author bingo
* @since 2021/10/31 10:14
*/
public class TagSNS {
/**
* 好友分组
*/
public static final String IM_GROUP = "Tag_SNS_IM_Group";
/**
* 好友备注
*/
public static final String IM_REMARK = "Tag_SNS_IM_Remark";
/**
* 加好友来源
*/
public static final String IM_ADD_SOURCE = "Tag_SNS_IM_AddSource";
/**
* 加好友附言
*/
public static final String IM_ADD_WORDING = "Tag_SNS_IM_AddWording";
}
...@@ -16,11 +16,11 @@ public class TIMCustomMsgElement extends TIMMsgElement { ...@@ -16,11 +16,11 @@ public class TIMCustomMsgElement extends TIMMsgElement {
private CustomMsgContent msgContent; private CustomMsgContent msgContent;
public TIMCustomMsgElement() { public TIMCustomMsgElement() {
super(MsgType.TIM_CUSTOM_ELEM); this(null);
} }
public TIMCustomMsgElement(CustomMsgContent msgContent) { public TIMCustomMsgElement(CustomMsgContent msgContent) {
this(); super(MsgType.TIM_CUSTOM_ELEM);
this.msgContent = msgContent; this.msgContent = msgContent;
} }
......
...@@ -16,11 +16,11 @@ public class TIMFaceMsgElement extends TIMMsgElement { ...@@ -16,11 +16,11 @@ public class TIMFaceMsgElement extends TIMMsgElement {
private FaceMsgContent msgContent; private FaceMsgContent msgContent;
public TIMFaceMsgElement() { public TIMFaceMsgElement() {
super(MsgType.TIM_FACE_ELEM); this(null);
} }
public TIMFaceMsgElement(FaceMsgContent msgContent) { public TIMFaceMsgElement(FaceMsgContent msgContent) {
this(); super(MsgType.TIM_FACE_ELEM);
this.msgContent = msgContent; this.msgContent = msgContent;
} }
......
...@@ -16,11 +16,11 @@ public class TIMFileMsgElement extends TIMMsgElement { ...@@ -16,11 +16,11 @@ public class TIMFileMsgElement extends TIMMsgElement {
private FileMsgContent msgContent; private FileMsgContent msgContent;
public TIMFileMsgElement() { public TIMFileMsgElement() {
super(MsgType.TIM_FILE_ELEM); this(null);
} }
public TIMFileMsgElement(FileMsgContent msgContent) { public TIMFileMsgElement(FileMsgContent msgContent) {
this(); super(MsgType.TIM_FILE_ELEM);
this.msgContent = msgContent; this.msgContent = msgContent;
} }
......
...@@ -18,11 +18,11 @@ public class TIMImageMsgElement extends TIMMsgElement { ...@@ -18,11 +18,11 @@ public class TIMImageMsgElement extends TIMMsgElement {
private ImageMsgContent msgContent; private ImageMsgContent msgContent;
public TIMImageMsgElement() { public TIMImageMsgElement() {
super(MsgType.TIM_IMAGE_ELEM); this(null);
} }
public TIMImageMsgElement(ImageMsgContent msgContent) { public TIMImageMsgElement(ImageMsgContent msgContent) {
this(); super(MsgType.TIM_IMAGE_ELEM);
this.msgContent = msgContent; this.msgContent = msgContent;
} }
......
...@@ -16,11 +16,11 @@ public class TIMLocationMsgElement extends TIMMsgElement { ...@@ -16,11 +16,11 @@ public class TIMLocationMsgElement extends TIMMsgElement {
private LocationMsgContent msgContent; private LocationMsgContent msgContent;
public TIMLocationMsgElement() { public TIMLocationMsgElement() {
super(MsgType.TIM_LOCATION_ELEM); this(null);
} }
public TIMLocationMsgElement(LocationMsgContent msgContent) { public TIMLocationMsgElement(LocationMsgContent msgContent) {
this(); super(MsgType.TIM_LOCATION_ELEM);
this.msgContent = msgContent; this.msgContent = msgContent;
} }
......
...@@ -16,11 +16,11 @@ public class TIMSoundMsgElement extends TIMMsgElement { ...@@ -16,11 +16,11 @@ public class TIMSoundMsgElement extends TIMMsgElement {
private SoundMsgContent msgContent; private SoundMsgContent msgContent;
public TIMSoundMsgElement() { public TIMSoundMsgElement() {
super(MsgType.TIM_SOUND_ELEM); this(null);
} }
public TIMSoundMsgElement(SoundMsgContent msgContent) { public TIMSoundMsgElement(SoundMsgContent msgContent) {
this(); super(MsgType.TIM_SOUND_ELEM);
this.msgContent = msgContent; this.msgContent = msgContent;
} }
......
...@@ -20,7 +20,7 @@ public class TIMTextMsgElement extends TIMMsgElement { ...@@ -20,7 +20,7 @@ public class TIMTextMsgElement extends TIMMsgElement {
} }
public TIMTextMsgElement(TextMsgContent msgContent) { public TIMTextMsgElement(TextMsgContent msgContent) {
this(); super(MsgType.TIM_TEXT_ELEM);
this.msgContent = msgContent; this.msgContent = msgContent;
} }
......
...@@ -16,11 +16,11 @@ public class TIMVideoFileMsgElement extends TIMMsgElement { ...@@ -16,11 +16,11 @@ public class TIMVideoFileMsgElement extends TIMMsgElement {
private VideoFileMsgContent msgContent; private VideoFileMsgContent msgContent;
public TIMVideoFileMsgElement() { public TIMVideoFileMsgElement() {
super(MsgType.TIM_VIDEO_FILE_ELEM); this(null);
} }
public TIMVideoFileMsgElement(VideoFileMsgContent msgContent) { public TIMVideoFileMsgElement(VideoFileMsgContent msgContent) {
this(); super(MsgType.TIM_VIDEO_FILE_ELEM);
this.msgContent = msgContent; this.msgContent = msgContent;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment