2 Commits

Author SHA1 Message Date
e92b04ad0f Shamrock: fix build error #201 2024-01-18 09:58:16 +08:00
160d1a11ac Shamrock: #201 2024-01-18 09:49:56 +08:00
5 changed files with 58 additions and 29 deletions

View File

@ -31,10 +31,6 @@ import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
internal object MsgSvc: BaseSvc() {
fun uploadForwardMsg(): Result<String> {
return Result.failure(Exception("Not implemented"))
}
suspend fun prepareTempChatFromGroup(
groupId: String,
peerId: String

View File

@ -9,16 +9,17 @@ internal object SendGroupMessage: IActionHandler() {
override suspend fun internalHandle(session: ActionSession): String {
val groupId = session.getString("group_id")
val retryCnt = session.getIntOrNull("retry_cnt")
val recallDuration = session.getLongOrNull("recall_duration")
return if (session.isString("message")) {
val autoEscape = session.getBooleanOrDefault("auto_escape", false)
val message = session.getString("message")
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, message, autoEscape, echo = session.echo, retryCnt = retryCnt ?: 3)
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, message, autoEscape, echo = session.echo, retryCnt = retryCnt ?: 3, recallDuration = recallDuration)
} else if (session.isObject("message")) {
val message = session.getObject("message")
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, listOf( message ).jsonArray, session.echo, retryCnt = retryCnt ?: 3)
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, listOf( message ).jsonArray, session.echo, retryCnt = retryCnt ?: 3, recallDuration = recallDuration)
} else {
val message = session.getArray("message")
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, message, session.echo, retryCnt = retryCnt ?: 3)
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, message, session.echo, retryCnt = retryCnt ?: 3, recallDuration = recallDuration)
}
}

View File

@ -1,6 +1,10 @@
package moe.fuqiuluo.shamrock.remote.action.handlers
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import moe.fuqiuluo.shamrock.remote.action.ActionSession
import moe.fuqiuluo.shamrock.remote.action.IActionHandler
import moe.fuqiuluo.shamrock.helper.MessageHelper
@ -46,16 +50,17 @@ internal object SendMessage: IActionHandler() {
else -> error("unknown chat type: $chatType")
}
val retryCnt = session.getIntOrNull("retry_cnt")
val recallDuration = session.getLongOrNull("recall_duration")
return if (session.isString("message")) {
val autoEscape = session.getBooleanOrDefault("auto_escape", false)
val message = session.getString("message")
invoke(chatType, peerId, message, autoEscape, echo = session.echo, fromId = fromId, retryCnt = retryCnt ?: 3)
invoke(chatType, peerId, message, autoEscape, echo = session.echo, fromId = fromId, retryCnt = retryCnt ?: 3, recallDuration = recallDuration)
} else if (session.isArray("message")) {
val message = session.getArray("message")
invoke(chatType, peerId, message, session.echo, fromId = fromId, retryCnt ?: 3)
invoke(chatType, peerId, message, session.echo, fromId = fromId, retryCnt ?: 3, recallDuration = recallDuration)
} else {
val message = session.getObject("message")
invoke(chatType, peerId, listOf( message ).jsonArray, session.echo, fromId = fromId, retryCnt ?: 3)
invoke(chatType, peerId, listOf( message ).jsonArray, session.echo, fromId = fromId, retryCnt ?: 3, recallDuration = recallDuration)
}
} catch (e: ParamsException) {
return noParam(e.message!!, session.echo)
@ -72,6 +77,7 @@ internal object SendMessage: IActionHandler() {
autoEscape: Boolean,
fromId: String = peerId,
retryCnt: Int,
recallDuration: Long?,
echo: JsonElement = EmptyJsonString
): String {
//if (!ContactHelper.checkContactAvailable(chatType, peerId)) {
@ -102,6 +108,7 @@ internal object SendMessage: IActionHandler() {
if (pair.first <= 0) {
return logic("send message failed", echo = echo)
}
recallDuration?.let { autoRecall(pair.second, it) }
return ok(MessageResult(
msgId = pair.second,
time = (pair.first * 0.001).toLong()
@ -110,7 +117,7 @@ internal object SendMessage: IActionHandler() {
// 消息段格式消息
suspend operator fun invoke(
chatType: Int, peerId: String, message: JsonArray, echo: JsonElement = EmptyJsonString, fromId: String = peerId, retryCnt: Int
chatType: Int, peerId: String, message: JsonArray, echo: JsonElement = EmptyJsonString, fromId: String = peerId, retryCnt: Int, recallDuration: Long?,
): String {
//if (!ContactHelper.checkContactAvailable(chatType, peerId)) {
// return logic("contact is not found", echo = echo)
@ -123,12 +130,20 @@ internal object SendMessage: IActionHandler() {
if (pair.first <= 0) {
return logic("send message failed", echo = echo)
}
recallDuration?.let { autoRecall(pair.second, it) }
return ok(MessageResult(
msgId = pair.second,
time = (pair.first * 0.001).toLong()
), echo)
}
private fun autoRecall(msgHash: Int, duration: Long) {
GlobalScope.launch(Dispatchers.Default) {
delay(duration)
MsgSvc.recallMsg(msgHash)
}
}
override val requiredParams: Array<String> = arrayOf("message")
override fun path(): String = "send_message"

View File

@ -11,6 +11,7 @@ internal object SendPrivateMessage: IActionHandler() {
val groupId = session.getStringOrNull("group_id")
val chatType = if (groupId == null) MsgConstant.KCHATTYPEC2C else MsgConstant.KCHATTYPETEMPC2CFROMGROUP
val retryCnt = session.getIntOrNull("retry_cnt")
val recallDuration = session.getLongOrNull("recall_duration")
return if (session.isString("message")) {
val autoEscape = session.getBooleanOrDefault("auto_escape", false)
val message = session.getString("message")
@ -21,7 +22,8 @@ internal object SendPrivateMessage: IActionHandler() {
autoEscape = autoEscape,
echo = session.echo,
fromId = groupId ?: userId,
retryCnt = retryCnt ?: 3
retryCnt = retryCnt ?: 3,
recallDuration = recallDuration
)
} else if (session.isArray("message")) {
val message = session.getArray("message")
@ -31,7 +33,8 @@ internal object SendPrivateMessage: IActionHandler() {
message = message,
echo = session.echo,
fromId = groupId ?: userId,
retryCnt = retryCnt ?: 3
retryCnt = retryCnt ?: 3,
recallDuration = recallDuration
)
} else {
val message = session.getObject("message")
@ -41,7 +44,8 @@ internal object SendPrivateMessage: IActionHandler() {
message = listOf( message ).jsonArray,
echo = session.echo,
fromId = groupId ?: userId,
retryCnt = retryCnt ?: 3
retryCnt = retryCnt ?: 3,
recallDuration = recallDuration
)
}
}

View File

@ -120,13 +120,16 @@ fun Routing.messageAction() {
val userId = fetchGetOrNull("user_id")
val groupId = fetchGetOrNull("group_id")
val recallDuration = fetchGetOrNull("recall_duration")?.toLongOrNull()
call.respondText(SendMessage(
chatType = chatType,
peerId = if (chatType == MsgConstant.KCHATTYPEC2C) userId!! else groupId!!,
message = message,
autoEscape = autoEscape,
fromId = groupId ?: userId ?: "",
retryCnt = retryCnt
retryCnt = retryCnt,
recallDuration = recallDuration
), ContentType.Application.Json)
}
post {
@ -137,6 +140,7 @@ fun Routing.messageAction() {
val userId = fetchPostOrNull("user_id")
val groupId = fetchPostOrNull("group_id")
val peerId = if (chatType == MsgConstant.KCHATTYPEC2C) userId!! else groupId!!
val recallDuration = fetchPostOrNull("recall_duration")?.toLongOrNull()
call.respondText(if (isJsonData() && !isJsonString("message")) {
if (isJsonObject("message")) {
@ -145,7 +149,8 @@ fun Routing.messageAction() {
peerId = peerId,
message = listOf(fetchPostJsonObject("message")).jsonArray,
fromId = groupId ?: userId ?: "",
retryCnt = retryCnt
retryCnt = retryCnt,
recallDuration = recallDuration
)
} else {
SendMessage(
@ -153,7 +158,8 @@ fun Routing.messageAction() {
peerId = peerId,
message = fetchPostJsonArray("message"),
fromId = groupId ?: userId ?: "",
retryCnt = retryCnt
retryCnt = retryCnt,
recallDuration = recallDuration
)
}
} else {
@ -165,7 +171,8 @@ fun Routing.messageAction() {
message = fetchPostOrThrow("message"),
autoEscape = autoEscape,
fromId = groupId ?: userId ?: "",
retryCnt = retryCnt
retryCnt = retryCnt,
recallDuration = recallDuration
)
}, ContentType.Application.Json)
}
@ -177,36 +184,41 @@ fun Routing.messageAction() {
val message = fetchGetOrThrow("message")
val retryCnt = fetchGetOrNull("retry_cnt")?.toInt() ?: 3
val autoEscape = fetchGetOrNull("auto_escape")?.toBooleanStrict() ?: false
call.respondText(SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, message, autoEscape, retryCnt = retryCnt))
val recallDuration = fetchGetOrNull("recall_duration")?.toLongOrNull()
call.respondText(SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, message, autoEscape, retryCnt = retryCnt, recallDuration = recallDuration), ContentType.Application.Json)
}
post {
val groupId = fetchPostOrThrow("group_id")
val retryCnt = fetchPostOrNull("retry_cnt")?.toInt() ?: 3
val autoEscape = fetchPostOrNull("auto_escape")?.toBooleanStrict() ?: false
val recallDuration = fetchPostOrNull("recall_duration")?.toLongOrNull()
val result = if (isJsonData()) {
if (isJsonString("message")) {
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, fetchPostJsonString("message"), autoEscape, retryCnt = retryCnt)
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, fetchPostJsonString("message"), autoEscape, retryCnt = retryCnt, recallDuration = recallDuration)
} else {
if (isJsonObject("message")) {
SendMessage(
chatType = MsgConstant.KCHATTYPEGROUP,
peerId = groupId,
message = listOf(fetchPostJsonObject("message")).jsonArray,
retryCnt = retryCnt
retryCnt = retryCnt,
recallDuration = recallDuration
)
} else {
SendMessage(
chatType = MsgConstant.KCHATTYPEGROUP,
peerId = groupId,
message = fetchPostJsonArray("message"),
retryCnt = retryCnt
retryCnt = retryCnt,
recallDuration = recallDuration
)
}
}
} else {
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, fetchPostOrThrow("message"), autoEscape, retryCnt = retryCnt)
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, fetchPostOrThrow("message"), autoEscape, retryCnt = retryCnt, recallDuration = recallDuration)
}
call.respondText(result, ContentType.Application.Json)
@ -220,13 +232,14 @@ fun Routing.messageAction() {
val message = fetchGetOrThrow("message")
val retryCnt = fetchGetOrNull("retry_cnt")?.toInt() ?: 3
val autoEscape = fetchGetOrNull("auto_escape")?.toBooleanStrict() ?: false
val recallDuration = fetchGetOrNull("recall_duration")?.toLongOrNull()
call.respondText(SendMessage(
chatType = if (groupId == null) MsgConstant.KCHATTYPEC2C else MsgConstant.KCHATTYPETEMPC2CFROMGROUP,
peerId = userId,
message = message,
autoEscape = autoEscape,
fromId = groupId ?: userId,
retryCnt = retryCnt
retryCnt = retryCnt, recallDuration = recallDuration
), ContentType.Application.Json)
}
post {
@ -237,7 +250,7 @@ fun Routing.messageAction() {
val chatType = if (groupId == null) MsgConstant.KCHATTYPEC2C else MsgConstant.KCHATTYPETEMPC2CFROMGROUP
val fromId = groupId ?: userId
val recallDuration = fetchPostOrNull("recall_duration")?.toLongOrNull()
val result = if (isJsonData()) {
if (isJsonString("message")) {
@ -247,7 +260,7 @@ fun Routing.messageAction() {
message = fetchPostJsonString("message"),
autoEscape = autoEscape,
fromId = fromId,
retryCnt = retryCnt
retryCnt = retryCnt, recallDuration = recallDuration
)
} else {
if (isJsonObject("message")) {
@ -256,7 +269,7 @@ fun Routing.messageAction() {
peerId = userId,
message = listOf(fetchPostJsonObject("message")).jsonArray,
fromId = fromId,
retryCnt = retryCnt
retryCnt = retryCnt, recallDuration = recallDuration
)
} else {
SendMessage(
@ -264,7 +277,7 @@ fun Routing.messageAction() {
peerId = userId,
message = fetchPostJsonArray("message"),
fromId = fromId,
retryCnt = retryCnt
retryCnt = retryCnt, recallDuration = recallDuration
)
}
}
@ -275,7 +288,7 @@ fun Routing.messageAction() {
message = fetchPostOrThrow("message"),
autoEscape = autoEscape,
fromId = fromId,
retryCnt = retryCnt
retryCnt = retryCnt, recallDuration = recallDuration
)
}