-
Notifications
You must be signed in to change notification settings - Fork 1
/
message_container.js
37 lines (37 loc) · 1.08 KB
/
message_container.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class MessageContainer extends Array {
constructor(msg_list, outer_self) {
msg_list = msg_list ? msg_list : [];
super(...msg_list);
this.outer_self = outer_self;
}
toString() {
const ss = this.map(elem => elem.toString());
const s = '[' + ss.join("\n") + ']';
return s;
}
get(args) {
let filtered_list = [];
this.forEach(msg => {
if (
this.outer_self.all(
Object.keys(args).map(
arg => {
return Object.keys(msg).includes(arg);
}
)
)
) {
if (this.outer_self.all(
Object.keys(args).map(arg => {
return msg[arg] == args[arg];
})
)
) {
filtered_list.push(msg);
}
}
});
return this.outer_self.MessageContainer(filtered_list, this.outer_self);
}
}
module.exports=MessageContainer;