Feature: Availability Statuses (#874)
Co-authored-by: Pranav Raj S <pranav@thoughtwoot.com>
This commit is contained in:
@@ -1,20 +1,31 @@
|
||||
import { createConsumer } from '@rails/actioncable';
|
||||
|
||||
const PRESENCE_INTERVAL = 60000;
|
||||
|
||||
class BaseActionCableConnector {
|
||||
constructor(app, pubsubToken) {
|
||||
this.consumer = createConsumer();
|
||||
this.consumer.subscriptions.create(
|
||||
this.subscription = this.consumer.subscriptions.create(
|
||||
{
|
||||
channel: 'RoomChannel',
|
||||
pubsub_token: pubsubToken,
|
||||
account_id: app.$store.getters.getCurrentAccountId,
|
||||
user_id: app.$store.getters.getCurrentUserID,
|
||||
},
|
||||
{
|
||||
updatePresence() {
|
||||
this.perform('update_presence');
|
||||
},
|
||||
received: this.onReceived,
|
||||
}
|
||||
);
|
||||
this.app = app;
|
||||
this.events = {};
|
||||
this.isAValidEvent = () => true;
|
||||
|
||||
setInterval(() => {
|
||||
this.subscription.updatePresence();
|
||||
}, PRESENCE_INTERVAL);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
|
||||
@@ -34,6 +34,17 @@ export const updateAttributes = (state, data) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const updatePresence = (state, data) => {
|
||||
state.records.forEach((element, index) => {
|
||||
const availabilityStatus = data[element.id];
|
||||
if (availabilityStatus) {
|
||||
Vue.set(state.records[index], 'availability_status', availabilityStatus);
|
||||
} else {
|
||||
Vue.delete(state.records[index], 'availability_status');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const destroy = (state, id) => {
|
||||
state.records = state.records.filter(record => record.id !== id);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user