-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildMessage.ts
More file actions
121 lines (101 loc) · 2.85 KB
/
buildMessage.ts
File metadata and controls
121 lines (101 loc) · 2.85 KB
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
import {Admin, MessageBuilder, MessageLauncher} from "../../api/admin";
import {Media, PushSettings, Receiver, SystemMessageTo} from "../../model/messages";
import {AdminMessageLauncherImpl} from "./launcher";
class AdminMessageBuilderImpl implements MessageBuilder {
private admin: Admin;
private receiver: {
id?: string;
type?: Receiver
};
private message: SystemMessageTo;
constructor(admin: Admin, text: string, remark?: string) {
this.admin = admin;
this.message = {
content: {
media: Media.TEXT,
body: text,
},
};
if (remark !== undefined && remark !== null) {
this.message.remark = remark;
}
}
public disablePush(): MessageBuilder {
this.touchPush().enable = false;
return this;
}
public setPushSound(sound: string): MessageBuilder {
this.touchPush().sound = sound;
return this;
}
public setPushBadge(badge: number): MessageBuilder {
this.touchPush().badge = badge;
return this;
}
public setPushContentAvailable(contentAvailable: boolean): MessageBuilder {
this.touchPush().contentAvailable = contentAvailable;
return this;
}
public setPushPrefix(prefix: string): MessageBuilder {
this.touchPush().prefix = prefix;
return this;
}
public setPushSuffix(suffix: string): MessageBuilder {
this.touchPush().suffix = suffix;
return this;
}
public setPushTextOverwrite(text: string): MessageBuilder {
this.touchPush().overwrite = text;
return this;
}
public asText(): MessageBuilder {
this.message.content.media = Media.TEXT;
return this;
}
public asImage(): MessageBuilder {
this.message.content.media = Media.IMAGE;
return this;
}
public asAudio(): MessageBuilder {
this.message.content.media = Media.AUDIO;
return undefined;
}
public asVideo(): MessageBuilder {
this.message.content.media = Media.VIDEO;
return undefined;
}
public toAll(): MessageLauncher {
this.receiver = {};
return new AdminMessageLauncherImpl(this.admin, this.message, this.receiver);
}
public toUser(userid: string): MessageLauncher {
this.receiver = {
id: userid,
type: Receiver.ACTOR,
};
return new AdminMessageLauncherImpl(this.admin, this.message, this.receiver);
}
public toGroup(groupid: string): MessageLauncher {
this.receiver = {
id: groupid,
type: Receiver.GROUP,
};
return new AdminMessageLauncherImpl(this.admin, this.message, this.receiver);
}
public toRoom(roomid: string): MessageLauncher {
this.receiver = {
id: roomid,
type: Receiver.ROOM,
};
return new AdminMessageLauncherImpl(this.admin, this.message, this.receiver);
}
private touchPush(): PushSettings {
if (!this.message.push) {
this.message.push = {};
}
return this.message.push;
}
}
export {
AdminMessageBuilderImpl,
};