Browse Source

Don't show send when online if user hid his online

master
Eduard Kuzmenko 3 years ago
parent
commit
4c90cfb97a
  1. 4
      src/components/chat/input.ts
  2. 17
      src/components/popups/schedule.ts
  3. 4
      src/lib/appManagers/appUsersManager.ts

4
src/components/chat/input.ts

@ -654,6 +654,8 @@ export default class ChatInput {
} }
public scheduleSending = (callback: () => void = this.sendMessage.bind(this, true), initDate = new Date()) => { public scheduleSending = (callback: () => void = this.sendMessage.bind(this, true), initDate = new Date()) => {
const canSendWhenOnline = this.chat.peerId > 0 && this.appUsersManager.isUserOnlineVisible(this.chat.peerId);
new PopupSchedule(initDate, (timestamp) => { new PopupSchedule(initDate, (timestamp) => {
const minTimestamp = (Date.now() / 1000 | 0) + 10; const minTimestamp = (Date.now() / 1000 | 0) + 10;
if(timestamp <= minTimestamp) { if(timestamp <= minTimestamp) {
@ -666,7 +668,7 @@ export default class ChatInput {
if(this.chat.type !== 'scheduled' && timestamp) { if(this.chat.type !== 'scheduled' && timestamp) {
this.appImManager.openScheduled(this.chat.peerId); this.appImManager.openScheduled(this.chat.peerId);
} }
}).show(); }, canSendWhenOnline).show();
}; };
public setUnreadCount() { public setUnreadCount() {

17
src/components/popups/schedule.ts

@ -28,7 +28,7 @@ const checkDate = (date: Date) => {
}; };
export default class PopupSchedule extends PopupDatePicker { export default class PopupSchedule extends PopupDatePicker {
constructor(initDate: Date, onPick: (timestamp: number) => void) { constructor(initDate: Date, onPick: (timestamp: number) => void, canSendWhenOnline: boolean) {
super(checkDate(initDate), onPick, { super(checkDate(initDate), onPick, {
noButtons: true, noButtons: true,
noTitle: true, noTitle: true,
@ -43,13 +43,16 @@ export default class PopupSchedule extends PopupDatePicker {
this.element.classList.add('popup-schedule'); this.element.classList.add('popup-schedule');
this.header.append(this.controlsDiv); this.header.append(this.controlsDiv);
this.title.replaceWith(this.monthTitle); this.title.replaceWith(this.monthTitle);
this.body.append(this.btnConfirm);
const btnSendWhenOnline = Button('btn-primary btn-secondary btn-primary-transparent primary', {text: 'Schedule.SendWhenOnline'}); if(canSendWhenOnline) {
this.body.append(this.btnConfirm, btnSendWhenOnline); const btnSendWhenOnline = Button('btn-primary btn-secondary btn-primary-transparent primary', {text: 'Schedule.SendWhenOnline'});
this.body.append(btnSendWhenOnline);
attachClickEvent(btnSendWhenOnline, () => { attachClickEvent(btnSendWhenOnline, () => {
onPick(SEND_WHEN_ONLINE_TIMESTAMP); onPick(SEND_WHEN_ONLINE_TIMESTAMP);
this.hide(); this.hide();
}); });
}
} }
} }

4
src/lib/appManagers/appUsersManager.ts

@ -427,6 +427,10 @@ export class AppUsersManager {
return '+' + formatPhoneNumber(phone).formatted; return '+' + formatPhoneNumber(phone).formatted;
} }
public isUserOnlineVisible(id: number) {
return this.getUserStatusForSort(id) > 3;
}
public getUserStatusForSort(status: User['status'] | number) { public getUserStatusForSort(status: User['status'] | number) {
if(typeof(status) === 'number') { if(typeof(status) === 'number') {
status = this.getUser(status).status; status = this.getUser(status).status;

Loading…
Cancel
Save