Merge pull request #272 from NicolasConstant/topic_firefox-autofocus

Topic firefox autofocus
This commit is contained in:
Nicolas Constant 2020-04-30 20:53:28 -04:00 committed by GitHub
commit fde017ccf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 53 deletions

View File

@ -735,7 +735,11 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
if (isVisible) { if (isVisible) {
setTimeout(() => { setTimeout(() => {
this.footerElement.nativeElement.scrollIntoViewIfNeeded({ behavior: 'instant', block: 'end', inline: 'start' }); try{
this.footerElement.nativeElement.scrollIntoViewIfNeeded({ behavior: 'instant', block: 'end', inline: 'start' });
}catch(err) {
this.footerElement.nativeElement.scrollIntoView({ behavior: 'instant', block: 'end', inline: 'start' });
}
}, 0); }, 0);
} }
} }

View File

@ -25,6 +25,9 @@ export class UserNotificationService {
private soundJustPlayed = false; private soundJustPlayed = false;
private soundFileId: string; private soundFileId: string;
private accountSub: Subscription;
private loadedAccounts: AccountInfo[] = [];
constructor( constructor(
private readonly streamingService: StreamingService, private readonly streamingService: StreamingService,
private readonly toolsService: ToolsService, private readonly toolsService: ToolsService,
@ -37,49 +40,58 @@ export class UserNotificationService {
private fetchNotifications() { private fetchNotifications() {
let accounts = this.store.snapshot().registeredaccounts.accounts; let accounts = this.store.snapshot().registeredaccounts.accounts;
// let promises: Promise<any>[] = [];
accounts.forEach((account: AccountInfo) => { accounts.forEach((account: AccountInfo) => {
// let sinceId = null; this.loadedAccounts.push(account);
// if (this.sinceIds[account.id]) { this.startFetchingNotifications(account);
// sinceId = this.sinceIds[account.id];
// }
let getMentionsPromise = this.mastodonService.getNotifications(account, ['favourite', 'follow', 'reblog', 'poll'], null, null, 10)
.then((notifications: Notification[]) => {
this.processMentionsAndNotifications(account, notifications, NotificationTypeEnum.UserMention);
})
.catch(err => {
this.notificationService.notifyHttpError(err, account);
});
let getNotificationPromise = this.mastodonService.getNotifications(account, ['mention'], null, null, 10)
.then((notifications: Notification[]) => {
this.processMentionsAndNotifications(account, notifications, NotificationTypeEnum.UserNotification);
})
.catch(err => {
this.notificationService.notifyHttpError(err, account);
});
Promise.all([getMentionsPromise, getNotificationPromise])
.then(() => {
let streamElement = new StreamElement(StreamTypeEnum.personnal, 'activity', account.id, null, null, null, account.instance);
let streaming = this.streamingService.getStreaming(account, streamElement);
streaming.statusUpdateSubjet.subscribe((notification: StatusUpdate) => {
if (notification && notification.type === EventEnum.notification) {
this.processNewUpdate(account, notification);
}
});
})
.catch(err => { });
}); });
this.accountSub = this.store.select(state => state.registeredaccounts.accounts)
.subscribe((accounts: AccountInfo[]) => {
accounts.forEach(a => {
if(!this.loadedAccounts.find(x => x.id === a.id)){
this.loadedAccounts.push(a);
this.startFetchingNotifications(a);
}
});
});
}
private startFetchingNotifications(account: AccountInfo) {
let getMentionsPromise = this.mastodonService.getNotifications(account, ['favourite', 'follow', 'reblog', 'poll'], null, null, 10)
.then((notifications: Notification[]) => {
this.processMentionsAndNotifications(account, notifications, NotificationTypeEnum.UserMention);
})
.catch(err => {
this.notificationService.notifyHttpError(err, account);
});
let getNotificationPromise = this.mastodonService.getNotifications(account, ['mention'], null, null, 10)
.then((notifications: Notification[]) => {
this.processMentionsAndNotifications(account, notifications, NotificationTypeEnum.UserNotification);
})
.catch(err => {
this.notificationService.notifyHttpError(err, account);
});
Promise.all([getMentionsPromise, getNotificationPromise])
.then(() => {
let streamElement = new StreamElement(StreamTypeEnum.personnal, 'activity', account.id, null, null, null, account.instance);
let streaming = this.streamingService.getStreaming(account, streamElement);
streaming.statusUpdateSubjet.subscribe((notification: StatusUpdate) => {
if (notification && notification.type === EventEnum.notification) {
this.processNewUpdate(account, notification);
}
});
})
.catch(err => { });
} }
private playSoundNotification() { private playSoundNotification() {
const settings = this.toolsService.getSettings(); const settings = this.toolsService.getSettings();
if(settings.disableSounds) return; if (settings.disableSounds) return;
if(this.soundJustPlayed) return; if (this.soundJustPlayed) return;
this.soundJustPlayed = true; this.soundJustPlayed = true;
this.setNotificationSound(); this.setNotificationSound();
@ -94,13 +106,13 @@ export class UserNotificationService {
let settings = this.toolsService.getSettings(); let settings = this.toolsService.getSettings();
let soundId = settings.notificationSoundFileId; let soundId = settings.notificationSoundFileId;
if(!soundId){ if (!soundId) {
soundId = '0'; soundId = '0';
settings.notificationSoundFileId = '0'; settings.notificationSoundFileId = '0';
this.toolsService.saveSettings(settings); this.toolsService.saveSettings(settings);
} }
if(this.soundFileId === soundId) return; if (this.soundFileId === soundId) return;
var sound = this.getAllNotificationSounds().find(x => x.id === soundId); var sound = this.getAllNotificationSounds().find(x => x.id === soundId);
this.sound = new Howl({ this.sound = new Howl({
@ -110,9 +122,9 @@ export class UserNotificationService {
} }
private processNewUpdate(account: AccountInfo, notification: StatusUpdate) { private processNewUpdate(account: AccountInfo, notification: StatusUpdate) {
if(!notification && !notification.notification) return; if (!notification && !notification.notification) return;
if(!notification.muteSound){ if (!notification.muteSound) {
this.playSoundNotification(); this.playSoundNotification();
} }
@ -135,9 +147,9 @@ export class UserNotificationService {
currentAccountNotifications = this.analyseNotifications(account, currentAccountNotifications, notifications, type); currentAccountNotifications = this.analyseNotifications(account, currentAccountNotifications, notifications, type);
//if (currentAccountNotifications.hasNewMentions || currentAccountNotifications.hasNewNotifications) { //if (currentAccountNotifications.hasNewMentions || currentAccountNotifications.hasNewNotifications) {
currentNotifications = currentNotifications.filter(x => x.account.id !== account.id); currentNotifications = currentNotifications.filter(x => x.account.id !== account.id);
currentNotifications.push(currentAccountNotifications); currentNotifications.push(currentAccountNotifications);
this.userNotifications.next(currentNotifications); this.userNotifications.next(currentNotifications);
//} //}
} else { } else {
let newNotifications = new UserNotification(); let newNotifications = new UserNotification();
@ -261,5 +273,5 @@ export class NotificationSoundDefinition {
constructor( constructor(
public readonly id: string, public readonly id: string,
public readonly path: string, public readonly path: string,
public readonly name: string) {} public readonly name: string) { }
} }