Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add ShortVideo message support #2739

Merged
merged 44 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5a949d1
initial support for ShortVideo message
Jul 17, 2023
3c75356
dump api
Jul 17, 2023
4c94b45
[core] upload protocol
Aug 1, 2023
4ee4751
[core] short video upload event
Aug 2, 2023
1e0f190
[core] doc
Aug 2, 2023
85f43a1
[core] protocol
Aug 2, 2023
1a19b23
[core] fix mp4 file check
Aug 2, 2023
53c2946
[core] extract fileName from `OnlineShortVideo` to `ShortVideo`
Aug 2, 2023
f21eb65
[core] ShortVideo.Builder
Aug 2, 2023
a26e1f1
[core] mirai code support for `ShortVideo`
Aug 2, 2023
3629e7f
[core] add doc for OnlineShortVideo and OfflineShortVideo
Aug 2, 2023
3385855
[core] fix text
Aug 2, 2023
c8a6b36
dump api
Aug 2, 2023
c38f5ad
update `Contact.uploadShortVideo`·` doc
Aug 3, 2023
263dd98
[core] remove mirai code support for ShortVideo
Aug 3, 2023
47bfc67
[core] ensure Mirai service is loaded before load other services
Aug 3, 2023
0ae2553
[core] introduce `CombinedExternalResource` to reference multiple ext…
Aug 4, 2023
553243a
[core] move refine context key defined in `OnlineShortVideoMsgInterna…
Aug 4, 2023
6a5b9f3
[core] remove data class
Aug 4, 2023
6fe4b63
[core] broadcast `ShortVideoUploadEvent.Failed` event
Aug 4, 2023
d203935
[core] warn when cannot determine fromId
Aug 4, 2023
2fea0c8
[core] add `contentToString` and `toString` for `OnlineShortVideoMsgI…
Aug 4, 2023
c004f6e
[core] optimize imports
Aug 4, 2023
de059c1
[core] import
Aug 4, 2023
428e2e5
[core] revert
Aug 4, 2023
461f612
[core] doc
Aug 4, 2023
342b459
[core] auto close resource
Aug 4, 2023
b50124f
dump api
Aug 6, 2023
75abe69
keep consistence of param name
Aug 12, 2023
0e35672
update doc
Aug 12, 2023
884bc85
move Builder to OfflineShortVideo
Aug 12, 2023
413e97e
optimize RefineContext
Aug 12, 2023
e6bafd3
RefineContext.merge
Aug 12, 2023
fafb134
dump api
Aug 12, 2023
a560b41
fix test
Aug 12, 2023
76391f3
show more video info
Aug 13, 2023
138a679
optimize constructor and builder of offline short video
Aug 13, 2023
12a40ef
optimize thumbnail
Aug 16, 2023
2f93f36
Merge branch 'dev' into short-video-message
Aug 16, 2023
f3c4222
move thumbnail to main constructor arg
Aug 16, 2023
29e799a
dump api
Aug 16, 2023
858e2fe
avoid null cast exception.
Aug 20, 2023
929f550
combine format transition
Aug 20, 2023
b9efcfe
cleanup
Aug 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions mirai-core/src/commonMain/kotlin/message/data/shortVideo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ internal class OnlineShortVideoMsgInternal(
}
}

@Serializable
internal class ShortVideoThumbnail(
val md5: ByteArray,
val size: Long,
val width: Int?,
val height: Int?,
)

internal abstract class AbstractShortVideoWithThumbnail : ShortVideo {
abstract val thumbMd5: ByteArray
abstract val thumbSize: Long
abstract val thumbWidth: Int?
abstract val thumbHeight: Int?
abstract val thumbnail: ShortVideoThumbnail
}

@Suppress("DuplicatedCode")
Expand All @@ -118,11 +123,14 @@ internal class OnlineShortVideoImpl(
override val fileSize: Long,
override val fileFormat: String,
override val urlForDownload: String,
override val thumbMd5: ByteArray,
override val thumbSize: Long,
@Transient override val thumbWidth: Int = 0,
@Transient override val thumbHeight: Int = 0
val thumbMd5: ByteArray,
val thumbSize: Long,
@Transient val thumbWidth: Int = 0,
@Transient val thumbHeight: Int = 0
) : OnlineShortVideo, AbstractShortVideoWithThumbnail() {
override val thumbnail: ShortVideoThumbnail by lazy {
ShortVideoThumbnail(thumbMd5, thumbSize, thumbWidth, thumbHeight)
}

override fun toString(): String {
return "[mirai:shortvideo:$videoId, videoName=$filename.$fileFormat, videoMd5=${fileMd5.toUHexString("")}, " +
Expand Down Expand Up @@ -175,11 +183,14 @@ internal class OfflineShortVideoImpl(
override val fileMd5: ByteArray,
override val fileSize: Long,
override val fileFormat: String,
override val thumbMd5: ByteArray,
override val thumbSize: Long,
@Transient override val thumbWidth: Int = 0,
@Transient override val thumbHeight: Int = 0
val thumbMd5: ByteArray,
val thumbSize: Long,
@Transient val thumbWidth: Int = 0,
@Transient val thumbHeight: Int = 0
StageGuard marked this conversation as resolved.
Show resolved Hide resolved
) : OfflineShortVideo, AbstractShortVideoWithThumbnail() {
override val thumbnail: ShortVideoThumbnail by lazy {
ShortVideoThumbnail(thumbMd5, thumbSize, thumbWidth, thumbHeight)
}

/**
* offline short video uses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ internal class ShortVideoProtocol : MessageProtocol() {

collect(ImMsgBody.Elem(text = ImMsgBody.Text("你的 QQ 暂不支持查看视频短片,请期待后续版本。")))

val thumbWidth = if (data.thumbWidth == null || data.thumbWidth == 0) 1280 else data.thumbWidth!!
val thumbHeight = if (data.thumbHeight == null || data.thumbHeight == 0) 720 else data.thumbHeight!!
val thumbWidth = if (data.thumbnail.width == null || data.thumbnail.width == 0) 1280 else data.thumbnail.width!!
val thumbHeight = if (data.thumbnail.height == null || data.thumbnail.height == 0) 720 else data.thumbnail.height!!

collect(
ImMsgBody.Elem(
Expand All @@ -65,8 +65,8 @@ internal class ShortVideoProtocol : MessageProtocol() {
fileSize = data.fileSize.toInt(),
thumbWidth = thumbWidth,
thumbHeight = thumbHeight,
thumbFileMd5 = data.thumbMd5,
thumbFileSize = data.thumbSize.toInt(),
thumbFileMd5 = data.thumbnail.md5,
thumbFileSize = data.thumbnail.size.toInt(),
busiType = 0,
fromChatType = -1,
toChatType = -1,
Expand Down