-
Notifications
You must be signed in to change notification settings - Fork 1
/
chat.ts
730 lines (660 loc) · 27.5 KB
/
chat.ts
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
import { Ack, chatType, common, FiregunUser, Pubkey } from './common';
import Firegun from "./firegun";
export default class Chat {
firegun : Firegun
user : FiregunUser
/**
* Init Chat Class
* @param {Firegun} firegun Firegun instance
*/
constructor(firegun: Firegun) {
this.firegun = firegun;
this.user = this.firegun.user;
}
async getCert(pubKey:string) {
try {
let cert = await this.firegun.Get(`~${pubKey}/chat-cert`);
return cert;
} catch (error) {
console.log (error);
return "";
}
}
/**
* Generate Public Certificate for Logged in User
* @returns
*/
async generatePublicCert() : Promise<{data : Ack[],error : Ack[]}> {
return await common.generatePublicCert(this.firegun);
}
async decryptChat (s:{[x:string] : any},pubkey : Pubkey) {
if (s.msg) {
if ((typeof s.msg === "string") && (s.msg.search("SEA") === 0))
if (s._self) {
s.msg = await this.firegun.Gun.SEA.decrypt(s.msg, this.firegun.user.pair);
} else {
s.msg = await this.firegun.Gun.SEA.decrypt(s.msg, await (this.firegun.Gun as any).SEA.secret(pubkey.epub, this.firegun.user.pair));
}
return (s);
} else {
return ({})
}
}
/**
* Retrieve Chat Message, the result is stream
*
* @param pubkey
* @param date
* @param month
* @param year
* @param callback
*/
async retrieveDaily(pubkey: Pubkey, date : {date:string, month:string, year:string}) {
let res = await this.firegun.userLoad(`chat-with/${pubkey.pub}/${date.year}/${date.month}/${date.date}`);
let readTimestamp = await this.getReadTimestamp(pubkey);
// Load Data for 1 day
let chats:chatType[] = [];
if (res) {
for (const id in res.data) {
if (Object.prototype.hasOwnProperty.call(res.data, id)) {
let s = res.data[id].data as chatType;
if (s && s.id) {
let a = await this.decryptChat(s,pubkey)
s = a as chatType;
if (s) {
if (s.timestamp <= readTimestamp) {
s.status = "read";
} else {
s.status = "sent";
}
chats.push(s);
}
}
}
}
}
return chats;
}
async retrieveMonthly(pubkey: Pubkey, date : {month:string, year:string}) {
let res = await this.firegun.userLoad(`chat-with/${pubkey.pub}/${date.year}/${date.month}`);
let readTimestamp = await this.getReadTimestamp(pubkey);
// Load chat for 1 month
let chats:chatType[] = [];
if (res)
for (const date in res.data) {
const chatInDate = res.data[date].data;
for (const id in chatInDate) {
if (Object.prototype.hasOwnProperty.call(chatInDate, id)) {
let s = chatInDate[id].data as chatType;
if (s && s.id) {
let a = await this.decryptChat(s,pubkey)
s = a as chatType;
if (s) {
if (s.timestamp <= readTimestamp) {
s.status = "read";
} else {
s.status = "sent";
}
chats.push(s);
}
}
}
}
}
return chats;
}
async listen(pubkey : Pubkey, callback:(s:{[x:string] : any})=>void) {
let date = common.getDate();
this.firegun.gun.user().get("chat-with").get(pubkey.pub).get(date.year).get(date.month).get(date.date).map((s:any)=>{
if (s && s.id) {
// only listen to future chat
if (s.id > `${date.year}.${date.month}.${date.date}T${date.hour}:${date.minutes}:${date.seconds}.${date.miliseconds}`) {
return (s)
} else {
return null
}
} else {
return null
}
}).once(async (s:any)=>{
if (s && s.id) {
s = await this.decryptChat(s,pubkey);
if (s)
callback(s);
}
})
}
async listenUnsent(pubkey : Pubkey, callback:(chatID:string)=>void) {
const dateNow = common.getDate();
const date = `${dateNow.year}/${dateNow.month}/${dateNow.date}`;
this.firegun.On(`~${this.firegun.user.pair.pub}/chat-with/${pubkey.pub}/${date}/unsendChat`,(res)=>{
if (typeof res === "string") {
callback(res);
}
},pubkey.pub.substring(0,8),true);
}
async groupRetrieveChat(groupkey: { owner:string, alias:string}, date : {date:string, month:string, year:string} ,callback:(s:{[x:string] : any},alwaysSelf? : boolean)=>void) {
this.groupGetMembers(groupkey.owner,groupkey.alias)
.then(members => {
members.forEach(async (member) => {
this.firegun.gun.get(`~${member.pub}`).get("chat-group-with").get(`${groupkey.owner}&${groupkey.alias}`).get(date.year).get(date.month).get(date.date).map().once(async (s:any)=>{
if (s) {
callback(s);
callback(s,member.pub === this.firegun.user.pair.pub);
}
})
})
})
}
async listenMarkAsRead(pairkey: Pubkey, callback:(timeStamp:string)=>void) {
this.firegun.On(`~${this.firegun.user.pair.pub}/chat-with/${pairkey.pub}/readTimeStamp`,(s)=>{
if (typeof s==="string") {
callback(s);
}
});
}
async getReadTimestamp(pairkey: Pubkey): Promise<string> {
let data:string;
try {
let s = await this.firegun.userGet(`chat-with/${pairkey.pub}/readTimeStamp`);
if (typeof s === "string") {
data = s;
} else {
data = ""
}
} catch (error) {
data = "";
}
return (data);
}
async markAsRead(pairkey: Pubkey,cert=""): Promise<void> {
if (cert === "") {
let tempCert = await this.firegun.Get(`~${pairkey.pub}/chat-cert`);
if (typeof tempCert === "string") {
cert = tempCert;
}
}
let datetime = common.getDate()
let timestamp = `${datetime.year}/${datetime.month}/${datetime.date}T${datetime.hour}:${datetime.minutes}:${datetime.seconds}.${datetime.miliseconds}`;
await this.firegun.Put(`~${pairkey.pub}/chat-with/${this.firegun.user.pair.pub}/readTimeStamp`,timestamp,true, "",{
opt : {
cert : cert
}
});
}
async groupRetrieveChatMonthly(groupkey: { owner:string, alias:string}, date : {date:string, month:string, year:string}):Promise<chatType[]> {
return new Promise(async (resolve) => {
let members = await this.groupGetMembers(groupkey.owner,groupkey.alias);
let res = [];
for (const member of members) {
let data = await this.firegun.Load(`~${member.pub}/chat-group-with/${groupkey.owner}&${groupkey.alias}/${date.year}/${date.month}`);
if (data)
for (const date in data.data) {
const chatInDate = data.data[date].data;
for (const id in chatInDate) {
if (Object.prototype.hasOwnProperty.call(chatInDate, id)) {
let s = chatInDate[id].data;
if (s && s.id) {
if (s) {
res.push(s)
}
}
}
}
}
}
resolve (res);
});
}
async groupListen(groupkey: { owner:string, alias:string}, callback:(s:chatType)=>void) {
let date = common.getDate();
let members = await this.groupGetMembers(groupkey.owner,groupkey.alias);
for (const member of members) {
this.firegun.gun.get(`~${member.pub}`).get("chat-group-with").get(`${groupkey.owner}&${groupkey.alias}`).get(date.year).get(date.month).get(date.date).map((s:any)=>{
if (s && s.id) {
// only listen to future chat
if (s.id > `${date.year}.${date.month}.${date.date}T${date.hour}:${date.minutes}:${date.seconds}.${date.miliseconds}`) {
return (s)
} else {
return null
}
} else {
return null
}
}).once((s:any)=>{
if (s && s.id) {
if (s) {
let a = s as chatType;
callback(a);
}
}
});
}
}
async searchChat (searchString:string, pub:string, epub:string, callback:(s:{[x:string] : string})=>void) {
let date = common.getDate();
this.firegun.gun.user().get("chat-with")
.get(pub)
.get(date.year)
.once().map()
.once().map()
.once().map()
.once(async (s:any)=>{
if (s !== undefined) {
if ((typeof s.msg === "string") && (s.msg.search("SEA") === 0))
if (s._self) {
s.msg = await this.firegun.Gun.SEA.decrypt(s.msg, this.firegun.user.pair);
} else {
s.msg = await this.firegun.Gun.SEA.decrypt(s.msg, await (this.firegun.Gun as any).SEA.secret(epub, this.firegun.user.pair));
}
if (s.msg !== undefined && s.msg.toLowerCase().indexOf(searchString.toLowerCase()) !== -1) {
callback(s);
}
}
})
}
async unsend(pairkey: Pubkey,date:string,chatID: string,cert=""): Promise<string> {
return new Promise(async (resolve, reject) => {
if (!this.firegun.user.alias) {
reject("User Belum Login")
} else {
if (cert === "") {
let tempCert = await this.firegun.Get(`~${pairkey.pub}/chat-cert`);
if (typeof tempCert === "string") {
cert = tempCert;
}
}
try {
await this.firegun.Del(`~${pairkey.pub}/chat-with/${this.firegun.user.pair.pub}/${date}/${chatID}`,true,cert)
await this.firegun.userDel(`chat-with/${pairkey.pub}/${date}/${chatID}`)
await this.firegun.Put(`~${pairkey.pub}/chat-with/${this.firegun.user.pair.pub}/${date}/unsendChat`,chatID,true,"",{opt : { cert : cert }})
resolve("OK");
} catch (error) {
reject (error);
}
}
});
}
deleteChat = (pubkey:string, chatID:string, timestamp:string) => {
const date = timestamp.split("T")[0];
this.firegun.userDel(`chat-with/${pubkey}/${date}/${chatID}`)
console.log ("DELETE", `chat-with/${pubkey}/${date}/${chatID}`);
}
groupDeleteChat = (groupID:string, chatID:string, timestamp:string) => {
const date = timestamp.split("T")[0];
this.firegun.userDel(`chat-group-with/${groupID}/${date}/${chatID}`)
console.log ("DELETE", `chat-with/${groupID}/${date}/${chatID}`);
}
/**
*
* Send Chat Message
*
* @param pairkey
* @param msg
* @returns
*/
async send(pairkey: Pubkey,msg: string,cert=""): Promise<string> {
return new Promise(async (resolve, reject) => {
if (!this.firegun.user.alias) {
reject("User Belum Login")
} else {
let msgToHim, msgToMe;
if (pairkey.epub) {
msgToHim = await this.firegun.Gun.SEA.encrypt(msg,await (this.firegun.Gun as any).SEA.secret(pairkey.epub,this.firegun.user.pair));
msgToMe = await this.firegun.Gun.SEA.encrypt(msg,this.firegun.user.pair);
} else {
msgToHim = msg
}
msgToMe = msgToMe || ""
if (cert === "") {
let tempCert = await this.firegun.Get(`~${pairkey.pub}/chat-cert`);
if (typeof tempCert === "string") {
cert = tempCert;
}
}
let datetime = common.getDate()
let timestamp = `${datetime.year}/${datetime.month}/${datetime.date}T${datetime.hour}:${datetime.minutes}:${datetime.seconds}.${datetime.miliseconds}`;
let promises = [];
// Harus await, entah kenapa. Kalau tidak await tidak bisa.
// Put to Penerima userspace/chat-with/publickey/year/month/day * 2, Pengirim dan Penerima
promises.push(
await this.firegun.Put(`~${pairkey.pub}/chat-with/${this.firegun.user.pair.pub}/${datetime.year}/${datetime.month}/${datetime.date}/${timestamp.replace(/\//g, '.')}`,{
"alias" : this.firegun.user.alias,
"id" : timestamp.replace(/\//g, '.'),
"_self" : false,
"timestamp" : timestamp,
"msg" : msgToHim,
"status" : "sent"
},true, undefined,{
opt : {
cert : cert
}
})
);
// Put to My userspace/chat-with/publickey/year/month/day * 2, Pengirim dan Penerima
promises.push(
await this.firegun.Put(`~${this.firegun.user.pair.pub}/chat-with/${`${pairkey.pub}`}/${datetime.year}/${datetime.month}/${datetime.date}/${timestamp.replace(/\//g, '.')}`,{
"alias" : this.firegun.user.alias,
"id" : timestamp.replace(/\//g, '.'),
"_self" : true,
"timestamp" : timestamp,
"msg" : msgToMe,
"status" : "sent"
})
)
promises.push(
await this.markAsRead(pairkey,cert)
)
Promise.all(promises)
.then(()=>{
resolve("OK");
})
.catch(err=>{
reject(err);
})
}
});
}
/**
*
* Send Group Chat Message
*
* @param groupowner
* @param groupname
* @param msg
* @returns
*/
async groupSend(groupowner: string,groupname: string,msg: string) : Promise<{data : Ack[],error : Ack[]}> {
return new Promise(async (resolve, reject) => {
let datetime = common.getDate()
let timestamp = `${datetime.year}/${datetime.month}/${datetime.date}T${datetime.hour}:${datetime.minutes}:${datetime.seconds}.${datetime.miliseconds}`;
await this.firegun.userPut(`chat-group-with/${groupowner}&${groupname}/${datetime.year}/${datetime.month}/${datetime.date}/${timestamp.replace(/\//g, '.')}`,{
"alias" : this.firegun.user.alias,
"id" : timestamp.replace(/\//g, '.'),
"_self" : true,
"timestamp" : timestamp,
"msg" : msg,
"status" : "sent"
})
.then(s=>{
resolve(s)
})
.catch(err=>{
reject(err)
})
});
}
/**
* --------------------
* New Group Chat
*
* @param groupname
*/
async groupNew(groupname: string, groupDesc:string, groupImage:string) : Promise<string> {
// /userspace/chat-group/groupname/cert
if (this.firegun.user.alias) {
return new Promise(async (resolve, reject) => {
let promises:any[] = [];
promises.push(this.firegun.userPut(`chat-group/${groupname}/info/name`,groupname))
promises.push(this.firegun.userPut(`chat-group/${groupname}/info/desc`,groupDesc))
promises.push(this.firegun.userPut(`chat-group/${groupname}/info/image`,groupImage))
promises.push(this.firegun.userPut(`chat-group/${groupname}/members`,JSON.stringify([{
"alias" : this.firegun.user.alias,
"pub" : this.firegun.user.pair.pub
}])));
promises.push(this.firegun.userPut(`chat-group-with/${this.firegun.user.pair.pub}&${groupname}`,{"t" : "_"}));
Promise.allSettled(promises)
.then(()=>{
resolve("OK");
})
.catch(s=>{
console.log(s);
reject(s);
})
});
} else {
return "User not Logged in"
}
}
/**
* --------------------------------
* Update Group Certificate
*
* @param groupname
*/
async groupUpdateCert(groupname : string) : Promise<{data : Ack[],error : Ack[]}> {
return new Promise(async (resolve, reject) => {
// BUG Blacklis Work Around
// await this.firegun.userPut(`chat-group/${groupname}/banlist`,{
// "t" : "_"
// })
let members:string[];
let s = await this.firegun.userGet(`chat-group/${groupname}/members`);
if (typeof s === "string") {
members = JSON.parse(s);
let cert = await (this.firegun.Gun as any).SEA.certify(members, [{ "*" : `chat-group/${groupname}/chat`,"+" : "*"}], this.firegun.user.pair,null,{
// block : `chat-group/${groupname}/banlist` //ADA BUG DARI GUN JADI BELUM BISA BLACKLIST
});
this.firegun.userPut(`chat-group/${groupname}/cert`,cert)
.then(s=>{
resolve(s);
})
.catch(err=>{
reject(err);
})
} else {
reject("Members node not found");
}
});
}
/**
* -----------------------------
* Invite new member to group
*
* @param groupname
* @param pairkey
*/
async groupInvite(groupowner:string, groupname: string, pubkey: string, alias : string) {
// Verifikasi apakah user yang mengakses adalah pemilik group atau masuk ke dalam list admin
let currentUser = this.firegun.user.pair.pub;
let valid = false;
if (currentUser === groupowner) {
// user yg login adalah pemilik group
valid = true
} else {
// bukan pemilik, cek apakah termasuk ke dalam admin
let admins = await this.groupGetAdmin(groupowner,groupname);
if (admins.some(e => e.pub === currentUser)) {
valid = true
}
}
if (this.firegun.user.alias && valid) {
let members = await this.groupGetMembers(groupowner,groupname);
members.push({
"alias" : alias,
"pub" : pubkey,
})
let res;
if (currentUser === groupowner) {
res = await this.firegun.userPut(`chat-group/${groupname}/members`,JSON.stringify(members));
} else {
let cert:string;
try {
cert = await this.firegun.Get(`~${groupowner}/chat-group/${groupname}/adminCert`) as string;
res = await this.firegun.Put(`~${groupowner}/chat-group/${groupname}/members`,JSON.stringify(members),false,"",{opt : { cert : cert}});
} catch (error) {
res = {}
}
}
return (res);
} else {
return "User have no right"
}
}
/**
* -------------------------
* Set group Info
*
* @param groupname
* @param info
*/
async groupSetInfo(groupowner:string, groupname: string, groupDesc:string, groupImage:string) : Promise<string> {
// Verifikasi apakah user yang mengakses adalah pemilik group atau masuk ke dalam list admin
let currentUser = this.firegun.user.pair.pub;
let valid = false;
if (currentUser === groupowner) {
// user yg login adalah pemilik group
valid = true
} else {
// bukan pemilik, cek apakah termasuk ke dalam admin
let admins = await this.groupGetAdmin(groupowner,groupname);
if (admins.some(e => e.pub === currentUser)) {
valid = true
}
}
if (this.firegun.user.alias && valid) {
return new Promise(async (resolve, reject) => {
let promises:any[] = [];
if (currentUser === groupowner) {
promises.push(this.firegun.Put(`~${groupowner}/chat-group/${groupname}/info/name`,groupname))
promises.push(this.firegun.Put(`~${groupowner}/chat-group/${groupname}/info/desc`,groupDesc))
promises.push(this.firegun.Put(`~${groupowner}/chat-group/${groupname}/info/image`,groupImage))
} else {
let cert:string;
try {
cert = await this.firegun.Get(`~${groupowner}/chat-group/${groupname}/adminCert`) as string;
} catch (error) {
cert = ""
}
if (cert) {
promises.push(this.firegun.Put(`~${groupowner}/chat-group/${groupname}/info/name`,groupname,false,"",{ opt : { cert : cert} }))
promises.push(this.firegun.Put(`~${groupowner}/chat-group/${groupname}/info/desc`,groupDesc,false,"",{ opt : { cert : cert} }))
promises.push(this.firegun.Put(`~${groupowner}/chat-group/${groupname}/info/image`,groupImage,false,"",{ opt : { cert : cert} }))
}
}
promises.push(this.firegun.userPut(`~${groupowner}/chat-group-with/${this.firegun.user.pair.pub}&${groupname}`,{"t" : "_"}));
Promise.allSettled(promises)
.then(()=>{
resolve("OK");
})
.catch(s=>{
console.log(s);
reject(s);
})
});
} else {
return "User not Logged in"
}
}
/**
* Group Get Info
*
* @param groupname
* @returns
*/
async groupGetInfo(groupowner:string, groupname : string) {
let data: {
desc : string,
name : string,
image : string,
};
try {
data = (await this.firegun.Get(`~${groupowner}/chat-group/${groupname}/info`) as any);
} catch (error) {
data = {
desc : "",
name : "",
image : "",
}
}
return (data)
}
async groupBan(groupname:string, pubkey:string) {
let data = await this.firegun.userGet(`chat-group/${groupname}/members`);
if (typeof data === "string") {
let members:{alias:string,pub:string}[] = JSON.parse(data);
members = members.filter(s=>s.pub !== pubkey);
let res = await this.firegun.userPut(`chat-group/${groupname}/members`,JSON.stringify(members));
return (res);
} else {
return {}
}
}
async groupGetAdmin(groupOwner:string, groupName:string) : Promise<{alias:string, pub:string}[]> {
var data;
try {
let s = await this.firegun.Get(`~${groupOwner}/chat-group/${groupName}/admins`);
if (typeof s === "string") {
data = s
} else {
data = JSON.stringify([]);
}
} catch (error) {
data = JSON.stringify([]);
}
if (typeof data === "string") {
let members = JSON.parse(data);
return members
} else {
return []
}
}
async groupGetMembers(groupOwner:string, groupName:string) : Promise<{alias:string, pub:string}[]> {
var data;
try {
let s = await this.firegun.Get(`~${groupOwner}/chat-group/${groupName}/members`);
if (typeof s === "string") {
data = s
} else {
data = JSON.stringify([]);
}
} catch (error) {
data = JSON.stringify([]);
}
if (typeof data === "string") {
let members = JSON.parse(data);
return members
} else {
return []
}
}
async groupInviteAdmin(groupname: string, pubkey: string, alias : string) {
var data:string;
try {
let s = await this.firegun.userGet(`chat-group/${groupname}/admins`);
if (typeof s === "string") {
data = s;
} else {
data = JSON.stringify([]);
}
} catch (error) {
data = JSON.stringify([]);
}
let members = JSON.parse(data);
members.push({
"alias" : alias,
"pub" : pubkey,
})
// Cek lagi untuk add multi user pubkey, instead of *. Terakhir kali coba gagal.
let cert = await (this.firegun.Gun as any)
.SEA.certify("*", [
{ "*" : `chat-group`}
], this.firegun.user.pair,null,{
// block : `chat-group/${groupname}/banlist` //ADA BUG DARI GUN JADI BELUM BISA BLACKLIST
});
let res = await this.firegun.userPut(`chat-group/${groupname}/admins`,JSON.stringify(members));
await this.firegun.userPut(`chat-group/${groupname}/adminCert`,cert);
return (res);
}
async groupBanAdmin(groupname:string, pubkey:string) {
let data = await this.firegun.userGet(`chat-group/${groupname}/admins`);
if (typeof data === "string") {
let members:{alias:string,pub:string}[] = JSON.parse(data);
members = members.filter(s=>s.pub !== pubkey);
let res = await this.firegun.userPut(`chat-group/${groupname}/admins`,JSON.stringify(members));
return (res);
} else {
return {}
}
}
}