xugenyuan

ref |> 直播模块显示自己发的评论数据

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
... ... @@ -372,6 +372,7 @@ export struct LiveOperRowListView {
this.publishCommentModel.rootCommentId = '-1';
this.publishCommentModel.parentId = '-1';
this.publishCommentModel.placeHolderText = "说两句..."
this.publishCommentModel.commentContent = ""
this.commentInputDialogController?.open();
}
... ...
import { ContentDetailDTO, LiveRoomDataBean } from 'wdBean/Index';
import { ContentDetailDTO, LiveRoomDataBean, LiveRoomItemBean } from 'wdBean/Index';
import { LiveViewModel } from '../viewModel/LiveViewModel';
import { TabComponent } from '../widgets/details/TabComponent';
import { TopPlayComponent } from '../widgets/details/video/TopPlayComponet';
... ... @@ -35,6 +35,10 @@ export struct DetailPlayLivePage {
@Consume contentDetailData: ContentDetailDTO
@Consume publishCommentModel: publishCommentModel
// 尽量不要动属性。用来作为输入了评论之后,值传递
@State lastInputedLiveComment: LiveRoomItemBean = {} as LiveRoomItemBean // 上次输入的直播间消息
@State lastInputedChatComment: LiveRoomItemBean = {} as LiveRoomItemBean // 上次输入的大家聊消息
aboutToAppear(): void {
Logger.info(TAG, `wyj-aboutToAppear`)
... ... @@ -65,7 +69,10 @@ export struct DetailPlayLivePage {
TopPlayComponent({ playerController: this.playerController })
.height(this.displayDirection == DisplayDirection.VERTICAL ? 211 : '100%')
TabComponent({ tabs: this.tabs, changeToTab: this.changeToTab })
TabComponent({ tabs: this.tabs,
changeToTab: this.changeToTab,
lastInputedLiveComment: this.lastInputedLiveComment,
lastInputedChatComment: this.lastInputedChatComment})
.layoutWeight(1)
.visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)
... ... @@ -79,7 +86,16 @@ export struct DetailPlayLivePage {
},
onCommentInputed: (content) => {
if (content.comment) {
this.liveViewModel.sendComment(content.comment, this.contentDetailData)
this.liveViewModel.sendComment(content.comment, this.contentDetailData).then(result => {
if (!result) {
return
}
if (result.isWall == 1) {
this.lastInputedLiveComment = result
} else {
this.lastInputedChatComment = result
}
})
}
}
}).visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)
... ...
import { HttpUrlUtils, HttpUtils, ResponseDTO } from 'wdNetwork';
import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest';
import { Logger, ToastUtils, EmitterEventId, EmitterUtils, SPHelper } from 'wdKit';
import { ContentDetailDTO, LiveDetailsBean, LiveRoomBean, LiveRoomDataBean, ReserveItemBean, ValueType } from 'wdBean/Index';
import { ContentDetailDTO, LiveDetailsBean, LiveRoomBean, LiveRoomDataBean,
LiveRoomItemBean,
ReserveItemBean, ValueType } from 'wdBean/Index';
import { ContentDetailRequest } from 'wdDetailPlayApi/Index';
import { SpConstants } from 'wdConstant/Index';
... ... @@ -274,6 +276,11 @@ export class LiveModel {
let liveId: string = content.newsId + ''
let mLiveId: string = content.liveInfo.mlive.mliveId as string
let commentItem: LiveRoomItemBean = {} as LiveRoomItemBean
commentItem.text = comment
commentItem.isWall = 0
commentItem.dataType = "ZH_TEXT_MSG"
let params: Record<string, string | number> = {};
params["liveId"] = liveId
params["mliveId"] = mLiveId
... ... @@ -288,14 +295,22 @@ export class LiveModel {
params["senderUserId"] = SPHelper.default.getSync(SpConstants.USER_ID, "") as string
params["senderAvatarUrl"] = SPHelper.default.getSync(SpConstants.USER_HEAD_PHOTO_URL, "") as string
params["senderUserName"] = SPHelper.default.getSync(SpConstants.USER_NAME, "") as string
commentItem.senderUserAvatarUrl = params["senderAvatarUrl"]
}
commentItem.senderUserName = params["senderUserName"]
params["customizeExpression"] = 0
params["role"] = tourist ? "tourist" : "audience"
commentItem.role = tourist ? "tourist" : "audience"
let url = tourist ? HttpUrlUtils.getLiveTouristSendBarrageUrl() : HttpUrlUtils.getLiveSendBarrageUrl()
return new Promise<ResponseDTO<Record<string, string | number>>>((success, fail) => {
HttpRequest.post<ResponseDTO<Record<string, string | number>>>(url, params).then((data) => {
success(data)
return new Promise<SendLiveCommentRes>((success, fail) => {
HttpRequest.post<ResponseDTO<SendLiveCommentInterfaceRes>>(url, params).then((data) => {
let res:SendLiveCommentRes = {
preDisplay: data.data?.preDisplay || false,
tipMessage: data.message,
commentItem: commentItem
}
success(res)
}, (error: Error) => {
fail(error.message)
Logger.debug(TAG + ":error ", error.toString())
... ... @@ -304,3 +319,11 @@ export class LiveModel {
}
}
interface SendLiveCommentInterfaceRes {
preDisplay: boolean
}
export interface SendLiveCommentRes {
preDisplay: boolean
tipMessage: string
commentItem: LiveRoomItemBean
}
\ No newline at end of file
... ...
import { ContentDetailDTO,
GetPullAddressBean,
LiveDetailsBean, LiveRoomBean, LiveRoomDataBean, ValueType } from 'wdBean/Index'
LiveDetailsBean, LiveRoomBean, LiveRoomDataBean,
LiveRoomItemBean,
ValueType } from 'wdBean/Index'
import { ContentDetailRequest } from 'wdDetailPlayApi/Index'
import { Logger } from 'wdKit/Index'
import { ToastUtils } from 'wdKit/src/main/ets/utils/ToastUtils'
import { ResponseDTO } from 'wdNetwork/Index'
import { LiveModel } from './LiveModel'
... ... @@ -138,13 +141,38 @@ export class LiveViewModel {
// 发送评论
sendComment(comment: string, content: ContentDetailDTO) {
return new Promise<ResponseDTO<string>>((success, fail) => {
return new Promise<LiveRoomItemBean | undefined>((success, fail) => {
this.liveModel.liveSendComment(comment, content).then((data) => {
// success(data)
Logger.debug(TAG, "发送评论结果: " + JSON.stringify(data))
if (data.preDisplay) {
success(data.commentItem)
} else {
success(undefined)
}
ToastUtils.showToast(data.tipMessage, 3000)
}).catch((message: string) => {
fail(message)
})
})
}
deepCopyLiveRoomItem(item: LiveRoomItemBean) {
return item
let retItem: LiveRoomItemBean = {} as LiveRoomItemBean
retItem.text = item.text
retItem.senderUserAvatarUrl = item.senderUserAvatarUrl
retItem.senderUserName = item.senderUserName
retItem.pictureUrls = item.pictureUrls
retItem.time = item.time
retItem.isWall = item.isWall
retItem.isTop = item.isTop
retItem.dataType = item.dataType
retItem.transcodeImageUrl = item.transcodeImageUrl
retItem.videoUrl = item.videoUrl
retItem.pictureResolutions = item.pictureResolutions
retItem.duration = item.duration
retItem.audioUrl = item.audioUrl
retItem.fullColumnImgUrlDto = item.fullColumnImgUrlDto
return retItem
}
}
... ...
... ... @@ -23,6 +23,7 @@ export struct TabChatComponent {
@State liveChatList: Array<LiveRoomItemBean> = []
@Consume contentDetailData: ContentDetailDTO
@Consume publishCommentModel: publishCommentModel
@Prop @Watch("lastInputedCommentChanged") lastInputedComment: LiveRoomItemBean
aboutToAppear(): void {
this.getLiveChatList()
... ... @@ -46,6 +47,12 @@ export struct TabChatComponent {
})
}
lastInputedCommentChanged(info: string) {
Logger.debug(TAG, "2显示评论》》》: " + JSON.stringify(this.lastInputedComment))
this.liveChatList.push(this.liveViewModel.deepCopyLiveRoomItem(this.lastInputedComment))
this.pageModel.viewType = ViewType.LOADED;
}
build() {
Stack() {
if (this.pageModel.viewType == ViewType.LOADING) {
... ...
import { LiveRoomItemBean, Action, PhotoListBean, Params } from 'wdBean/Index'
import { StringUtils } from 'wdKit/Index'
import { Logger, StringUtils } from 'wdKit/Index'
// import { Action, LiveRoomItemBean, Params, PhotoListBean } from 'wdBean/Index'
import { WDRouterRule } from 'wdRouter'
import { ExtraDTO } from 'wdBean/src/main/ets/bean/component/extra/ExtraDTO'
const TAG = "TabChatItemComponent"
@Component
export struct TabChatItemComponent {
item: LiveRoomItemBean = {} as LiveRoomItemBean
aboutToAppear(): void {
Logger.debug(TAG, "评论内容: " + this.item.text + " 评论sender: " + this.item.senderUserName)
}
build() {
... ...
import { LiveRoomItemBean } from 'wdBean/Index'
import { TabChatComponent } from './TabChatComponent'
import { TabInfoComponent } from './TabInfoComponent'
import { TabLiveComponent } from './TabLiveComponent'
... ... @@ -13,6 +14,9 @@ export struct TabComponent {
@State currentIndex: number = 0
private controller: TabsController = new TabsController()
@Prop tabs: string[] = []
@Prop lastInputedLiveComment: LiveRoomItemBean // 上次输入的直播间消息
@Prop lastInputedChatComment: LiveRoomItemBean // 上次输入的大家聊消息
aboutToAppear(): void {
}
... ... @@ -34,9 +38,9 @@ export struct TabComponent {
if ('简介' === item) {
TabInfoComponent()
} else if ('直播间' === item) {
TabLiveComponent()
TabLiveComponent({lastInputedComment: this.lastInputedLiveComment})
} else if ('大家聊' === item) {
TabChatComponent()
TabChatComponent({lastInputedComment: this.lastInputedChatComment})
}
}
.backgroundColor('#F5F5F5')
... ...
... ... @@ -23,11 +23,18 @@ export struct TabLiveComponent {
@Consume @Watch('updateData') contentDetailData: ContentDetailDTO
@State private pageModel: PageModel = new PageModel()
private scroller: Scroller = new Scroller()
@Prop @Watch("lastInputedCommentChanged") lastInputedComment: LiveRoomItemBean
aboutToAppear(): void {
this.getLiveList()
}
lastInputedCommentChanged(info: string) {
Logger.debug(TAG, "1显示评论》》》: " + JSON.stringify(this.lastInputedComment))
this.liveList.push(this.liveViewModel.deepCopyLiveRoomItem(this.lastInputedComment))
this.pageModel.viewType = ViewType.LOADED;
}
build() {
Stack() {
if (this.pageModel.viewType == ViewType.LOADING) {
... ...
... ... @@ -10,7 +10,7 @@ import { LiveViewModel } from '../../viewModel/LiveViewModel'
import { ChartItemCompereComponent } from './ChartItemCompereComponent'
import { ChatItemComponent } from './ChartItemComponent'
import { router } from '@kit.ArkUI'
import { EmitterEventId, EmitterUtils, SPHelper, WindowModel } from 'wdKit/Index'
import { EmitterEventId, EmitterUtils, Logger, SPHelper, WindowModel } from 'wdKit/Index'
const TAG = "PlayerCommentComponent"
... ... @@ -28,22 +28,6 @@ export struct PlayerCommentComponent {
async aboutToAppear(): Promise<void> {
this.getLiveChatList()
//注册通知
EmitterUtils.receiveEvent(EmitterEventId.COMMENT_PUBLISH, async (targetId?: string) => {
if (targetId) {
if (targetId == this.publishCommentModel.targetId) {
const info = {
senderUserName: this.publishCommentModel.lastCommentModel.fromUserName,
text: this.publishCommentModel.lastCommentModel.commentContent,
} as LiveRoomItemBean
this.liveChatList.push(info)
this.scroller.scrollEdge(Edge.Bottom)
console.log(TAG, '发布评论:', JSON.stringify(this.publishCommentModel.lastCommentModel))
}
}
})
}
generateRandomString() {
... ... @@ -122,7 +106,14 @@ export struct PlayerCommentComponent {
},
onCommentInputed: (content) => {
if (content.comment) {
this.liveViewModel.sendComment(content.comment, this.contentDetailData)
this.liveViewModel.sendComment(content.comment, this.contentDetailData).then(result => {
if (!result) {
return
}
Logger.debug(TAG, "3显示评论》》》: " + JSON.stringify(result))
this.liveChatList.push(result)
this.scroller.scrollEdge(Edge.Bottom)
})
}
},
onBack: () => {
... ...