2018-02-14 10:29:41 +01:00

72 lines
2.6 KiB
TypeScript

// (C) Copyright 2015 Martin Dougiamas
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { Component, OnDestroy, ViewChild } from '@angular/core';
import { IonicPage } from 'ionic-angular';
import { CoreEventsProvider } from '../../../../providers/events';
import { CoreSitesProvider } from '../../../../providers/sites';
import { AddonMessagesProvider } from '../../providers/messages';
import { CoreSplitViewComponent } from '../../../../components/split-view/split-view';
/**
* Page that displays the messages index page.
*/
@IonicPage({ segment: 'addon-messages-index' })
@Component({
selector: 'page-addon-messages-index',
templateUrl: 'index.html',
})
export class AddonMessagesIndexPage implements OnDestroy {
@ViewChild(CoreSplitViewComponent) splitviewCtrl: CoreSplitViewComponent;
protected loadSplitViewObserver: any;
protected siteId: string;
constructor(private eventsProvider: CoreEventsProvider, sitesProvider: CoreSitesProvider,
private messagesProvider: AddonMessagesProvider) {
this.siteId = sitesProvider.getCurrentSiteId();
// Update split view or navigate.
this.loadSplitViewObserver = eventsProvider.on(AddonMessagesProvider.SPLIT_VIEW_LOAD_EVENT, (data) => {
if (data.discussion && (this.splitviewCtrl.isOn() || !data.onlyWithSplitView)) {
this.gotoDiscussion(data.discussion, data.message);
}
}, this.siteId);
}
/**
* Navigate to a particular discussion.
*
* @param {number} discussionUserId Discussion Id to load.
* @param {number} [messageId] Message to scroll after loading the discussion. Used when searching.
*/
gotoDiscussion(discussionUserId: number, messageId?: number): void {
const params = {
id: discussionUserId
};
if (messageId) {
params['message'] = messageId;
}
this.splitviewCtrl.push('AddonMessagesDiscussionPage', params);
}
/**
* Page destroyed.
*/
ngOnDestroy(): void {
this.loadSplitViewObserver && this.loadSplitViewObserver.off();
}
}