xugenyuan

ref |> 直播IM消息显示,处理竖屏直播

@@ -38,8 +38,14 @@ export interface LiveRoomItemBean { @@ -38,8 +38,14 @@ export interface LiveRoomItemBean {
38 fullColumnImgUrlDto: FullColumnImgUrlDTO 38 fullColumnImgUrlDto: FullColumnImgUrlDTO
39 //观看人次 39 //观看人次
40 pv: string 40 pv: string
41 - // 自义定表情 - from im 41 +
  42 + ///------- from IM
  43 + // 自义定表情
42 customizeExpression: number 44 customizeExpression: number
  45 + // 已登录的用户id
  46 + senderUserId?: string
  47 + // 未登录的设备id
  48 + deviceId?: string
43 49
44 // 自定义字段 50 // 自定义字段
45 customFormIM?: boolean // 默认来自网络接口 51 customFormIM?: boolean // 默认来自网络接口
@@ -71,4 +77,26 @@ export enum LiveMessageOptType { @@ -71,4 +77,26 @@ export enum LiveMessageOptType {
71 export enum LiveMessageRoomType { 77 export enum LiveMessageRoomType {
72 living = "ZH_VIDEO", // 直播间 78 living = "ZH_VIDEO", // 直播间
73 chat = "ZH_CHAT", // 大家聊 79 chat = "ZH_CHAT", // 大家聊
  80 +}
  81 +
  82 +export enum LiveMessageRole {
  83 + host = "host",
  84 + guest = "guest",
  85 + tourist = "tourist",
  86 +}
  87 +
  88 +export function LiveMessageIsHistoryMessage(optionType: LiveMessageOptType): boolean {
  89 + let isHistoryMessage = false
  90 + switch (optionType) {
  91 + case LiveMessageOptType.ZH_TEXT_MSG:
  92 + case LiveMessageOptType.ZH_IMAGE_MSG:
  93 + case LiveMessageOptType.ZH_TEXT_AND_IMAGE_MSG:
  94 + case LiveMessageOptType.ZH_AUDIO_MSG:
  95 + case LiveMessageOptType.ZH_VIDEO_MSG: {
  96 + isHistoryMessage = true
  97 + } break;
  98 + default:
  99 + break;
  100 + }
  101 + return isHistoryMessage
74 } 102 }
@@ -10,7 +10,7 @@ import { LiveRoomItemBean } from 'wdBean/Index'; @@ -10,7 +10,7 @@ import { LiveRoomItemBean } from 'wdBean/Index';
10 import { LiveRoomBaseInfo } from './LiveRoomBaseInfo' 10 import { LiveRoomBaseInfo } from './LiveRoomBaseInfo'
11 11
12 import { JSON } from '@kit.ArkTS'; 12 import { JSON } from '@kit.ArkTS';
13 -import { LiveMessageOptType } from 'wdBean/src/main/ets/bean/live/LiveRoomBean'; 13 +import { LiveMessageIsHistoryMessage, LiveMessageOptType } from 'wdBean/src/main/ets/bean/live/LiveRoomBean';
14 14
15 const TAG = "LiveRoomManager" 15 const TAG = "LiveRoomManager"
16 16
@@ -109,7 +109,7 @@ export class LiveRoom extends ChatroomStatusListener { @@ -109,7 +109,7 @@ export class LiveRoom extends ChatroomStatusListener {
109 109
110 let optionType = liveRoomItemBean.optionType != undefined ? liveRoomItemBean.optionType : liveRoomItemBean.dataType 110 let optionType = liveRoomItemBean.optionType != undefined ? liveRoomItemBean.optionType : liveRoomItemBean.dataType
111 111
112 - if (this.isHistoryMessage(optionType)) { 112 + if (LiveMessageIsHistoryMessage(optionType)) {
113 liveRoomItemBean.customFormIM = true 113 liveRoomItemBean.customFormIM = true
114 if (this.onHistoryMessage) { 114 if (this.onHistoryMessage) {
115 this.onHistoryMessage(liveRoomItemBean) 115 this.onHistoryMessage(liveRoomItemBean)
@@ -123,20 +123,4 @@ export class LiveRoom extends ChatroomStatusListener { @@ -123,20 +123,4 @@ export class LiveRoom extends ChatroomStatusListener {
123 123
124 124
125 } 125 }
126 -  
127 - isHistoryMessage(optionType: string): boolean {  
128 - let isHistoryMessage = false  
129 - switch (optionType) {  
130 - case LiveMessageOptType.ZH_TEXT_MSG:  
131 - case LiveMessageOptType.ZH_IMAGE_MSG:  
132 - case LiveMessageOptType.ZH_TEXT_AND_IMAGE_MSG:  
133 - case LiveMessageOptType.ZH_AUDIO_MSG:  
134 - case LiveMessageOptType.ZH_VIDEO_MSG: {  
135 - isHistoryMessage = true  
136 - } break;  
137 - default:  
138 - break;  
139 - }  
140 - return isHistoryMessage  
141 - }  
142 } 126 }
@@ -95,6 +95,10 @@ export struct DetailPlayLivePage { @@ -95,6 +95,10 @@ export struct DetailPlayLivePage {
95 95
96 configChatRoom() { 96 configChatRoom() {
97 this.chatRoomController.onHistoryMessage = (liveRoomItemBean: LiveRoomItemBean) => { 97 this.chatRoomController.onHistoryMessage = (liveRoomItemBean: LiveRoomItemBean) => {
  98 + const preDisplay = this.contentDetailData.liveInfo.preCommentFlag == 1
  99 + if (this.liveViewModel.filterMySelfCommentNoPreDisplay(liveRoomItemBean, preDisplay)) {
  100 + return
  101 + }
98 if (liveRoomItemBean.messageRoom == LiveMessageRoomType.living) { 102 if (liveRoomItemBean.messageRoom == LiveMessageRoomType.living) {
99 this.lastInputedLiveComment = liveRoomItemBean 103 this.lastInputedLiveComment = liveRoomItemBean
100 } else if (liveRoomItemBean.messageRoom == LiveMessageRoomType.chat) { 104 } else if (liveRoomItemBean.messageRoom == LiveMessageRoomType.chat) {
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 { CustomToast, WindowModel } from 'wdKit/Index'; 3 import { CustomToast, WindowModel } from 'wdKit/Index';
4 import { PlayerComponent } from '../widgets/vertical/PlayerComponent'; 4 import { PlayerComponent } from '../widgets/vertical/PlayerComponent';
@@ -12,6 +12,7 @@ import { LiveDetailPageLogic } from '../viewModel/LiveDetailPageLogic'; @@ -12,6 +12,7 @@ import { LiveDetailPageLogic } from '../viewModel/LiveDetailPageLogic';
12 import { onlyWifiLoadVideo } from 'wdComponent/src/main/ets/utils/lazyloadImg'; 12 import { onlyWifiLoadVideo } from 'wdComponent/src/main/ets/utils/lazyloadImg';
13 import { StringUtils } from 'wdKit'; 13 import { StringUtils } from 'wdKit';
14 import { LiveDetailChatRoomController } from '../im/LiveDetailChatRoomController'; 14 import { LiveDetailChatRoomController } from '../im/LiveDetailChatRoomController';
  15 +import { LiveMessageOptType } from 'wdBean/src/main/ets/bean/live/LiveRoomBean';
15 16
16 const storage = LocalStorage.getShared(); 17 const storage = LocalStorage.getShared();
17 const TAG = 'DetailPlayVLivePage' 18 const TAG = 'DetailPlayVLivePage'
@@ -40,6 +41,7 @@ export struct DetailPlayVLivePage { @@ -40,6 +41,7 @@ export struct DetailPlayVLivePage {
40 @Consume contentId: string 41 @Consume contentId: string
41 @State swiperIndex: number = 1 42 @State swiperIndex: number = 1
42 @Consume liveDetailPageLogic: LiveDetailPageLogic 43 @Consume liveDetailPageLogic: LiveDetailPageLogic
  44 + @Provide lastInputedComment: LiveRoomItemBean = {} as LiveRoomItemBean // 上次输入的消息
43 //播放错误 45 //播放错误
44 @State isPlayerError: boolean = false 46 @State isPlayerError: boolean = false
45 @State isCanplay: boolean = false 47 @State isCanplay: boolean = false
@@ -71,7 +73,7 @@ export struct DetailPlayVLivePage { @@ -71,7 +73,7 @@ export struct DetailPlayVLivePage {
71 if(!await onlyWifiLoadVideo()){ 73 if(!await onlyWifiLoadVideo()){
72 this.showToastTip(this.toastText) 74 this.showToastTip(this.toastText)
73 } 75 }
74 - this.chatRoomController.configDetail(this.contentDetailData) 76 + this.configChatRoom()
75 } 77 }
76 78
77 aboutToDisappear(): void { 79 aboutToDisappear(): void {
@@ -92,6 +94,22 @@ export struct DetailPlayVLivePage { @@ -92,6 +94,22 @@ export struct DetailPlayVLivePage {
92 // WindowModel.shared.setWindowSystemBarProperties({ statusBarContentColor: '#000000', }) 94 // WindowModel.shared.setWindowSystemBarProperties({ statusBarContentColor: '#000000', })
93 } 95 }
94 96
  97 + configChatRoom() {
  98 + this.chatRoomController.onHistoryMessage = (liveRoomItemBean: LiveRoomItemBean) => {
  99 + const preDisplay = this.contentDetailData.liveInfo.preCommentFlag == 1
  100 + if (this.liveViewModel.filterMySelfCommentNoPreDisplay(liveRoomItemBean, preDisplay)) {
  101 + return
  102 + }
  103 + this.lastInputedComment = liveRoomItemBean
  104 + }
  105 + this.chatRoomController.onLiveMessage = (liveRoomItemBean: LiveRoomItemBean) => {
  106 + if (liveRoomItemBean.optionType == LiveMessageOptType.ZH_ROOM_NUMBER_MSG) {
  107 + this.liveRoomDataBean.pv = Number(liveRoomItemBean.pv)
  108 + }
  109 + }
  110 + this.chatRoomController.configDetail(this.contentDetailData)
  111 + }
  112 +
95 build() { 113 build() {
96 114
97 Stack({ alignContent: Alignment.Top }) { 115 Stack({ alignContent: Alignment.Top }) {
@@ -7,10 +7,12 @@ import { @@ -7,10 +7,12 @@ import {
7 LiveRoomItemBean, 7 LiveRoomItemBean,
8 ValueType 8 ValueType
9 } from 'wdBean/Index' 9 } from 'wdBean/Index'
  10 +import { LiveMessageIsHistoryMessage } from 'wdBean/src/main/ets/bean/live/LiveRoomBean'
  11 +import { SpConstants } from 'wdConstant'
10 import { ContentDetailRequest } from 'wdDetailPlayApi/Index' 12 import { ContentDetailRequest } from 'wdDetailPlayApi/Index'
11 -import { Logger } from 'wdKit/Index' 13 +import { Logger, SPHelper } from 'wdKit/Index'
12 import { ToastUtils } from 'wdKit/src/main/ets/utils/ToastUtils' 14 import { ToastUtils } from 'wdKit/src/main/ets/utils/ToastUtils'
13 -import { ResponseDTO } from 'wdNetwork/Index' 15 +import { HttpUtils, ResponseDTO } from 'wdNetwork/Index'
14 import { LiveModel } from './LiveModel' 16 import { LiveModel } from './LiveModel'
15 17
16 const TAG = "LiveViewModel" 18 const TAG = "LiveViewModel"
@@ -196,4 +198,26 @@ export class LiveViewModel { @@ -196,4 +198,26 @@ export class LiveViewModel {
196 retItem.fullColumnImgUrlDto = item.fullColumnImgUrlDto 198 retItem.fullColumnImgUrlDto = item.fullColumnImgUrlDto
197 return retItem 199 return retItem
198 } 200 }
  201 +
  202 + filterMySelfCommentNoPreDisplay(comment: LiveRoomItemBean, openPreDisplay:boolean) {
  203 + let mySelf = false
  204 + const userId = HttpUtils.getUserId()
  205 + const deviceId = HttpUtils.getDeviceId()
  206 + if (comment.senderUserId && comment.senderUserId == userId) {
  207 + mySelf = true
  208 + } else if (comment.deviceId && comment.deviceId == deviceId) {
  209 + mySelf = true
  210 + }
  211 + let optionType = comment.optionType != undefined ? comment.optionType : comment.dataType
  212 +
  213 + if (mySelf
  214 + && openPreDisplay
  215 + && comment.customFormIM === true
  216 + && LiveMessageIsHistoryMessage(optionType)
  217 + ) {
  218 + return true
  219 + }
  220 + return false
  221 + }
  222 +
199 } 223 }
@@ -53,7 +53,9 @@ export struct TabChatComponent { @@ -53,7 +53,9 @@ export struct TabChatComponent {
53 53
54 this.liveChatList.push(info) 54 this.liveChatList.push(info)
55 this.pageModel.viewType = ViewType.LOADED; 55 this.pageModel.viewType = ViewType.LOADED;
56 - // this.scroller.scrollEdge(Edge.Bottom) 56 + if (this.pageModel.viewType == ViewType.LOADED) {
  57 + this.scroller.scrollEdge(Edge.Bottom)
  58 + }
57 console.log(TAG, '发布评论:', JSON.stringify(this.publishCommentModel.lastCommentModel)) 59 console.log(TAG, '发布评论:', JSON.stringify(this.publishCommentModel.lastCommentModel))
58 } 60 }
59 } 61 }
@@ -63,6 +65,9 @@ export struct TabChatComponent { @@ -63,6 +65,9 @@ export struct TabChatComponent {
63 lastInputedCommentChanged(info: string) { 65 lastInputedCommentChanged(info: string) {
64 Logger.debug(TAG, "2显示评论》》》: " + JSON.stringify(this.lastInputedComment)) 66 Logger.debug(TAG, "2显示评论》》》: " + JSON.stringify(this.lastInputedComment))
65 this.liveChatList.push(this.liveViewModel.deepCopyLiveRoomItem(this.lastInputedComment)) 67 this.liveChatList.push(this.liveViewModel.deepCopyLiveRoomItem(this.lastInputedComment))
  68 + if (this.pageModel.viewType == ViewType.LOADED) {
  69 + this.scroller.scrollEdge(Edge.Bottom)
  70 + }
66 this.pageModel.viewType = ViewType.LOADED; 71 this.pageModel.viewType = ViewType.LOADED;
67 } 72 }
68 73
1 import { LiveRoomItemBean } from 'wdBean/Index' 1 import { LiveRoomItemBean } from 'wdBean/Index'
  2 +import { LiveMessageRole } from 'wdBean/src/main/ets/bean/live/LiveRoomBean'
  3 +import { LengthMetrics } from '@kit.ArkUI'
2 4
3 @Component 5 @Component
4 export struct ChatItemComponent { 6 export struct ChatItemComponent {
@@ -10,17 +12,23 @@ export struct ChatItemComponent { @@ -10,17 +12,23 @@ export struct ChatItemComponent {
10 build() { 12 build() {
11 Row() { 13 Row() {
12 Text() { 14 Text() {
13 - // if (this.item.senderUserName) {  
14 - // Span(' 主持人 ')  
15 - // .fontSize(11)  
16 - // .lineHeight(20)  
17 - // .textBackgroundStyle({ color: '#808562', radius: 2 })  
18 - // Span(' ')  
19 - // } 15 + if (this.item.role == LiveMessageRole.host) {
  16 + Span(' 主持人 ')
  17 + .fontSize(11)
  18 + .lineHeight(20)
  19 + .textBackgroundStyle({ color: "#70FFC63F", radius: 2 })
  20 + Span(' ')
  21 + }
  22 + if (this.item.role == LiveMessageRole.guest) {
  23 + Span(' 嘉宾 ')
  24 + .fontSize(11)
  25 + .lineHeight(20)
  26 + .textBackgroundStyle({ color: "#70FFC63F", radius: 2 })
  27 + Span(' ')
  28 + }
20 Span(this.item.senderUserName + ': ') 29 Span(this.item.senderUserName + ': ')
21 .fontColor('#FFFFC63F') 30 .fontColor('#FFFFC63F')
22 .padding({ right: 118 }) 31 .padding({ right: 118 })
23 - //  
24 32
25 Span(this.item.text) 33 Span(this.item.text)
26 } 34 }
1 import { Action, ContentDetailDTO, LiveDetailsBean, LiveRoomDataBean, LiveRoomItemBean } from 'wdBean/Index' 1 import { Action, ContentDetailDTO, LiveDetailsBean, LiveRoomDataBean, LiveRoomItemBean } from 'wdBean/Index'
2 -import { LiveCommentComponent } from 'wdComponent/Index'  
3 -import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment/model/PublishCommentModel'  
4 import { LiveOperRowListView } from 'wdComponent' 2 import { LiveOperRowListView } from 'wdComponent'
5 import PageModel from 'wdComponent/src/main/ets/viewmodel/PageModel' 3 import PageModel from 'wdComponent/src/main/ets/viewmodel/PageModel'
6 import { DisplayDirection, SpConstants, ViewType } from 'wdConstant/Index' 4 import { DisplayDirection, SpConstants, ViewType } from 'wdConstant/Index'
@@ -25,8 +23,8 @@ export struct PlayerCommentComponent { @@ -25,8 +23,8 @@ export struct PlayerCommentComponent {
25 @Consume displayDirection: DisplayDirection 23 @Consume displayDirection: DisplayDirection
26 @State private pageModel: PageModel = new PageModel() 24 @State private pageModel: PageModel = new PageModel()
27 @State liveChatList: Array<LiveRoomItemBean> = [] 25 @State liveChatList: Array<LiveRoomItemBean> = []
  26 + @Consume @Watch("lastInputedCommentChagned") lastInputedComment: LiveRoomItemBean
28 @Consume @Watch('liveDetailsBeanChange') contentDetailData: ContentDetailDTO 27 @Consume @Watch('liveDetailsBeanChange') contentDetailData: ContentDetailDTO
29 - @Consume publishCommentModel: publishCommentModel  
30 scroller: Scroller = new Scroller() 28 scroller: Scroller = new Scroller()
31 29
32 async aboutToAppear(): Promise<void> { 30 async aboutToAppear(): Promise<void> {
@@ -81,6 +79,16 @@ export struct PlayerCommentComponent { @@ -81,6 +79,16 @@ export struct PlayerCommentComponent {
81 }) 79 })
82 } 80 }
83 81
  82 + lastInputedCommentChagned() {
  83 + Logger.debug(TAG, "2显示评论》》》: " + JSON.stringify(this.lastInputedComment))
  84 +
  85 + this.liveChatList.push(this.lastInputedComment)
  86 + if (this.pageModel.viewType == ViewType.LOADED) {
  87 + this.scroller.scrollEdge(Edge.Bottom)
  88 + }
  89 + this.pageModel.viewType = ViewType.LOADED;
  90 + }
  91 +
84 build() { 92 build() {
85 Column() { 93 Column() {
86 Stack({ alignContent: Alignment.BottomStart }) { 94 Stack({ alignContent: Alignment.BottomStart }) {