xugenyuan

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

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
@@ -372,6 +372,7 @@ export struct LiveOperRowListView { @@ -372,6 +372,7 @@ export struct LiveOperRowListView {
372 this.publishCommentModel.rootCommentId = '-1'; 372 this.publishCommentModel.rootCommentId = '-1';
373 this.publishCommentModel.parentId = '-1'; 373 this.publishCommentModel.parentId = '-1';
374 this.publishCommentModel.placeHolderText = "说两句..." 374 this.publishCommentModel.placeHolderText = "说两句..."
  375 + this.publishCommentModel.commentContent = ""
375 this.commentInputDialogController?.open(); 376 this.commentInputDialogController?.open();
376 } 377 }
377 378
1 -import { ContentDetailDTO, LiveRoomDataBean } from 'wdBean/Index'; 1 +import { ContentDetailDTO, LiveRoomDataBean, LiveRoomItemBean } from 'wdBean/Index';
2 import { LiveViewModel } from '../viewModel/LiveViewModel'; 2 import { LiveViewModel } from '../viewModel/LiveViewModel';
3 import { TabComponent } from '../widgets/details/TabComponent'; 3 import { TabComponent } from '../widgets/details/TabComponent';
4 import { TopPlayComponent } from '../widgets/details/video/TopPlayComponet'; 4 import { TopPlayComponent } from '../widgets/details/video/TopPlayComponet';
@@ -35,6 +35,10 @@ export struct DetailPlayLivePage { @@ -35,6 +35,10 @@ export struct DetailPlayLivePage {
35 @Consume contentDetailData: ContentDetailDTO 35 @Consume contentDetailData: ContentDetailDTO
36 @Consume publishCommentModel: publishCommentModel 36 @Consume publishCommentModel: publishCommentModel
37 37
  38 + // 尽量不要动属性。用来作为输入了评论之后,值传递
  39 + @State lastInputedLiveComment: LiveRoomItemBean = {} as LiveRoomItemBean // 上次输入的直播间消息
  40 + @State lastInputedChatComment: LiveRoomItemBean = {} as LiveRoomItemBean // 上次输入的大家聊消息
  41 +
38 aboutToAppear(): void { 42 aboutToAppear(): void {
39 Logger.info(TAG, `wyj-aboutToAppear`) 43 Logger.info(TAG, `wyj-aboutToAppear`)
40 44
@@ -65,7 +69,10 @@ export struct DetailPlayLivePage { @@ -65,7 +69,10 @@ export struct DetailPlayLivePage {
65 TopPlayComponent({ playerController: this.playerController }) 69 TopPlayComponent({ playerController: this.playerController })
66 .height(this.displayDirection == DisplayDirection.VERTICAL ? 211 : '100%') 70 .height(this.displayDirection == DisplayDirection.VERTICAL ? 211 : '100%')
67 71
68 - TabComponent({ tabs: this.tabs, changeToTab: this.changeToTab }) 72 + TabComponent({ tabs: this.tabs,
  73 + changeToTab: this.changeToTab,
  74 + lastInputedLiveComment: this.lastInputedLiveComment,
  75 + lastInputedChatComment: this.lastInputedChatComment})
69 .layoutWeight(1) 76 .layoutWeight(1)
70 .visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None) 77 .visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)
71 78
@@ -79,7 +86,16 @@ export struct DetailPlayLivePage { @@ -79,7 +86,16 @@ export struct DetailPlayLivePage {
79 }, 86 },
80 onCommentInputed: (content) => { 87 onCommentInputed: (content) => {
81 if (content.comment) { 88 if (content.comment) {
82 - this.liveViewModel.sendComment(content.comment, this.contentDetailData) 89 + this.liveViewModel.sendComment(content.comment, this.contentDetailData).then(result => {
  90 + if (!result) {
  91 + return
  92 + }
  93 + if (result.isWall == 1) {
  94 + this.lastInputedLiveComment = result
  95 + } else {
  96 + this.lastInputedChatComment = result
  97 + }
  98 + })
83 } 99 }
84 } 100 }
85 }).visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None) 101 }).visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)
1 import { HttpUrlUtils, HttpUtils, ResponseDTO } from 'wdNetwork'; 1 import { HttpUrlUtils, HttpUtils, ResponseDTO } from 'wdNetwork';
2 import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest'; 2 import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest';
3 import { Logger, ToastUtils, EmitterEventId, EmitterUtils, SPHelper } from 'wdKit'; 3 import { Logger, ToastUtils, EmitterEventId, EmitterUtils, SPHelper } from 'wdKit';
4 -import { ContentDetailDTO, LiveDetailsBean, LiveRoomBean, LiveRoomDataBean, ReserveItemBean, ValueType } from 'wdBean/Index'; 4 +import { ContentDetailDTO, LiveDetailsBean, LiveRoomBean, LiveRoomDataBean,
  5 + LiveRoomItemBean,
  6 + ReserveItemBean, ValueType } from 'wdBean/Index';
5 import { ContentDetailRequest } from 'wdDetailPlayApi/Index'; 7 import { ContentDetailRequest } from 'wdDetailPlayApi/Index';
6 import { SpConstants } from 'wdConstant/Index'; 8 import { SpConstants } from 'wdConstant/Index';
7 9
@@ -274,6 +276,11 @@ export class LiveModel { @@ -274,6 +276,11 @@ export class LiveModel {
274 let liveId: string = content.newsId + '' 276 let liveId: string = content.newsId + ''
275 let mLiveId: string = content.liveInfo.mlive.mliveId as string 277 let mLiveId: string = content.liveInfo.mlive.mliveId as string
276 278
  279 + let commentItem: LiveRoomItemBean = {} as LiveRoomItemBean
  280 + commentItem.text = comment
  281 + commentItem.isWall = 0
  282 + commentItem.dataType = "ZH_TEXT_MSG"
  283 +
277 let params: Record<string, string | number> = {}; 284 let params: Record<string, string | number> = {};
278 params["liveId"] = liveId 285 params["liveId"] = liveId
279 params["mliveId"] = mLiveId 286 params["mliveId"] = mLiveId
@@ -288,14 +295,22 @@ export class LiveModel { @@ -288,14 +295,22 @@ export class LiveModel {
288 params["senderUserId"] = SPHelper.default.getSync(SpConstants.USER_ID, "") as string 295 params["senderUserId"] = SPHelper.default.getSync(SpConstants.USER_ID, "") as string
289 params["senderAvatarUrl"] = SPHelper.default.getSync(SpConstants.USER_HEAD_PHOTO_URL, "") as string 296 params["senderAvatarUrl"] = SPHelper.default.getSync(SpConstants.USER_HEAD_PHOTO_URL, "") as string
290 params["senderUserName"] = SPHelper.default.getSync(SpConstants.USER_NAME, "") as string 297 params["senderUserName"] = SPHelper.default.getSync(SpConstants.USER_NAME, "") as string
  298 + commentItem.senderUserAvatarUrl = params["senderAvatarUrl"]
291 } 299 }
  300 + commentItem.senderUserName = params["senderUserName"]
292 params["customizeExpression"] = 0 301 params["customizeExpression"] = 0
293 params["role"] = tourist ? "tourist" : "audience" 302 params["role"] = tourist ? "tourist" : "audience"
  303 + commentItem.role = tourist ? "tourist" : "audience"
294 304
295 let url = tourist ? HttpUrlUtils.getLiveTouristSendBarrageUrl() : HttpUrlUtils.getLiveSendBarrageUrl() 305 let url = tourist ? HttpUrlUtils.getLiveTouristSendBarrageUrl() : HttpUrlUtils.getLiveSendBarrageUrl()
296 - return new Promise<ResponseDTO<Record<string, string | number>>>((success, fail) => {  
297 - HttpRequest.post<ResponseDTO<Record<string, string | number>>>(url, params).then((data) => {  
298 - success(data) 306 + return new Promise<SendLiveCommentRes>((success, fail) => {
  307 + HttpRequest.post<ResponseDTO<SendLiveCommentInterfaceRes>>(url, params).then((data) => {
  308 + let res:SendLiveCommentRes = {
  309 + preDisplay: data.data?.preDisplay || false,
  310 + tipMessage: data.message,
  311 + commentItem: commentItem
  312 + }
  313 + success(res)
299 }, (error: Error) => { 314 }, (error: Error) => {
300 fail(error.message) 315 fail(error.message)
301 Logger.debug(TAG + ":error ", error.toString()) 316 Logger.debug(TAG + ":error ", error.toString())
@@ -304,3 +319,11 @@ export class LiveModel { @@ -304,3 +319,11 @@ export class LiveModel {
304 } 319 }
305 } 320 }
306 321
  322 +interface SendLiveCommentInterfaceRes {
  323 + preDisplay: boolean
  324 +}
  325 +export interface SendLiveCommentRes {
  326 + preDisplay: boolean
  327 + tipMessage: string
  328 + commentItem: LiveRoomItemBean
  329 +}
1 import { ContentDetailDTO, 1 import { ContentDetailDTO,
2 GetPullAddressBean, 2 GetPullAddressBean,
3 - LiveDetailsBean, LiveRoomBean, LiveRoomDataBean, ValueType } from 'wdBean/Index' 3 + LiveDetailsBean, LiveRoomBean, LiveRoomDataBean,
  4 + LiveRoomItemBean,
  5 + ValueType } from 'wdBean/Index'
4 import { ContentDetailRequest } from 'wdDetailPlayApi/Index' 6 import { ContentDetailRequest } from 'wdDetailPlayApi/Index'
5 - 7 +import { Logger } from 'wdKit/Index'
  8 +import { ToastUtils } from 'wdKit/src/main/ets/utils/ToastUtils'
6 import { ResponseDTO } from 'wdNetwork/Index' 9 import { ResponseDTO } from 'wdNetwork/Index'
7 import { LiveModel } from './LiveModel' 10 import { LiveModel } from './LiveModel'
8 11
@@ -138,13 +141,38 @@ export class LiveViewModel { @@ -138,13 +141,38 @@ export class LiveViewModel {
138 141
139 // 发送评论 142 // 发送评论
140 sendComment(comment: string, content: ContentDetailDTO) { 143 sendComment(comment: string, content: ContentDetailDTO) {
141 - return new Promise<ResponseDTO<string>>((success, fail) => { 144 + return new Promise<LiveRoomItemBean | undefined>((success, fail) => {
142 this.liveModel.liveSendComment(comment, content).then((data) => { 145 this.liveModel.liveSendComment(comment, content).then((data) => {
143 -  
144 - // success(data) 146 + Logger.debug(TAG, "发送评论结果: " + JSON.stringify(data))
  147 + if (data.preDisplay) {
  148 + success(data.commentItem)
  149 + } else {
  150 + success(undefined)
  151 + }
  152 + ToastUtils.showToast(data.tipMessage, 3000)
145 }).catch((message: string) => { 153 }).catch((message: string) => {
146 fail(message) 154 fail(message)
147 }) 155 })
148 }) 156 })
149 } 157 }
  158 +
  159 + deepCopyLiveRoomItem(item: LiveRoomItemBean) {
  160 + return item
  161 + let retItem: LiveRoomItemBean = {} as LiveRoomItemBean
  162 + retItem.text = item.text
  163 + retItem.senderUserAvatarUrl = item.senderUserAvatarUrl
  164 + retItem.senderUserName = item.senderUserName
  165 + retItem.pictureUrls = item.pictureUrls
  166 + retItem.time = item.time
  167 + retItem.isWall = item.isWall
  168 + retItem.isTop = item.isTop
  169 + retItem.dataType = item.dataType
  170 + retItem.transcodeImageUrl = item.transcodeImageUrl
  171 + retItem.videoUrl = item.videoUrl
  172 + retItem.pictureResolutions = item.pictureResolutions
  173 + retItem.duration = item.duration
  174 + retItem.audioUrl = item.audioUrl
  175 + retItem.fullColumnImgUrlDto = item.fullColumnImgUrlDto
  176 + return retItem
  177 + }
150 } 178 }
@@ -23,6 +23,7 @@ export struct TabChatComponent { @@ -23,6 +23,7 @@ export struct TabChatComponent {
23 @State liveChatList: Array<LiveRoomItemBean> = [] 23 @State liveChatList: Array<LiveRoomItemBean> = []
24 @Consume contentDetailData: ContentDetailDTO 24 @Consume contentDetailData: ContentDetailDTO
25 @Consume publishCommentModel: publishCommentModel 25 @Consume publishCommentModel: publishCommentModel
  26 + @Prop @Watch("lastInputedCommentChanged") lastInputedComment: LiveRoomItemBean
26 27
27 aboutToAppear(): void { 28 aboutToAppear(): void {
28 this.getLiveChatList() 29 this.getLiveChatList()
@@ -46,6 +47,12 @@ export struct TabChatComponent { @@ -46,6 +47,12 @@ export struct TabChatComponent {
46 }) 47 })
47 } 48 }
48 49
  50 + lastInputedCommentChanged(info: string) {
  51 + Logger.debug(TAG, "2显示评论》》》: " + JSON.stringify(this.lastInputedComment))
  52 + this.liveChatList.push(this.liveViewModel.deepCopyLiveRoomItem(this.lastInputedComment))
  53 + this.pageModel.viewType = ViewType.LOADED;
  54 + }
  55 +
49 build() { 56 build() {
50 Stack() { 57 Stack() {
51 if (this.pageModel.viewType == ViewType.LOADING) { 58 if (this.pageModel.viewType == ViewType.LOADING) {
1 import { LiveRoomItemBean, Action, PhotoListBean, Params } from 'wdBean/Index' 1 import { LiveRoomItemBean, Action, PhotoListBean, Params } from 'wdBean/Index'
2 -import { StringUtils } from 'wdKit/Index' 2 +import { Logger, StringUtils } from 'wdKit/Index'
3 // import { Action, LiveRoomItemBean, Params, PhotoListBean } from 'wdBean/Index' 3 // import { Action, LiveRoomItemBean, Params, PhotoListBean } from 'wdBean/Index'
4 import { WDRouterRule } from 'wdRouter' 4 import { WDRouterRule } from 'wdRouter'
5 import { ExtraDTO } from 'wdBean/src/main/ets/bean/component/extra/ExtraDTO' 5 import { ExtraDTO } from 'wdBean/src/main/ets/bean/component/extra/ExtraDTO'
6 6
  7 +const TAG = "TabChatItemComponent"
  8 +
7 @Component 9 @Component
8 export struct TabChatItemComponent { 10 export struct TabChatItemComponent {
9 item: LiveRoomItemBean = {} as LiveRoomItemBean 11 item: LiveRoomItemBean = {} as LiveRoomItemBean
10 12
11 aboutToAppear(): void { 13 aboutToAppear(): void {
  14 + Logger.debug(TAG, "评论内容: " + this.item.text + " 评论sender: " + this.item.senderUserName)
12 } 15 }
13 16
14 build() { 17 build() {
  1 +import { LiveRoomItemBean } from 'wdBean/Index'
1 import { TabChatComponent } from './TabChatComponent' 2 import { TabChatComponent } from './TabChatComponent'
2 import { TabInfoComponent } from './TabInfoComponent' 3 import { TabInfoComponent } from './TabInfoComponent'
3 import { TabLiveComponent } from './TabLiveComponent' 4 import { TabLiveComponent } from './TabLiveComponent'
@@ -13,6 +14,9 @@ export struct TabComponent { @@ -13,6 +14,9 @@ export struct TabComponent {
13 @State currentIndex: number = 0 14 @State currentIndex: number = 0
14 private controller: TabsController = new TabsController() 15 private controller: TabsController = new TabsController()
15 @Prop tabs: string[] = [] 16 @Prop tabs: string[] = []
  17 + @Prop lastInputedLiveComment: LiveRoomItemBean // 上次输入的直播间消息
  18 + @Prop lastInputedChatComment: LiveRoomItemBean // 上次输入的大家聊消息
  19 +
16 aboutToAppear(): void { 20 aboutToAppear(): void {
17 21
18 } 22 }
@@ -34,9 +38,9 @@ export struct TabComponent { @@ -34,9 +38,9 @@ export struct TabComponent {
34 if ('简介' === item) { 38 if ('简介' === item) {
35 TabInfoComponent() 39 TabInfoComponent()
36 } else if ('直播间' === item) { 40 } else if ('直播间' === item) {
37 - TabLiveComponent() 41 + TabLiveComponent({lastInputedComment: this.lastInputedLiveComment})
38 } else if ('大家聊' === item) { 42 } else if ('大家聊' === item) {
39 - TabChatComponent() 43 + TabChatComponent({lastInputedComment: this.lastInputedChatComment})
40 } 44 }
41 } 45 }
42 .backgroundColor('#F5F5F5') 46 .backgroundColor('#F5F5F5')
@@ -23,11 +23,18 @@ export struct TabLiveComponent { @@ -23,11 +23,18 @@ export struct TabLiveComponent {
23 @Consume @Watch('updateData') contentDetailData: ContentDetailDTO 23 @Consume @Watch('updateData') contentDetailData: ContentDetailDTO
24 @State private pageModel: PageModel = new PageModel() 24 @State private pageModel: PageModel = new PageModel()
25 private scroller: Scroller = new Scroller() 25 private scroller: Scroller = new Scroller()
  26 + @Prop @Watch("lastInputedCommentChanged") lastInputedComment: LiveRoomItemBean
26 27
27 aboutToAppear(): void { 28 aboutToAppear(): void {
28 this.getLiveList() 29 this.getLiveList()
29 } 30 }
30 31
  32 + lastInputedCommentChanged(info: string) {
  33 + Logger.debug(TAG, "1显示评论》》》: " + JSON.stringify(this.lastInputedComment))
  34 + this.liveList.push(this.liveViewModel.deepCopyLiveRoomItem(this.lastInputedComment))
  35 + this.pageModel.viewType = ViewType.LOADED;
  36 + }
  37 +
31 build() { 38 build() {
32 Stack() { 39 Stack() {
33 if (this.pageModel.viewType == ViewType.LOADING) { 40 if (this.pageModel.viewType == ViewType.LOADING) {
@@ -10,7 +10,7 @@ import { LiveViewModel } from '../../viewModel/LiveViewModel' @@ -10,7 +10,7 @@ import { LiveViewModel } from '../../viewModel/LiveViewModel'
10 import { ChartItemCompereComponent } from './ChartItemCompereComponent' 10 import { ChartItemCompereComponent } from './ChartItemCompereComponent'
11 import { ChatItemComponent } from './ChartItemComponent' 11 import { ChatItemComponent } from './ChartItemComponent'
12 import { router } from '@kit.ArkUI' 12 import { router } from '@kit.ArkUI'
13 -import { EmitterEventId, EmitterUtils, SPHelper, WindowModel } from 'wdKit/Index' 13 +import { EmitterEventId, EmitterUtils, Logger, SPHelper, WindowModel } from 'wdKit/Index'
14 14
15 const TAG = "PlayerCommentComponent" 15 const TAG = "PlayerCommentComponent"
16 16
@@ -28,22 +28,6 @@ export struct PlayerCommentComponent { @@ -28,22 +28,6 @@ export struct PlayerCommentComponent {
28 async aboutToAppear(): Promise<void> { 28 async aboutToAppear(): Promise<void> {
29 29
30 this.getLiveChatList() 30 this.getLiveChatList()
31 - //注册通知  
32 - EmitterUtils.receiveEvent(EmitterEventId.COMMENT_PUBLISH, async (targetId?: string) => {  
33 - if (targetId) {  
34 - if (targetId == this.publishCommentModel.targetId) {  
35 - const info = {  
36 - senderUserName: this.publishCommentModel.lastCommentModel.fromUserName,  
37 - text: this.publishCommentModel.lastCommentModel.commentContent,  
38 - } as LiveRoomItemBean  
39 -  
40 - this.liveChatList.push(info)  
41 - this.scroller.scrollEdge(Edge.Bottom)  
42 - console.log(TAG, '发布评论:', JSON.stringify(this.publishCommentModel.lastCommentModel))  
43 - }  
44 - }  
45 - })  
46 -  
47 } 31 }
48 32
49 generateRandomString() { 33 generateRandomString() {
@@ -122,7 +106,14 @@ export struct PlayerCommentComponent { @@ -122,7 +106,14 @@ export struct PlayerCommentComponent {
122 }, 106 },
123 onCommentInputed: (content) => { 107 onCommentInputed: (content) => {
124 if (content.comment) { 108 if (content.comment) {
125 - this.liveViewModel.sendComment(content.comment, this.contentDetailData) 109 + this.liveViewModel.sendComment(content.comment, this.contentDetailData).then(result => {
  110 + if (!result) {
  111 + return
  112 + }
  113 + Logger.debug(TAG, "3显示评论》》》: " + JSON.stringify(result))
  114 + this.liveChatList.push(result)
  115 + this.scroller.scrollEdge(Edge.Bottom)
  116 + })
126 } 117 }
127 }, 118 },
128 onBack: () => { 119 onBack: () => {