Make AnnouncementParameters better for Java

This commit is contained in:
Him188 2021-07-05 15:43:16 +08:00
parent 5c89645056
commit d10cd270e8
3 changed files with 49 additions and 37 deletions

View File

@ -31,11 +31,11 @@ public class AnnouncementParameters internal constructor(
/** 发送给新成员 */
public val sendToNewMember: Boolean = false,
/** 置顶. 可以有多个置顶公告 */
public val isPinned: Boolean = false,
public val pinned: Boolean = false,
/** 显示能够引导群成员修改昵称的窗口 */
public val isShowEditCard: Boolean = false,
public val showEditCard: Boolean = false,
/** 使用弹窗 */
public val isTip: Boolean = false,
public val popup: Boolean = false,
/** 需要群成员确认 */
public val needConfirm: Boolean = false,
) {
@ -44,12 +44,12 @@ public class AnnouncementParameters internal constructor(
*/
public fun builder(): AnnouncementParametersBuilder = AnnouncementParametersBuilder().apply {
val outer = this@AnnouncementParameters
this.image = outer.image
this.sendToNewMember = outer.sendToNewMember
this.isPinned = outer.isPinned
this.isShowEditCard = outer.isShowEditCard
this.isTip = outer.isTip
this.needConfirm = outer.needConfirm
image(outer.image)
sendToNewMember(outer.sendToNewMember)
pinned(outer.pinned)
showEditCard(outer.showEditCard)
popup(outer.popup)
needConfirm(outer.needConfirm)
}
public companion object {
@ -71,9 +71,9 @@ public class AnnouncementParameters internal constructor(
if (image != other.image) return false
if (sendToNewMember != other.sendToNewMember) return false
if (isPinned != other.isPinned) return false
if (isShowEditCard != other.isShowEditCard) return false
if (isTip != other.isTip) return false
if (pinned != other.pinned) return false
if (showEditCard != other.showEditCard) return false
if (popup != other.popup) return false
if (needConfirm != other.needConfirm) return false
return true
@ -82,14 +82,14 @@ public class AnnouncementParameters internal constructor(
override fun hashCode(): Int {
var result = image?.hashCode() ?: 0
result = 31 * result + sendToNewMember.hashCode()
result = 31 * result + isPinned.hashCode()
result = 31 * result + isShowEditCard.hashCode()
result = 31 * result + isTip.hashCode()
result = 31 * result + pinned.hashCode()
result = 31 * result + showEditCard.hashCode()
result = 31 * result + popup.hashCode()
result = 31 * result + needConfirm.hashCode()
return result
}
override fun toString(): String {
return "AnnouncementParameters(image=$image, sendToNewMember=$sendToNewMember, isPinned=$isPinned, isShowEditCard=$isShowEditCard, isTip=$isTip, needConfirm=$needConfirm)"
return "AnnouncementParameters(image=$image, sendToNewMember=$sendToNewMember, pinned=$pinned, showEditCard=$showEditCard, popup=$popup, needConfirm=$needConfirm)"
}
}

View File

@ -53,36 +53,48 @@ public class AnnouncementParametersBuilder @JvmOverloads constructor(
* @see AnnouncementParameters.image
*/
public var image: AnnouncementImage? = prototype.image
@JvmName("image") get
@JvmSynthetic set
/**
* @see AnnouncementParameters.sendToNewMember
*/
public var sendToNewMember: Boolean = prototype.sendToNewMember
@JvmName("sendToNewMember") get
@JvmSynthetic set
/**
* @see AnnouncementParameters.isPinned
* @see AnnouncementParameters.pinned
*/
public var isPinned: Boolean = prototype.isPinned
public var pinned: Boolean = prototype.pinned
@JvmName("pinned") get
@JvmSynthetic set
/**
* @see AnnouncementParameters.isShowEditCard
* @see AnnouncementParameters.showEditCard
*/
public var isShowEditCard: Boolean = prototype.isShowEditCard
public var showEditCard: Boolean = prototype.showEditCard
@JvmName("showEditCard") get
@JvmSynthetic set
/**
* @see AnnouncementParameters.isTip
* @see AnnouncementParameters.popup
*/
public var isTip: Boolean = prototype.isTip
public var popup: Boolean = prototype.popup
@JvmName("popup") get
@JvmSynthetic set
/**
* @see AnnouncementParameters.needConfirm
*/
public var needConfirm: Boolean = prototype.needConfirm
@JvmName("needConfirm") get
@JvmSynthetic set
/**
* @see AnnouncementParameters.image
*/
public fun image(image: AnnouncementImage): AnnouncementParametersBuilder {
public fun image(image: AnnouncementImage?): AnnouncementParametersBuilder {
this.image = image
return this
}
@ -96,26 +108,26 @@ public class AnnouncementParametersBuilder @JvmOverloads constructor(
}
/**
* @see AnnouncementParameters.isPinned
* @see AnnouncementParameters.pinned
*/
public fun pinned(isPinned: Boolean): AnnouncementParametersBuilder {
this.isPinned = isPinned
this.pinned = isPinned
return this
}
/**
* @see AnnouncementParameters.isShowEditCard
* @see AnnouncementParameters.showEditCard
*/
public fun showEditCard(isShowEditCard: Boolean): AnnouncementParametersBuilder {
this.isShowEditCard = isShowEditCard
this.showEditCard = isShowEditCard
return this
}
/**
* @see AnnouncementParameters.isTip
* @see AnnouncementParameters.popup
*/
public fun tip(isTip: Boolean): AnnouncementParametersBuilder {
this.isTip = isTip
public fun popup(popup: Boolean): AnnouncementParametersBuilder {
this.popup = popup
return this
}
@ -131,7 +143,7 @@ public class AnnouncementParametersBuilder @JvmOverloads constructor(
* 使用当前参数构造 [AnnouncementParameters].
*/
public fun build(): AnnouncementParameters =
AnnouncementParameters(image, sendToNewMember, isPinned, isShowEditCard, isTip, needConfirm)
AnnouncementParameters(image, sendToNewMember, pinned, showEditCard, popup, needConfirm)
}
/**

View File

@ -256,11 +256,11 @@ internal object AnnouncementProtocol {
msg = GroupAnnouncementMsg(text = content),
type = if (parameters.sendToNewMember) 20 else 6,
settings = GroupAnnouncementSettings(
isShowEditCard = if (parameters.isShowEditCard) 1 else 0,
tipWindowType = if (parameters.isTip) 0 else 1,
isShowEditCard = if (parameters.showEditCard) 1 else 0,
tipWindowType = if (parameters.popup) 0 else 1,
confirmRequired = if (parameters.needConfirm) 1 else 0,
),
pinned = if (parameters.isPinned) 1 else 0,
pinned = if (parameters.pinned) 1 else 0,
)
}
@ -273,11 +273,11 @@ internal object AnnouncementProtocol {
sender = group[sender],
content = msg.text,
parameters = buildAnnouncementParameters {
isPinned = pinned == 1
pinned = this@toAnnouncement.pinned == 1
sendToNewMember = type == 20
isTip = settings.tipWindowType == 0
popup = settings.tipWindowType == 0
needConfirm = settings.confirmRequired == 1
isShowEditCard = settings.isShowEditCard == 1
showEditCard = settings.isShowEditCard == 1
},
fid = fid,
isAllRead = isAllConfirm != 0,