forked from EVOgeek/Vmeda.Online
		
	MOBILE-4048 chat: Log sessions view events
This commit is contained in:
		
							parent
							
								
									c6714285b0
								
							
						
					
					
						commit
						6088b7ed56
					
				| @ -48,12 +48,17 @@ export class AddonModChatSessionMessagesPage implements OnInit { | |||||||
|     protected logView: () => void; |     protected logView: () => void; | ||||||
| 
 | 
 | ||||||
|     constructor() { |     constructor() { | ||||||
|         this.logView = CoreTime.once(() => { |         this.logView = CoreTime.once(async () => { | ||||||
|  |             await CoreUtils.ignoreErrors(AddonModChat.logViewSessions(this.cmId, { | ||||||
|  |                 start: this.sessionStart, | ||||||
|  |                 end: this.sessionEnd, | ||||||
|  |             })); | ||||||
|  | 
 | ||||||
|             CoreAnalytics.logEvent({ |             CoreAnalytics.logEvent({ | ||||||
|                 type: CoreAnalyticsEventType.VIEW_ITEM_LIST, |                 type: CoreAnalyticsEventType.VIEW_ITEM, | ||||||
|                 ws: 'mod_chat_view_sessions', |                 ws: 'mod_chat_view_sessions', | ||||||
|                 name: Translate.instant('addon.mod_chat.messages'), |                 name: Translate.instant('addon.mod_chat.messages'), | ||||||
|                 data: { chatid: this.chatId, category: 'chat' }, |                 data: { chatid: this.chatId, category: 'chat', start: this.sessionStart, end: this.sessionEnd }, | ||||||
|                 url: `/mod/chat/report.php?id=${this.cmId}&start=${this.sessionStart}&end=${this.sessionEnd}`, |                 url: `/mod/chat/report.php?id=${this.cmId}&start=${this.sessionStart}&end=${this.sessionEnd}`, | ||||||
|             }); |             }); | ||||||
|         }); |         }); | ||||||
|  | |||||||
| @ -24,6 +24,8 @@ import { AddonModChatSessionFormatted, AddonModChatSessionsSource } from '../../ | |||||||
| import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; | import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; | ||||||
| import { CoreTime } from '@singletons/time'; | import { CoreTime } from '@singletons/time'; | ||||||
| import { Translate } from '@singletons'; | import { Translate } from '@singletons'; | ||||||
|  | import { AddonModChat } from '@addons/mod/chat/services/chat'; | ||||||
|  | import { CoreUtils } from '@services/utils/utils'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Page that displays list of chat sessions. |  * Page that displays list of chat sessions. | ||||||
| @ -41,9 +43,11 @@ export class AddonModChatSessionsPage implements OnInit, AfterViewInit, OnDestro | |||||||
|     protected logView: () => void; |     protected logView: () => void; | ||||||
| 
 | 
 | ||||||
|     constructor() { |     constructor() { | ||||||
|         this.logView = CoreTime.once(() => { |         this.logView = CoreTime.once(async () => { | ||||||
|             const source = this.sessions.getSource(); |             const source = this.sessions.getSource(); | ||||||
| 
 | 
 | ||||||
|  |             await CoreUtils.ignoreErrors(AddonModChat.logViewSessions(this.sessions.getSource().CM_ID)); | ||||||
|  | 
 | ||||||
|             CoreAnalytics.logEvent({ |             CoreAnalytics.logEvent({ | ||||||
|                 type: CoreAnalyticsEventType.VIEW_ITEM_LIST, |                 type: CoreAnalyticsEventType.VIEW_ITEM_LIST, | ||||||
|                 ws: 'mod_chat_view_sessions', |                 ws: 'mod_chat_view_sessions', | ||||||
|  | |||||||
| @ -104,6 +104,32 @@ export class AddonModChatProvider { | |||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Report chat session views. | ||||||
|  |      * | ||||||
|  |      * @param id Chat instance ID. | ||||||
|  |      * @param period Session period if viewing an individual session. | ||||||
|  |      * @param period.start Period start. | ||||||
|  |      * @param period.end Period end. | ||||||
|  |      */ | ||||||
|  |     async logViewSessions(id: number, period?: { start: number; end: number }): Promise<void> { | ||||||
|  |         const params: AddonModChatViewSessionsWSParams = { | ||||||
|  |             cmid: id, | ||||||
|  |         }; | ||||||
|  | 
 | ||||||
|  |         if (period) { | ||||||
|  |             params.start = period.start; | ||||||
|  |             params.end = period.end; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         await CoreCourseLogHelper.log( | ||||||
|  |             'mod_chat_view_sessions', | ||||||
|  |             params, | ||||||
|  |             AddonModChatProvider.COMPONENT, | ||||||
|  |             id, | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * Send a message to a chat. |      * Send a message to a chat. | ||||||
|      * |      * | ||||||
| @ -478,6 +504,15 @@ export type AddonModChatViewChatWSParams = { | |||||||
|     chatid: number; // Chat instance id.
 |     chatid: number; // Chat instance id.
 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | /** | ||||||
|  |  * Params of mod_chat_view_sessions WS. | ||||||
|  |  */ | ||||||
|  | export type AddonModChatViewSessionsWSParams = { | ||||||
|  |     cmid: number; // Course module id.
 | ||||||
|  |     start?: number; // Session start time.
 | ||||||
|  |     end?: number; // Session end time.
 | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * Params of mod_chat_send_chat_message WS. |  * Params of mod_chat_send_chat_message WS. | ||||||
|  */ |  */ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user