mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
ShamrockPublic
: 自発メッセージ同期ロジックの変更
Signed-off-by: WhiteChi <whitechi73@outlook.com>
This commit is contained in:
parent
41675ed874
commit
c3c14d6ead
@ -11,6 +11,7 @@ import moe.fuqiuluo.shamrock.helper.MessageHelper
|
|||||||
import moe.fuqiuluo.shamrock.helper.LogCenter
|
import moe.fuqiuluo.shamrock.helper.LogCenter
|
||||||
import moe.fuqiuluo.shamrock.xposed.helper.NTServiceFetcher
|
import moe.fuqiuluo.shamrock.xposed.helper.NTServiceFetcher
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
internal object MsgSvc: BaseSvc() {
|
internal object MsgSvc: BaseSvc() {
|
||||||
fun uploadForwardMsg(): Result<String> {
|
fun uploadForwardMsg(): Result<String> {
|
||||||
@ -60,7 +61,7 @@ internal object MsgSvc: BaseSvc() {
|
|||||||
return Result.failure(Exception("获取消息服务"))
|
return Result.failure(Exception("获取消息服务"))
|
||||||
|
|
||||||
val msg = withTimeoutOrNull(5000) {
|
val msg = withTimeoutOrNull(5000) {
|
||||||
suspendCancellableCoroutine { continuation ->
|
suspendCoroutine { continuation ->
|
||||||
service.getMsgsByMsgId(contact, arrayListOf(qqMsgId)) { code, _, msgRecords ->
|
service.getMsgsByMsgId(contact, arrayListOf(qqMsgId)) { code, _, msgRecords ->
|
||||||
if (code == 0 && msgRecords.isNotEmpty()) {
|
if (code == 0 && msgRecords.isNotEmpty()) {
|
||||||
continuation.resume(msgRecords.first())
|
continuation.resume(msgRecords.first())
|
||||||
@ -68,9 +69,6 @@ internal object MsgSvc: BaseSvc() {
|
|||||||
continuation.resume(null)
|
continuation.resume(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continuation.invokeOnCancellation {
|
|
||||||
continuation.resume(null)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,9 @@ interface MessageMappingDao {
|
|||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun insert(mapping: MessageMapping)
|
fun insert(mapping: MessageMapping)
|
||||||
|
|
||||||
|
@Query("UPDATE message_mapping SET msgSeq = :msgSeq WHERE msgHashId = :hash")
|
||||||
|
fun updateMsgSeqByMsgHash(hash: Int, msgSeq: Int)
|
||||||
|
|
||||||
@Query("DELETE FROM message_mapping WHERE msgHashId = :hash")
|
@Query("DELETE FROM message_mapping WHERE msgHashId = :hash")
|
||||||
fun deleteByMsgHash(hash: Int)
|
fun deleteByMsgHash(hash: Int)
|
||||||
|
|
||||||
|
@ -5,21 +5,18 @@ import moe.fuqiuluo.shamrock.helper.MessageHelper
|
|||||||
import com.tencent.qqnt.kernel.nativeinterface.*
|
import com.tencent.qqnt.kernel.nativeinterface.*
|
||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import moe.fuqiuluo.qqinterface.servlet.MsgSvc
|
|
||||||
import moe.fuqiuluo.qqinterface.servlet.msg.convert.toCQCode
|
import moe.fuqiuluo.qqinterface.servlet.msg.convert.toCQCode
|
||||||
import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc
|
import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc
|
||||||
import moe.fuqiuluo.shamrock.remote.service.config.ShamrockConfig
|
import moe.fuqiuluo.shamrock.remote.service.config.ShamrockConfig
|
||||||
import moe.fuqiuluo.shamrock.helper.Level
|
import moe.fuqiuluo.shamrock.helper.Level
|
||||||
import moe.fuqiuluo.shamrock.helper.LogCenter
|
import moe.fuqiuluo.shamrock.helper.LogCenter
|
||||||
|
import moe.fuqiuluo.shamrock.helper.db.MessageDB
|
||||||
import moe.fuqiuluo.shamrock.remote.service.api.GlobalEventTransmitter
|
import moe.fuqiuluo.shamrock.remote.service.api.GlobalEventTransmitter
|
||||||
import moe.fuqiuluo.shamrock.remote.service.data.push.MessageTempSource
|
import moe.fuqiuluo.shamrock.remote.service.data.push.MessageTempSource
|
||||||
import moe.fuqiuluo.shamrock.remote.service.data.push.PostType
|
import moe.fuqiuluo.shamrock.remote.service.data.push.PostType
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import java.util.HashMap
|
import java.util.HashMap
|
||||||
import kotlin.coroutines.resume
|
|
||||||
import kotlin.coroutines.suspendCoroutine
|
|
||||||
|
|
||||||
internal object AioListener: IKernelMsgListener {
|
internal object AioListener: IKernelMsgListener {
|
||||||
override fun onRecvMsg(msgList: ArrayList<MsgRecord>) {
|
override fun onRecvMsg(msgList: ArrayList<MsgRecord>) {
|
||||||
@ -101,29 +98,10 @@ internal object AioListener: IKernelMsgListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAddSendMsg(tmpRecord: MsgRecord) {
|
override fun onAddSendMsg(record: MsgRecord) {
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
try {
|
try {
|
||||||
val msgHash = MessageHelper.generateMsgIdHash(tmpRecord.chatType, tmpRecord.msgId)
|
val msgHash = MessageHelper.generateMsgIdHash(record.chatType, record.msgId)
|
||||||
|
|
||||||
val record = suspendCoroutine<MsgRecord?> {
|
|
||||||
GlobalScope.launch {
|
|
||||||
while (true) {
|
|
||||||
MsgSvc.getMsgByQMsgId(tmpRecord.chatType, tmpRecord.peerUin.toString(), tmpRecord.msgId).onSuccess { record ->
|
|
||||||
if (record.sendStatus == MsgConstant.KSENDSTATUSSUCCESS ||
|
|
||||||
record.sendStatus == MsgConstant.KSENDSTATUSSUCCESSNOSEQ
|
|
||||||
) {
|
|
||||||
it.resume(record)
|
|
||||||
} else if (record.sendStatus == MsgConstant.KSENDSTATUSFAILED) {
|
|
||||||
it.resume(null)
|
|
||||||
}
|
|
||||||
}.onFailure { _ ->
|
|
||||||
it.resume(null)
|
|
||||||
}
|
|
||||||
delay(50)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} ?: return@launch
|
|
||||||
|
|
||||||
MessageHelper.saveMsgMapping(
|
MessageHelper.saveMsgMapping(
|
||||||
hash = msgHash,
|
hash = msgHash,
|
||||||
@ -139,10 +117,25 @@ internal object AioListener: IKernelMsgListener {
|
|||||||
if (rawMsg.isEmpty()) return@launch
|
if (rawMsg.isEmpty()) return@launch
|
||||||
|
|
||||||
LogCenter.log("发送消息($msgHash | ${record.msgSeq} | ${record.msgId}): $rawMsg")
|
LogCenter.log("发送消息($msgHash | ${record.msgSeq} | ${record.msgId}): $rawMsg")
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
LogCenter.log(e.stackTraceToString(), Level.WARN)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMsgInfoListUpdate(msgList: ArrayList<MsgRecord>?) {
|
||||||
|
msgList?.forEach { record ->
|
||||||
|
GlobalScope.launch {
|
||||||
if (!ShamrockConfig.enableSelfMsg())
|
if (!ShamrockConfig.enableSelfMsg())
|
||||||
return@launch
|
return@launch
|
||||||
|
|
||||||
|
val msgHash = MessageHelper.generateMsgIdHash(record.chatType, record.msgId)
|
||||||
|
|
||||||
|
MessageDB.getInstance().messageMappingDao().updateMsgSeqByMsgHash(msgHash, record.msgSeq.toInt())
|
||||||
|
|
||||||
|
val rawMsg = record.elements.toCQCode(record.chatType, record.peerUin.toString())
|
||||||
|
if (rawMsg.isEmpty()) return@launch
|
||||||
|
|
||||||
when (record.chatType) {
|
when (record.chatType) {
|
||||||
MsgConstant.KCHATTYPEGROUP -> {
|
MsgConstant.KCHATTYPEGROUP -> {
|
||||||
GlobalEventTransmitter.MessageTransmitter
|
GlobalEventTransmitter.MessageTransmitter
|
||||||
@ -159,12 +152,16 @@ internal object AioListener: IKernelMsgListener {
|
|||||||
}
|
}
|
||||||
else -> LogCenter.log("不支持SELF PUSH事件: ${record.chatType}")
|
else -> LogCenter.log("不支持SELF PUSH事件: ${record.chatType}")
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
|
||||||
LogCenter.log(e.stackTraceToString(), Level.WARN)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onMsgAbstractUpdate(arrayList: ArrayList<MsgAbstract>?) {
|
||||||
|
//arrayList?.forEach {
|
||||||
|
// LogCenter.log("onMsgAbstractUpdate($it)", Level.WARN)
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onRecvMsgSvrRspTransInfo(
|
override fun onRecvMsgSvrRspTransInfo(
|
||||||
j2: Long,
|
j2: Long,
|
||||||
contact: Contact?,
|
contact: Contact?,
|
||||||
@ -363,11 +360,7 @@ internal object AioListener: IKernelMsgListener {
|
|||||||
//LogCenter.log("onLineDev($arrayList)")
|
//LogCenter.log("onLineDev($arrayList)")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLogLevelChanged(j2: Long) {
|
override fun onLogLevelChanged(newLevel: Long) {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onMsgAbstractUpdate(arrayList: ArrayList<MsgAbstract>?) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,16 +380,12 @@ internal object AioListener: IKernelMsgListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMsgInfoListUpdate(arrayList: ArrayList<MsgRecord>?) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onMsgQRCodeStatusChanged(i2: Int) {
|
override fun onMsgQRCodeStatusChanged(i2: Int) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMsgRecall(i2: Int, str: String?, j2: Long) {
|
override fun onMsgRecall(chatType: Int, peerId: String?, msgId: Long) {
|
||||||
LogCenter.log("onMsgRecall($i2, $str, $j2)")
|
LogCenter.log("onMsgRecall($chatType, $peerId, $msgId)")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMsgSecurityNotify(msgRecord: MsgRecord?) {
|
override fun onMsgSecurityNotify(msgRecord: MsgRecord?) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user