Skip to content

Commit 584d405

Browse files
committedJan 12, 2020
Обработка временно выключенных уведомлений
1 parent 96c6054 commit 584d405

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed
 

Diff for: ‎src/components/App.vue

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import { fields } from 'js/utils';
1616
import { mapState } from 'vuex';
1717
import vkapi from 'js/vkapi';
18+
import { addNotificationsTimer } from 'js/messages';
1819
1920
import Titlebar from './Titlebar.vue';
2021
import MainMenu from './MainMenu.vue';
@@ -44,15 +45,19 @@
4445
this.$router.replace('/messages');
4546
}
4647
47-
const { lp, counters, user } = await vkapi('execute.init', {
48+
const { lp, counters, user, temporarilyDisabledNotifications } = await vkapi('execute.init', {
4849
lp_version: longpoll.version,
49-
fields: fields
50+
fields
5051
});
5152
5253
this.$store.commit('users/updateUser', user);
5354
this.$store.commit('setMenuCounters', counters);
5455
5556
longpoll.start(lp);
57+
58+
for(const peer of temporarilyDisabledNotifications) {
59+
addNotificationsTimer(peer);
60+
}
5661
}
5762
}
5863
},

Diff for: ‎src/js/longpollEvents.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parseMessage, parseConversation, loadConversation, loadConversationMembers } from './messages';
1+
import { parseMessage, parseConversation, loadConversation, loadConversationMembers, addNotificationsTimer } from './messages';
22
import { supportedAttachments, preloadAttachments } from '../components/messages/chat/attachments/attachments';
33
import longpoll from 'js/longpoll';
44
import store from './store/';
@@ -723,7 +723,6 @@ export default {
723723
// Изменеие настроек пуш-уведомлений в беседе
724724
// [{ peer_id, sound, disabled_until }]
725725
// disabled_until: -1 - выключены; 0 - включены; * - время их включения
726-
// При значении > 0 нужно самому следить за временем, ибо событие при включении не приходит.
727726
parser: (data) => data,
728727
handler([{ peer_id, disabled_until }]) {
729728
if(!store.state.messages.conversations[peer_id]) return;
@@ -734,6 +733,8 @@ export default {
734733
muted: !!disabled_until
735734
}
736735
});
736+
737+
addNotificationsTimer({ peer_id, disabled_until }, disabled_until <= 0);
737738
}
738739
},
739740

Diff for: ‎src/js/messages.js

+24
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,27 @@ export async function loadConversationMembers(id, force) {
206206
}
207207
}
208208
}
209+
210+
const activeNotificationsTimers = new Map();
211+
212+
export function addNotificationsTimer({ peer_id, disabled_until }, remove) {
213+
if(remove) {
214+
clearTimeout(activeNotificationsTimers.get(peer_id));
215+
return activeNotificationsTimers.delete(peer_id);
216+
}
217+
218+
if(activeNotificationsTimers.has(peer_id)) {
219+
clearTimeout(activeNotificationsTimers.get(peer_id));
220+
}
221+
222+
activeNotificationsTimers.set(peer_id, setTimeout(() => {
223+
activeNotificationsTimers.delete(peer_id);
224+
225+
store.commit('messages/updateConversation', {
226+
peer: {
227+
id: peer_id,
228+
muted: false
229+
}
230+
});
231+
}, disabled_until * 1000 - Date.now()));
232+
}

0 commit comments

Comments
 (0)
Please sign in to comment.