Skip to content

Commit

Permalink
Merge pull request #3730 from NoelDeMartin/MOBILE-4048
Browse files Browse the repository at this point in the history
MOBILE-4048 chat: Log sessions view events
  • Loading branch information
dpalou authored Jul 24, 2023
2 parents c843090 + 6088b7e commit aeb12fa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/addons/mod/chat/pages/session-messages/session-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ export class AddonModChatSessionMessagesPage implements OnInit {
protected logView: () => void;

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({
type: CoreAnalyticsEventType.VIEW_ITEM_LIST,
type: CoreAnalyticsEventType.VIEW_ITEM,
ws: 'mod_chat_view_sessions',
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}`,
});
});
Expand Down
6 changes: 5 additions & 1 deletion src/addons/mod/chat/pages/sessions/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { AddonModChatSessionFormatted, AddonModChatSessionsSource } from '../../
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { CoreTime } from '@singletons/time';
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.
Expand All @@ -41,9 +43,11 @@ export class AddonModChatSessionsPage implements OnInit, AfterViewInit, OnDestro
protected logView: () => void;

constructor() {
this.logView = CoreTime.once(() => {
this.logView = CoreTime.once(async () => {
const source = this.sessions.getSource();

await CoreUtils.ignoreErrors(AddonModChat.logViewSessions(this.sessions.getSource().CM_ID));

CoreAnalytics.logEvent({
type: CoreAnalyticsEventType.VIEW_ITEM_LIST,
ws: 'mod_chat_view_sessions',
Expand Down
35 changes: 35 additions & 0 deletions src/addons/mod/chat/services/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -478,6 +504,15 @@ export type AddonModChatViewChatWSParams = {
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.
*/
Expand Down

0 comments on commit aeb12fa

Please sign in to comment.