|
|
|
@ -7,7 +7,8 @@ const { URL, URLSearchParams } = require('url');
|
|
|
|
|
// Can't be less than 1200 if we have unauth'd requests
|
|
|
|
|
const PUBLICCHAT_MSG_POLL_EVERY = 1.5 * 1000; // 1.5s
|
|
|
|
|
const PUBLICCHAT_CHAN_POLL_EVERY = 20 * 1000; // 20s
|
|
|
|
|
const PUBLICCHAT_DELETION_POLL_EVERY = 5 * 1000; // 1 second
|
|
|
|
|
const PUBLICCHAT_DELETION_POLL_EVERY = 5 * 1000; // 5s
|
|
|
|
|
const PUBLICCHAT_MOD_POLL_EVERY = 5 * 1000; // 1 second
|
|
|
|
|
|
|
|
|
|
// singleton to relay events to libtextsecure/message_receiver
|
|
|
|
|
class LokiPublicChatAPI extends EventEmitter {
|
|
|
|
@ -219,7 +220,7 @@ class LokiPublicChannelAPI {
|
|
|
|
|
this.pollForMessages();
|
|
|
|
|
this.pollForDeletions();
|
|
|
|
|
this.pollForChannel();
|
|
|
|
|
this.refreshModStatus();
|
|
|
|
|
this.pollForModerators();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
@ -306,17 +307,34 @@ class LokiPublicChannelAPI {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get moderation actions
|
|
|
|
|
async pollForModerators() {
|
|
|
|
|
try {
|
|
|
|
|
await this.pollOnceForModerators();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log.warn(`Error while polling for public chat moderators: ${e}`);
|
|
|
|
|
}
|
|
|
|
|
if (this.running) {
|
|
|
|
|
this.timers.channel = setTimeout(() => {
|
|
|
|
|
this.pollForModerators();
|
|
|
|
|
}, PUBLICCHAT_MOD_POLL_EVERY);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get moderator status
|
|
|
|
|
async refreshModStatus() {
|
|
|
|
|
async pollOnceForModerators() {
|
|
|
|
|
// get moderator status
|
|
|
|
|
const res = await this.serverRequest('loki/v1/user_info');
|
|
|
|
|
const res = await this.serverRequest(`loki/v1/channel/${this.channelId}/get_moderators`);
|
|
|
|
|
const ourNumber = textsecure.storage.user.getNumber();
|
|
|
|
|
// if no problems and we have data
|
|
|
|
|
if (!res.err && res.response && res.response.data) {
|
|
|
|
|
this.modStatus = res.response.data.moderator_status;
|
|
|
|
|
let moderators;
|
|
|
|
|
if (!res.err && res.response && res.response.moderators) {
|
|
|
|
|
moderators = res.response.moderators;
|
|
|
|
|
this.modStatus = moderators.includes(ourNumber);
|
|
|
|
|
}
|
|
|
|
|
// if problems, we won't drop moderator status
|
|
|
|
|
|
|
|
|
|
await this.conversation.setModStatus(this.modStatus);
|
|
|
|
|
await this.conversation.setModerators(moderators);
|
|
|
|
|
|
|
|
|
|
// get token info
|
|
|
|
|
const tokenRes = await this.serverRequest('token');
|
|
|
|
@ -328,7 +346,6 @@ class LokiPublicChannelAPI {
|
|
|
|
|
tokenRes.response.data.user
|
|
|
|
|
) {
|
|
|
|
|
// get our profile name and write it to the network
|
|
|
|
|
const ourNumber = textsecure.storage.user.getNumber();
|
|
|
|
|
const profileConvo = ConversationController.get(ourNumber);
|
|
|
|
|
const profileName = profileConvo.getProfileName();
|
|
|
|
|
|
|
|
|
@ -386,11 +403,11 @@ class LokiPublicChannelAPI {
|
|
|
|
|
try {
|
|
|
|
|
await this.pollForChannelOnce();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log.warn(`Error while polling for public chat deletions: ${e}`);
|
|
|
|
|
log.warn(`Error while polling for public chat room details: ${e}`);
|
|
|
|
|
}
|
|
|
|
|
if (this.running) {
|
|
|
|
|
this.timers.channel = setTimeout(() => {
|
|
|
|
|
this.pollForChannelOnce();
|
|
|
|
|
this.pollForChannel();
|
|
|
|
|
}, PUBLICCHAT_CHAN_POLL_EVERY);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|