mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: 支持群临时消息推送携带群号以及群名称
This commit is contained in:
parent
494b1f1fd0
commit
3395cd9d95
@ -1,5 +1,6 @@
|
||||
package com.tencent.qqnt.kernel.api.impl;
|
||||
|
||||
import com.tencent.qqnt.kernel.nativeinterface.IGetTempChatInfoCallback;
|
||||
import com.tencent.qqnt.kernel.nativeinterface.IKernelMsgListener;
|
||||
import com.tencent.qqnt.kernel.nativeinterface.IOperateCallback;
|
||||
import com.tencent.qqnt.kernel.nativeinterface.RichMediaFilePathInfo;
|
||||
@ -24,4 +25,8 @@ public class MsgService {
|
||||
public void prepareTempChat(TempChatPrepareInfo tempChatPrepareInfo, IOperateCallback cb) {
|
||||
|
||||
}
|
||||
|
||||
public void getTempChatInfo(int chatType, @Nullable String uid, @Nullable IGetTempChatInfoCallback cb) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.tencent.qqnt.kernel.nativeinterface;
|
||||
|
||||
public interface IGetTempChatInfoCallback {
|
||||
void onResult(int code, String msg, TempChatInfo info);
|
||||
}
|
@ -9,6 +9,7 @@ import com.tencent.qqnt.kernel.nativeinterface.IOperateCallback
|
||||
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
||||
import com.tencent.qqnt.kernel.nativeinterface.MsgRecord
|
||||
import com.tencent.qqnt.kernel.nativeinterface.TempChatGameSession
|
||||
import com.tencent.qqnt.kernel.nativeinterface.TempChatInfo
|
||||
import com.tencent.qqnt.kernel.nativeinterface.TempChatPrepareInfo
|
||||
import com.tencent.qqnt.msg.api.IMsgService
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
@ -42,9 +43,12 @@ internal object MsgSvc: BaseSvc() {
|
||||
msgService.prepareTempChat(TempChatPrepareInfo(
|
||||
MsgConstant.KCHATTYPETEMPC2CFROMGROUP,
|
||||
ContactHelper.getUidByUinAsync(peerId = peerId.toLong()),
|
||||
app.getRuntimeService(ITroopMemberNameService::class.java, "all")
|
||||
.getTroopMemberNameRemarkFirst(groupId, peerId),
|
||||
groupId, EMPTY_BYTE_ARRAY, app.currentUid, "", TempChatGameSession()
|
||||
app.getRuntimeService(ITroopMemberNameService::class.java, "all").getTroopMemberNameRemarkFirst(groupId, peerId),
|
||||
groupId,
|
||||
EMPTY_BYTE_ARRAY,
|
||||
app.currentUid,
|
||||
"",
|
||||
TempChatGameSession()
|
||||
)) { code, reason ->
|
||||
if (code != 0) {
|
||||
LogCenter.log("临时会话创建失败: $code, $reason", Level.ERROR)
|
||||
@ -53,6 +57,24 @@ internal object MsgSvc: BaseSvc() {
|
||||
return Result.success(Unit)
|
||||
}
|
||||
|
||||
suspend fun getTempChatInfo(chatType: Int, uid: String): Result<TempChatInfo> {
|
||||
val msgService = app.getRuntimeService(IKernelService::class.java, "all").msgService
|
||||
?: return Result.failure(Exception("获取消息服务失败"))
|
||||
val info: TempChatInfo = withTimeoutOrNull(5000) {
|
||||
suspendCancellableCoroutine {
|
||||
msgService.getTempChatInfo(chatType, uid) { code, msg, tempChatInfo ->
|
||||
if (code == 0) {
|
||||
it.resume(tempChatInfo)
|
||||
} else {
|
||||
LogCenter.log("获取临时会话信息失败: $code:$msg", Level.ERROR)
|
||||
it.resume(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
} ?: return Result.failure(Exception("获取临时会话信息失败"))
|
||||
return Result.success(info)
|
||||
}
|
||||
|
||||
/**
|
||||
* 正常获取
|
||||
*/
|
||||
|
@ -114,7 +114,9 @@ internal object GlobalEventTransmitter: BaseSvc() {
|
||||
rawMsg: String,
|
||||
msgHash: Int,
|
||||
postType: PostType,
|
||||
tempSource: MessageTempSource = MessageTempSource.Unknown
|
||||
tempSource: MessageTempSource = MessageTempSource.Unknown,
|
||||
groupId: Long = Long.MIN_VALUE,
|
||||
fromNick: String? = null
|
||||
): Boolean {
|
||||
val botUin = app.longAccountUin
|
||||
var nickName = record.sendNickName
|
||||
@ -148,7 +150,9 @@ internal object GlobalEventTransmitter: BaseSvc() {
|
||||
title = "",
|
||||
level = "",
|
||||
),
|
||||
tmpSource = tempSource.id
|
||||
tmpSource = tempSource.id,
|
||||
groupId = groupId,
|
||||
fromNickName = fromNick
|
||||
)
|
||||
)
|
||||
return true
|
||||
|
@ -52,10 +52,10 @@ internal data class MessageEvent (
|
||||
@SerialName("message_type") val messageType: MsgType,
|
||||
@SerialName("sub_type") val subType: MsgSubType,
|
||||
@SerialName("message_id") val messageId: Int,
|
||||
@SerialName("group_id") val groupId: Long = 0,
|
||||
@SerialName("group_id") val groupId: Long = Long.MIN_VALUE,
|
||||
@SerialName("guild_id") val guildId: String? = null,
|
||||
@SerialName("channel_id") val channelId: String? = null,
|
||||
@SerialName("target_id") val targetId: Long = 0,
|
||||
@SerialName("target_id") val targetId: Long = Long.MIN_VALUE,
|
||||
@SerialName("peer_id") val peerId: Long,
|
||||
@SerialName("user_id") val userId: Long,
|
||||
@SerialName("anonymous") val anonymous: Anonymous? = null,
|
||||
@ -63,7 +63,8 @@ internal data class MessageEvent (
|
||||
@SerialName("raw_message") val rawMessage: String,
|
||||
@SerialName("font") val font: Int,
|
||||
@SerialName("sender") val sender: Sender,
|
||||
@SerialName("temp_source") val tmpSource: Int = -1
|
||||
@SerialName("temp_source") val tmpSource: Int = Int.MIN_VALUE,
|
||||
@SerialName("from_nick") val fromNickName: String? = null
|
||||
)
|
||||
|
||||
enum class MessageTempSource(val id: Int) {
|
||||
|
@ -7,6 +7,7 @@ import com.tencent.qqnt.kernel.nativeinterface.*
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import moe.fuqiuluo.qqinterface.servlet.MsgSvc
|
||||
import moe.fuqiuluo.qqinterface.servlet.TicketSvc
|
||||
import moe.fuqiuluo.qqinterface.servlet.msg.convert.toCQCode
|
||||
import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc
|
||||
@ -119,13 +120,22 @@ internal object AioListener : IKernelMsgListener {
|
||||
if (!rule.white.isNullOrEmpty() && !rule.white.contains(record.senderUin)) return
|
||||
}
|
||||
|
||||
|
||||
var groupCode = 0L
|
||||
var fromNick = ""
|
||||
MsgSvc.getTempChatInfo(record.chatType, record.senderUid).onSuccess {
|
||||
groupCode = it.groupCode.toLong()
|
||||
fromNick = it.fromNick
|
||||
}
|
||||
if (!GlobalEventTransmitter.MessageTransmitter.transPrivateMessage(
|
||||
record,
|
||||
record.elements,
|
||||
rawMsg,
|
||||
msgHash,
|
||||
tempSource = MessageTempSource.Group,
|
||||
postType = postType
|
||||
postType = postType,
|
||||
groupId = groupCode,
|
||||
fromNick = fromNick
|
||||
)
|
||||
) {
|
||||
LogCenter.log("私聊临时消息推送失败 -> MessageTransmitter", Level.WARN)
|
||||
|
Loading…
x
Reference in New Issue
Block a user