Merge pull request #272 from NicolasConstant/topic_firefox-autofocus
Topic firefox autofocus
This commit is contained in:
commit
fde017ccf6
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,82 +25,94 @@ 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,
|
||||||
private readonly notificationService: NotificationService,
|
private readonly notificationService: NotificationService,
|
||||||
private readonly mastodonService: MastodonWrapperService,
|
private readonly mastodonService: MastodonWrapperService,
|
||||||
private readonly store: Store) {
|
private readonly store: Store) {
|
||||||
|
|
||||||
this.fetchNotifications();
|
this.fetchNotifications();
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
this.sound.play();
|
this.sound.play();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.soundJustPlayed = false;
|
this.soundJustPlayed = false;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private setNotificationSound() {
|
private setNotificationSound() {
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,15 +141,15 @@ export class UserNotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentNotifications = this.userNotifications.value;
|
let currentNotifications = this.userNotifications.value;
|
||||||
let currentAccountNotifications = currentNotifications.find(x => x.account.id === account.id);
|
let currentAccountNotifications = currentNotifications.find(x => x.account.id === account.id);
|
||||||
|
|
||||||
if (currentAccountNotifications) {
|
if (currentAccountNotifications) {
|
||||||
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();
|
||||||
|
@ -230,7 +242,7 @@ export class UserNotificationService {
|
||||||
new NotificationSoundDefinition('0', 'assets/audio/all-eyes-on-me.mp3', 'All eyes on me'),
|
new NotificationSoundDefinition('0', 'assets/audio/all-eyes-on-me.mp3', 'All eyes on me'),
|
||||||
new NotificationSoundDefinition('1', 'assets/audio/exquisite.mp3', 'Exquisite'),
|
new NotificationSoundDefinition('1', 'assets/audio/exquisite.mp3', 'Exquisite'),
|
||||||
new NotificationSoundDefinition('2', 'assets/audio/appointed.mp3', 'Appointed'),
|
new NotificationSoundDefinition('2', 'assets/audio/appointed.mp3', 'Appointed'),
|
||||||
new NotificationSoundDefinition('3', 'assets/audio/boop.mp3', 'Mastodon boop'),
|
new NotificationSoundDefinition('3', 'assets/audio/boop.mp3', 'Mastodon boop'),
|
||||||
];
|
];
|
||||||
return defs;
|
return defs;
|
||||||
}
|
}
|
||||||
|
@ -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) { }
|
||||||
}
|
}
|
Loading…
Reference in New Issue