mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 02:20:14 +08:00
Unified MessageSource.toJceData
This commit is contained in:
parent
e279e79b63
commit
d97aa7bd94
@ -39,6 +39,8 @@ internal interface MessageSourceImpl {
|
|||||||
val sequenceId: Int
|
val sequenceId: Int
|
||||||
|
|
||||||
var isRecalledOrPlanned: Boolean // // TODO: 2020/4/7 实现 isRecalledOrPlanned
|
var isRecalledOrPlanned: Boolean // // TODO: 2020/4/7 实现 isRecalledOrPlanned
|
||||||
|
|
||||||
|
fun toJceData(): ImMsgBody.SourceMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
internal suspend inline fun MessageSource.ensureSequenceIdAvailable() {
|
internal suspend inline fun MessageSource.ensureSequenceIdAvailable() {
|
||||||
@ -76,7 +78,7 @@ internal class MessageSourceFromFriendImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun toJceDataImplForFriend(): ImMsgBody.SourceMsg {
|
override fun toJceData(): ImMsgBody.SourceMsg {
|
||||||
return ImMsgBody.SourceMsg(
|
return ImMsgBody.SourceMsg(
|
||||||
origSeqs = listOf(msg.msgHead.msgSeq),
|
origSeqs = listOf(msg.msgHead.msgSeq),
|
||||||
senderUin = msg.msgHead.fromUin,
|
senderUin = msg.msgHead.fromUin,
|
||||||
@ -131,9 +133,10 @@ internal class MessageSourceFromTempImpl(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
override val target: Bot get() = bot
|
override val target: Bot get() = bot
|
||||||
override val sender: Member get() = with(msg.msgHead) {
|
override val sender: Member
|
||||||
bot.getGroup(c2cTmpMsgHead!!.groupUin)[fromUin]
|
get() = with(msg.msgHead) {
|
||||||
}
|
bot.getGroup(c2cTmpMsgHead!!.groupUin)[fromUin]
|
||||||
|
}
|
||||||
|
|
||||||
private val elems by lazy {
|
private val elems by lazy {
|
||||||
msg.msgBody.richText.elems.toMutableList().also {
|
msg.msgBody.richText.elems.toMutableList().also {
|
||||||
@ -141,7 +144,7 @@ internal class MessageSourceFromTempImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun toJceDataImplForTemp(): ImMsgBody.SourceMsg {
|
override fun toJceData(): ImMsgBody.SourceMsg {
|
||||||
return ImMsgBody.SourceMsg(
|
return ImMsgBody.SourceMsg(
|
||||||
origSeqs = listOf(msg.msgHead.msgSeq),
|
origSeqs = listOf(msg.msgHead.msgSeq),
|
||||||
senderUin = msg.msgHead.fromUin,
|
senderUin = msg.msgHead.fromUin,
|
||||||
@ -204,7 +207,7 @@ internal class MessageSourceFromGroupImpl(
|
|||||||
?: error("cannot find member for MessageSourceFromGroupImpl. msg=${msg._miraiContentToString()}")
|
?: error("cannot find member for MessageSourceFromGroupImpl. msg=${msg._miraiContentToString()}")
|
||||||
|
|
||||||
|
|
||||||
fun toJceDataImplForGroup(): ImMsgBody.SourceMsg {
|
override fun toJceData(): ImMsgBody.SourceMsg {
|
||||||
return ImMsgBody.SourceMsg(
|
return ImMsgBody.SourceMsg(
|
||||||
origSeqs = listOf(msg.msgHead.msgSeq),
|
origSeqs = listOf(msg.msgHead.msgSeq),
|
||||||
senderUin = msg.msgHead.fromUin,
|
senderUin = msg.msgHead.fromUin,
|
||||||
@ -219,7 +222,8 @@ internal class MessageSourceFromGroupImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class OfflineMessageSourceImplByMsg( // from other sources' originalMessage
|
internal class OfflineMessageSourceImplByMsg(
|
||||||
|
// from other sources' originalMessage
|
||||||
val delegate: MsgComm.Msg,
|
val delegate: MsgComm.Msg,
|
||||||
override val bot: Bot
|
override val bot: Bot
|
||||||
) : OfflineMessageSource(), MessageSourceImpl {
|
) : OfflineMessageSource(), MessageSourceImpl {
|
||||||
@ -248,9 +252,24 @@ internal class OfflineMessageSourceImplByMsg( // from other sources' originalMes
|
|||||||
set(value) {
|
set(value) {
|
||||||
isRecalled.value = value
|
isRecalled.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toJceData(): ImMsgBody.SourceMsg {
|
||||||
|
return ImMsgBody.SourceMsg(
|
||||||
|
origSeqs = listOf(delegate.msgHead.msgSeq),
|
||||||
|
senderUin = delegate.msgHead.fromUin,
|
||||||
|
toUin = 0,
|
||||||
|
flag = 1,
|
||||||
|
elems = delegate.msgBody.richText.elems,
|
||||||
|
type = 0,
|
||||||
|
time = delegate.msgHead.msgTime,
|
||||||
|
pbReserve = EMPTY_BYTE_ARRAY,
|
||||||
|
srcMsg = EMPTY_BYTE_ARRAY
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class OfflineMessageSourceImplBySourceMsg( // from others' quotation
|
internal class OfflineMessageSourceImplBySourceMsg(
|
||||||
|
// from others' quotation
|
||||||
val delegate: ImMsgBody.SourceMsg,
|
val delegate: ImMsgBody.SourceMsg,
|
||||||
override val bot: Bot,
|
override val bot: Bot,
|
||||||
groupIdOrZero: Long
|
groupIdOrZero: Long
|
||||||
@ -295,6 +314,10 @@ internal class OfflineMessageSourceImplBySourceMsg( // from others' quotation
|
|||||||
)*/
|
)*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toJceData(): ImMsgBody.SourceMsg {
|
||||||
|
return delegate
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class MessageSourceToFriendImpl(
|
internal class MessageSourceToFriendImpl(
|
||||||
@ -317,7 +340,7 @@ internal class MessageSourceToFriendImpl(
|
|||||||
originalMessage.toRichTextElems(forGroup = false, withGeneralFlags = true)
|
originalMessage.toRichTextElems(forGroup = false, withGeneralFlags = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toJceDataImplForFriend(): ImMsgBody.SourceMsg {
|
override fun toJceData(): ImMsgBody.SourceMsg {
|
||||||
val messageUid: Long = sequenceId.toLong().shl(32) or id.toLong().and(0xffFFffFF)
|
val messageUid: Long = sequenceId.toLong().shl(32) or id.toLong().and(0xffFFffFF)
|
||||||
return ImMsgBody.SourceMsg(
|
return ImMsgBody.SourceMsg(
|
||||||
origSeqs = listOf(sequenceId),
|
origSeqs = listOf(sequenceId),
|
||||||
@ -374,7 +397,7 @@ internal class MessageSourceToTempImpl(
|
|||||||
originalMessage.toRichTextElems(forGroup = false, withGeneralFlags = true)
|
originalMessage.toRichTextElems(forGroup = false, withGeneralFlags = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toJceDataImplForTemp(): ImMsgBody.SourceMsg {
|
override fun toJceData(): ImMsgBody.SourceMsg {
|
||||||
val messageUid: Long = sequenceId.toLong().shl(32) or id.toLong().and(0xffFFffFF)
|
val messageUid: Long = sequenceId.toLong().shl(32) or id.toLong().and(0xffFFffFF)
|
||||||
return ImMsgBody.SourceMsg(
|
return ImMsgBody.SourceMsg(
|
||||||
origSeqs = listOf(sequenceId),
|
origSeqs = listOf(sequenceId),
|
||||||
@ -449,7 +472,7 @@ internal class MessageSourceToGroupImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun toJceDataImplForGroup(): ImMsgBody.SourceMsg {
|
override fun toJceData(): ImMsgBody.SourceMsg {
|
||||||
return ImMsgBody.SourceMsg(
|
return ImMsgBody.SourceMsg(
|
||||||
origSeqs = listOf(sequenceId),
|
origSeqs = listOf(sequenceId),
|
||||||
senderUin = fromId,
|
senderUin = fromId,
|
||||||
|
@ -40,14 +40,8 @@ internal fun MessageChain.toRichTextElems(forGroup: Boolean, withGeneralFlags: B
|
|||||||
|
|
||||||
if (this.anyIsInstance<QuoteReply>()) {
|
if (this.anyIsInstance<QuoteReply>()) {
|
||||||
when (val source = this[QuoteReply].source) {
|
when (val source = this[QuoteReply].source) {
|
||||||
is OfflineMessageSourceImplBySourceMsg -> elements.add(ImMsgBody.Elem(srcMsg = source.delegate))
|
is MessageSourceImpl -> elements.add(ImMsgBody.Elem(srcMsg = source.toJceData()))
|
||||||
is MessageSourceToFriendImpl -> elements.add(ImMsgBody.Elem(srcMsg = source.toJceDataImplForFriend()))
|
else -> error("unsupported MessageSource implementation: ${source::class.simpleName}. Don't implement your own MessageSource.")
|
||||||
is MessageSourceToGroupImpl -> elements.add(ImMsgBody.Elem(srcMsg = source.toJceDataImplForGroup()))
|
|
||||||
is MessageSourceToTempImpl -> elements.add(ImMsgBody.Elem(srcMsg = source.toJceDataImplForTemp()))
|
|
||||||
is MessageSourceFromFriendImpl -> elements.add(ImMsgBody.Elem(srcMsg = source.toJceDataImplForFriend()))
|
|
||||||
is MessageSourceFromGroupImpl -> elements.add(ImMsgBody.Elem(srcMsg = source.toJceDataImplForGroup()))
|
|
||||||
is MessageSourceFromTempImpl -> elements.add(ImMsgBody.Elem(srcMsg = source.toJceDataImplForTemp()))
|
|
||||||
else -> error("unsupported MessageSource implementation: ${source::class.simpleName}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user