-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildMessage.ts
More file actions
128 lines (105 loc) · 3.23 KB
/
buildMessage.ts
File metadata and controls
128 lines (105 loc) · 3.23 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
122
123
124
125
126
127
128
import {MessageBuilder, MessageLauncher} from "../../api/session";
import {Media, MessageTo, PushSettings, Receiver} from "../../model/messages";
import {MessageLauncherImpl} from "./launcher";
import {SessionImpl} from "./session";
class MessageBuilderImpl implements MessageBuilder {
public message: MessageTo;
public session: SessionImpl;
constructor(session: SessionImpl, text: string, remark?: string) {
this.session = session;
this.message = {
to: {
id: null,
},
content: {
media: Media.TEXT,
body: text,
},
};
if (remark != null) {
this.message.remark = remark;
}
}
public ack(ack: number): MessageBuilder {
this.message.ack = parseInt(`${ack}`, 0);
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 this;
}
public asVideo(): MessageBuilder {
this.message.content.media = Media.VIDEO;
return this;
}
public disablePush(): MessageBuilder {
this.createPushIfNotExist().enable = false;
return this;
}
public setPushSound(sound: string): MessageBuilder {
this.createPushIfNotExist().sound = sound;
return this;
}
public setPushBadge(badge: number): MessageBuilder {
this.createPushIfNotExist().badge = badge;
return this;
}
public setPushContentAvailable(contentAvailable: boolean): MessageBuilder {
this.createPushIfNotExist().contentAvailable = contentAvailable;
return this;
}
public setPushPrefix(prefix: string): MessageBuilder {
this.createPushIfNotExist().prefix = prefix;
return this;
}
public setPushSuffix(suffix: string): MessageBuilder {
this.createPushIfNotExist().suffix = suffix;
return this;
}
public setPushTextOverwrite(text: string): MessageBuilder {
this.createPushIfNotExist().overwrite = text;
return this;
}
public toFriend(friend: string): MessageLauncher {
this.message.to.id = friend;
this.message.to.type = Receiver.ACTOR;
return new MessageLauncherImpl(this.session, this.message);
}
public toGroup(groupid: string): MessageLauncher {
this.message.to.id = groupid;
this.message.to.type = Receiver.GROUP;
return new MessageLauncherImpl(this.session, this.message);
}
public toRoom(roomid: string): MessageLauncher {
this.message.to.id = roomid;
this.message.to.type = Receiver.ROOM;
return new MessageLauncherImpl(this.session, this.message);
}
public toPassenger(passengerid: string): MessageLauncher {
this.message.to.id = passengerid;
this.message.to.type = Receiver.PASSENGER;
return new MessageLauncherImpl(this.session, this.message);
}
public toStranger(strangerid: string): MessageLauncher {
this.message.to.id = strangerid;
this.message.to.type = Receiver.STRANGER;
return new MessageLauncherImpl(this.session, this.message);
}
private createPushIfNotExist(): PushSettings {
if (!this.message.push) {
this.message.push = {};
}
return this.message.push;
}
}
export {
MessageBuilderImpl,
};