Skip to content

Commit

Permalink
新增"好友消息撤回事件"
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyKidCN committed Dec 30, 2020
1 parent 989c333 commit 5ff91c5
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ public class 类名随意 extends IcqListener // 必须继承 IcqListener 监听
| EventNoticeGroupMemberInvite | 群员被邀请进群事件 |
| EventNoticeGroupUpload | 上传群文件事件 |
| EventNoticeGroupRecall | 群消息撤回事件 |
| EventNoticeFriendRecall | 好友消息撤回事件 |
| EventRequest | 所有请求事件 |
| EventFriendRequest | 加好友请求事件 |
| EventGroupAddRequest | 加群请求事件 |
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cc/moecraft/icq/PicqConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class PicqConstants
public static final String EVENT_KEY_NOTICE_TYPE_GROUP_INCREASE_INVITE = "invite";
public static final String EVENT_KEY_NOTICE_TYPE_GROUP_BAN = "group_ban";
public static final String EVENT_KEY_NOTICE_TYPE_GROUP_RECALL = "group_recall";
public static final String EVENT_KEY_NOTICE_TYPE_FRIEND_RECALL = "friend_recall";

public static final String EVENT_KEY_META_TYPE = "meta_event_type";
public static final String EVENT_KEY_META_TYPE_HEARTBEAT = "heartbeat";
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cc/moecraft/icq/event/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class EventManager
EventNoticeFriendAdd.class,
EventNoticeGroupUpload.class,
EventNoticeGroupRecall.class,
EventNoticeFriendRecall.class,
EventNotice.class,

EventFriendRequest.class,
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/cc/moecraft/icq/event/EventParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import cc.moecraft.icq.event.events.message.EventPrivateMessage;
import cc.moecraft.icq.event.events.meta.EventMetaHeartbeat;
import cc.moecraft.icq.event.events.meta.EventMetaLifecycle;
import cc.moecraft.icq.event.events.notice.EventNoticeFriendAdd;
import cc.moecraft.icq.event.events.notice.EventNoticeGroupBan;
import cc.moecraft.icq.event.events.notice.EventNoticeGroupRecall;
import cc.moecraft.icq.event.events.notice.EventNoticeGroupUpload;
import cc.moecraft.icq.event.events.notice.*;
import cc.moecraft.icq.event.events.notice.groupadmin.EventNoticeGroupAdminRemove;
import cc.moecraft.icq.event.events.notice.groupadmin.EventNoticeGroupAdminSet;
import cc.moecraft.icq.event.events.notice.groupmember.decrease.EventNoticeGroupMemberKick;
Expand All @@ -28,7 +25,6 @@
import java.util.Map;

import static cc.moecraft.icq.PicqConstants.*;
import static cc.moecraft.icq.PicqConstants.EVENT_KEY_NOTICE_TYPE_GROUP_RECALL;

/**
* The class {@code EventParser} has methods to decide which event
Expand Down Expand Up @@ -398,6 +394,13 @@ private void callNotice(JsonObject json)
}
break;
}
// 好友消息撤回
case EVENT_KEY_NOTICE_TYPE_FRIEND_RECALL:
{
EventNoticeFriendRecall event = gsonRead.fromJson(json, EventNoticeFriendRecall.class);
call(event);
break;
}
default: // 未识别
{
reportUnrecognized(EVENT_KEY_NOTICE_TYPE, noticeType, json);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cc.moecraft.icq.event.events.notice;

import cc.moecraft.icq.sender.returndata.returnpojo.get.RMessage;
import cc.moecraft.icq.user.User;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import lombok.*;

/**
* 好友消息撤回事件
*
* @author CrazyKid ([email protected])
* @since 2020/12/30 21:16
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Setter(AccessLevel.NONE)
@ToString(callSuper = true)
public class EventNoticeFriendRecall extends EventNotice {
/**
* 被撤回的消息 ID
*/
@SerializedName("message_id")
@Expose
protected Long messageId;

/**
* 获取消息发送者的用户对象
*
* @return 消息发送者的用户对象
*/
public User getSender() {
return getBot().getUserManager().getUserFromID(userId);
}

/**
* 获取被撤回的消息
*
* @param raw 是否获取未经处理的消息
* @return 消息内容
*/
public String getMessage(boolean raw) {
RMessage message = getHttpApi().getMsg(messageId).getData();
return raw ? message.getMessageRaw() : message.getMessage();
}

@Override
public boolean contentEquals(Object o) {
if (!(o instanceof EventNoticeFriendRecall)) return false;
EventNoticeFriendRecall other = (EventNoticeFriendRecall) o;

return super.contentEquals(o) &&
other.getMessageId().equals(this.getMessageId());
}
}

0 comments on commit 5ff91c5

Please sign in to comment.