2019-02-07 15:48:10 +00:00
|
|
|
import EJSON from 'ejson';
|
|
|
|
|
2018-04-24 19:34:03 +00:00
|
|
|
import normalizeMessage from './normalizeMessage';
|
|
|
|
// TODO: delete and update
|
|
|
|
|
|
|
|
export const merge = (subscription, room) => {
|
2019-02-07 15:48:10 +00:00
|
|
|
subscription = EJSON.fromJSONValue(subscription);
|
|
|
|
room = EJSON.fromJSONValue(room);
|
|
|
|
|
2018-08-10 17:26:36 +00:00
|
|
|
if (!subscription) {
|
|
|
|
return;
|
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
if (room) {
|
2019-10-07 20:56:30 +00:00
|
|
|
if (room._updatedAt) {
|
|
|
|
subscription.roomUpdatedAt = room._updatedAt;
|
|
|
|
subscription.lastMessage = normalizeMessage(room.lastMessage);
|
|
|
|
subscription.description = room.description;
|
|
|
|
subscription.topic = room.topic;
|
|
|
|
subscription.announcement = room.announcement;
|
|
|
|
subscription.reactWhenReadOnly = room.reactWhenReadOnly;
|
|
|
|
subscription.archived = room.archived || false;
|
|
|
|
subscription.joinCodeRequired = room.joinCodeRequired;
|
|
|
|
subscription.jitsiTimeout = room.jitsiTimeout;
|
2018-05-24 20:17:45 +00:00
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
subscription.ro = room.ro;
|
2018-05-24 20:17:45 +00:00
|
|
|
subscription.broadcast = room.broadcast;
|
2019-04-26 21:13:07 +00:00
|
|
|
if (!subscription.roles || !subscription.roles.length) {
|
|
|
|
subscription.roles = [];
|
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
if (room.muted && room.muted.length) {
|
2019-05-20 20:43:50 +00:00
|
|
|
subscription.muted = room.muted.filter(muted => !!muted);
|
2018-06-01 17:38:13 +00:00
|
|
|
} else {
|
|
|
|
subscription.muted = [];
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-20 19:54:20 +00:00
|
|
|
if (!subscription.name) {
|
|
|
|
subscription.name = subscription.fname;
|
|
|
|
}
|
|
|
|
|
2018-05-24 20:17:45 +00:00
|
|
|
subscription.blocker = !!subscription.blocker;
|
|
|
|
subscription.blocked = !!subscription.blocked;
|
2018-04-24 19:34:03 +00:00
|
|
|
return subscription;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default (subscriptions = [], rooms = []) => {
|
|
|
|
if (subscriptions.update) {
|
|
|
|
subscriptions = subscriptions.update;
|
|
|
|
rooms = rooms.update;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
subscriptions: subscriptions.map((s) => {
|
|
|
|
const index = rooms.findIndex(({ _id }) => _id === s.rid);
|
|
|
|
if (index < 0) {
|
|
|
|
return merge(s);
|
|
|
|
}
|
|
|
|
const [room] = rooms.splice(index, 1);
|
|
|
|
return merge(s, room);
|
|
|
|
}),
|
|
|
|
rooms
|
|
|
|
};
|
|
|
|
};
|