Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@adiwajshing/baileys/WASignalGroup/sender_key_name.js
1126 views
1
function isNull(str) {
2
return str === null || str.value === '';
3
}
4
5
/**
6
* java String hashCode 的实现
7
* @param strKey
8
* @return intValue
9
*/
10
function intValue(num) {
11
const MAX_VALUE = 0x7fffffff;
12
const MIN_VALUE = -0x80000000;
13
if (num > MAX_VALUE || num < MIN_VALUE) {
14
// eslint-disable-next-line
15
return (num &= 0xffffffff);
16
}
17
return num;
18
}
19
20
function hashCode(strKey) {
21
let hash = 0;
22
if (!isNull(strKey)) {
23
for (let i = 0; i < strKey.length; i++) {
24
hash = hash * 31 + strKey.charCodeAt(i);
25
hash = intValue(hash);
26
}
27
}
28
return hash;
29
}
30
31
/**
32
* 将js页面的number类型转换为java的int类型
33
* @param num
34
* @return intValue
35
*/
36
37
class SenderKeyName {
38
constructor(groupId, sender) {
39
this.groupId = groupId;
40
this.sender = sender;
41
}
42
43
getGroupId() {
44
return this.groupId;
45
}
46
47
getSender() {
48
return this.sender;
49
}
50
51
serialize() {
52
return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`;
53
}
54
55
toString() {
56
return this.serialize();
57
}
58
59
equals(other) {
60
if (other === null) return false;
61
if (!(other instanceof SenderKeyName)) return false;
62
return this.groupId === other.groupId && this.sender.toString() === other.sender.toString();
63
}
64
65
hashCode() {
66
return hashCode(this.groupId) ^ hashCode(this.sender.toString());
67
}
68
}
69
70
module.exports = SenderKeyName;
71