This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 白池 <whitechi73@outlook.com>
- Loading branch information
1 parent
3a07116
commit 6c9b282
Showing
25 changed files
with
2,966 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package qq.service.bdh | ||
|
||
import com.tencent.mobileqq.data.MessageRecord | ||
import java.io.File | ||
|
||
internal enum class ContactType { | ||
TROOP, | ||
PRIVATE, | ||
} | ||
|
||
internal interface TransTarget { | ||
val id: String | ||
val type: ContactType | ||
|
||
val mRec: MessageRecord? | ||
} | ||
|
||
internal class Troop( | ||
override val id: String, | ||
override val mRec: MessageRecord? = null | ||
): TransTarget { | ||
override val type: ContactType = ContactType.TROOP | ||
} | ||
|
||
internal class Private( | ||
override val id: String, | ||
override val mRec: MessageRecord? = null | ||
): TransTarget { | ||
override val type: ContactType = ContactType.PRIVATE | ||
} | ||
|
||
internal enum class ResourceType { | ||
Picture, | ||
Video, | ||
Voice | ||
} | ||
|
||
internal interface Resource { | ||
val type: ResourceType | ||
} | ||
|
||
internal data class PictureResource( | ||
val src: File | ||
): Resource { | ||
override val type = ResourceType.Picture | ||
} | ||
|
||
internal data class VideoResource( | ||
val src: File, val thumb: File | ||
): Resource { | ||
override val type = ResourceType.Video | ||
} | ||
|
||
internal data class VoiceResource( | ||
val src: File | ||
): Resource { | ||
override val type = ResourceType.Voice | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package qq.service.bdh | ||
|
||
import com.tencent.mobileqq.data.MessageForShortVideo | ||
import com.tencent.mobileqq.data.MessageRecord | ||
import com.tencent.mobileqq.transfile.FileMsg | ||
import com.tencent.mobileqq.transfile.TransferRequest | ||
import moe.fuqiuluo.shamrock.utils.MD5 | ||
import qq.service.bdh.ResourceType.* | ||
import java.io.File | ||
|
||
internal object Transfer: FileTransfer() { | ||
private val ROUTE = mapOf<ContactType, Map<ResourceType, suspend TransTarget.(Resource) -> Boolean>>( | ||
ContactType.TROOP to mapOf( | ||
Picture to { uploadGroupPic(id, (it as PictureResource).src, mRec) }, | ||
Voice to { uploadGroupVoice(id, (it as VoiceResource).src) }, | ||
Video to { uploadGroupVideo(id, (it as VideoResource).src, it.thumb) }, | ||
|
||
), | ||
ContactType.PRIVATE to mapOf( | ||
Picture to { uploadC2CPic(id, (it as PictureResource).src, mRec) }, | ||
Voice to { uploadC2CVoice(id, (it as VoiceResource).src) }, | ||
Video to { uploadC2CVideo(id, (it as VideoResource).src, it.thumb) }, | ||
) | ||
) | ||
|
||
suspend fun uploadC2CVideo( | ||
userId: String, | ||
file: File, | ||
thumb: File, | ||
wait: Boolean = true | ||
): Boolean { | ||
return transC2CResource(userId, file, FileMsg.TRANSFILE_TYPE_SHORT_VIDEO_C2C, BUSI_TYPE_SHORT_VIDEO, wait) { | ||
it.mSourceVideoCodecFormat = VIDEO_FORMAT_MP4 | ||
it.mRec = MessageForShortVideo().also { | ||
it.busiType = BUSI_TYPE_SHORT_VIDEO | ||
} | ||
it.mThumbPath = thumb.absolutePath | ||
it.mThumbMd5 = MD5.genFileMd5Hex(thumb.absolutePath) | ||
} | ||
} | ||
|
||
suspend fun uploadGroupVideo( | ||
groupId: String, | ||
file: File, | ||
thumb: File, | ||
wait: Boolean = true | ||
): Boolean { | ||
return transTroopResource(groupId, file, FileMsg.TRANSFILE_TYPE_SHORT_VIDEO_TROOP, BUSI_TYPE_SHORT_VIDEO, wait) { | ||
it.mSourceVideoCodecFormat = VIDEO_FORMAT_MP4 | ||
it.mRec = MessageForShortVideo().also { | ||
it.busiType = BUSI_TYPE_SHORT_VIDEO | ||
} | ||
it.mThumbPath = thumb.absolutePath | ||
it.mThumbMd5 = MD5.genFileMd5Hex(thumb.absolutePath) | ||
} | ||
} | ||
|
||
suspend fun uploadC2CVoice( | ||
userId: String, | ||
file: File, | ||
wait: Boolean = true | ||
): Boolean { | ||
return transC2CResource(userId, file, FileMsg.TRANSFILE_TYPE_PTT, 1002, wait) { | ||
it.mPttUploadPanel = 3 | ||
it.mPttCompressFinish = true | ||
it.mIsPttPreSend = true | ||
} | ||
} | ||
|
||
suspend fun uploadGroupVoice( | ||
groupId: String, | ||
file: File, | ||
wait: Boolean = true | ||
): Boolean { | ||
return transTroopResource(groupId, file, FileMsg.TRANSFILE_TYPE_PTT, 1002, wait) { | ||
it.mPttUploadPanel = 3 | ||
it.mPttCompressFinish = true | ||
it.mIsPttPreSend = true | ||
} | ||
} | ||
|
||
suspend fun uploadC2CPic( | ||
peerId: String, | ||
file: File, | ||
record: MessageRecord? = null, | ||
wait: Boolean = true | ||
): Boolean { | ||
return transC2CResource(peerId, file, FileMsg.TRANSFILE_TYPE_PIC, SEND_MSG_BUSINESS_TYPE_PIC_CAMERA, wait) { | ||
val picUpExtraInfo = TransferRequest.PicUpExtraInfo() | ||
picUpExtraInfo.mIsRaw = false | ||
picUpExtraInfo.mUinType = FileMsg.UIN_BUDDY | ||
it.mPicSendSource = 8 | ||
it.mExtraObj = picUpExtraInfo | ||
it.mIsPresend = true | ||
it.delayShowProgressTimeInMs = 2000 | ||
it.mRec = record | ||
} | ||
} | ||
|
||
suspend fun uploadGroupPic( | ||
groupId: String, | ||
file: File, | ||
record: MessageRecord? = null, | ||
wait: Boolean = true | ||
): Boolean { | ||
return transTroopResource(groupId, file, FileMsg.TRANSFILE_TYPE_PIC, SEND_MSG_BUSINESS_TYPE_PIC_CAMERA, wait) { | ||
val picUpExtraInfo = TransferRequest.PicUpExtraInfo() | ||
picUpExtraInfo.mIsRaw = false | ||
picUpExtraInfo.mUinType = FileMsg.UIN_TROOP | ||
it.mPicSendSource = 8 | ||
it.delayShowProgressTimeInMs = 2000 | ||
it.mExtraObj = picUpExtraInfo | ||
it.mRec = record | ||
} | ||
} | ||
|
||
operator fun get(contactType: ContactType, resourceType: ResourceType): suspend TransTarget.(Resource) -> Boolean { | ||
return (ROUTE[contactType] ?: error("unsupported contact type: $contactType"))[resourceType] | ||
?: error("Unsupported resource type: $resourceType") | ||
} | ||
} | ||
|
||
internal suspend infix fun TransferTaskBuilder.trans(res: Resource): Boolean { | ||
return Transfer[contact.type, res.type](contact, res) | ||
} | ||
|
||
internal class TransferTaskBuilder { | ||
lateinit var contact: TransTarget | ||
} | ||
|
||
internal infix fun Transfer.with(contact: TransTarget): TransferTaskBuilder { | ||
return TransferTaskBuilder().also { | ||
it.contact = contact | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package qq.service.contact | ||
|
||
import com.tencent.qqnt.kernel.nativeinterface.Contact | ||
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant | ||
import io.kritor.message.Scene | ||
|
||
suspend fun Contact.longPeer(): Long { | ||
return when(this.chatType) { | ||
MsgConstant.KCHATTYPEGROUP -> peerUid.toLong() | ||
MsgConstant.KCHATTYPETEMPC2CFROMGROUP, MsgConstant.KCHATTYPEC2C -> if (peerUid.startsWith("u_")) ContactHelper.getUinByUidAsync(peerUid).toLong() else peerUid.toLong() | ||
else -> 0L | ||
} | ||
} | ||
|
||
suspend fun io.kritor.message.Contact.longPeer(): Long { | ||
return when(this.scene) { | ||
Scene.GROUP -> peer.toLong() | ||
Scene.FRIEND, Scene.STRANGER, Scene.STRANGER_FROM_GROUP -> if (peer.startsWith("u_")) ContactHelper.getUinByUidAsync(peer).toLong() else peer.toLong() | ||
else -> 0L | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.