Remove RSS Feeds

This commit is contained in:
Mikunj 2020-07-16 13:30:38 +10:00
parent 5ec3a5b3f7
commit 9e14615cd2
6 changed files with 29 additions and 194 deletions

View File

@ -106,7 +106,6 @@ module.exports = {
updateConversation,
removeConversation,
getAllConversations,
getAllRssFeedConversations,
getAllPublicConversations,
getPublicConversationsByServer,
getPubkeysInPublicConversation,
@ -810,6 +809,7 @@ const LOKI_SCHEMA_VERSIONS = [
updateToLokiSchemaVersion3,
updateToLokiSchemaVersion4,
updateToLokiSchemaVersion5,
updateToLokiSchemaVersion6,
];
async function updateToLokiSchemaVersion1(currentVersion, instance) {
@ -999,6 +999,34 @@ async function updateToLokiSchemaVersion5(currentVersion, instance) {
console.log('updateToLokiSchemaVersion5: success!');
}
async function updateToLokiSchemaVersion6(currentVersion, instance) {
if (currentVersion >= 6) {
return;
}
console.log('updateToLokiSchemaVersion6: starting...');
await instance.run('BEGIN TRANSACTION;');
// Remove RSS Feed conversations
await instance.run(
`DELETE FROM conversations WHERE
type = 'group' AND
id LIKE 'rss://%';`
);
await instance.run(
`INSERT INTO loki_schema (
version
) values (
6
);`
);
await instance.run('COMMIT TRANSACTION;');
console.log('updateToLokiSchemaVersion6: success!');
}
async function updateLokiSchema(instance) {
const result = await instance.get(
"SELECT name FROM sqlite_master WHERE type = 'table' AND name='loki_schema';"
@ -1905,17 +1933,6 @@ async function getAllPrivateConversations() {
return map(rows, row => jsonToObject(row.json));
}
async function getAllRssFeedConversations() {
const rows = await db.all(
`SELECT json FROM conversations WHERE
type = 'group' AND
id LIKE 'rss://%'
ORDER BY id ASC;`
);
return map(rows, row => jsonToObject(row.json));
}
async function getAllPublicConversations() {
const rows = await db.all(
`SELECT json FROM conversations WHERE

View File

@ -216,14 +216,6 @@
if (specialConvInited) {
return;
}
const rssFeedConversations = await window.Signal.Data.getAllRssFeedConversations(
{
ConversationCollection: Whisper.ConversationCollection,
}
);
rssFeedConversations.forEach(conversation => {
window.feeds.push(new window.LokiRssAPI(conversation.getRssSettings()));
});
const publicConversations = await window.Signal.Data.getAllPublicConversations(
{
ConversationCollection: Whisper.ConversationCollection,

View File

@ -124,7 +124,6 @@ module.exports = {
getAllConversations,
getAllConversationIds,
getAllPrivateConversations,
getAllRssFeedConversations,
getAllPublicConversations,
getPublicConversationsByServer,
getPubkeysInPublicConversation,
@ -811,14 +810,6 @@ async function getAllConversationIds() {
return ids;
}
async function getAllRssFeedConversations({ ConversationCollection }) {
const conversations = await channels.getAllRssFeedConversations();
const collection = new ConversationCollection();
collection.add(conversations);
return collection;
}
async function getAllPublicConversations({ ConversationCollection }) {
const conversations = await channels.getAllPublicConversations();

View File

@ -1,162 +0,0 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-loop-func */
/* global log, window, textsecure */
const EventEmitter = require('events');
const PER_MIN = 60 * 1000;
const PER_HR = 60 * PER_MIN;
const RSS_POLL_EVERY = 1 * PER_HR; // once an hour
function xml2json(xml) {
try {
let obj = {};
if (xml.children.length > 0) {
for (let i = 0; i < xml.children.length; i += 1) {
const item = xml.children.item(i);
const { nodeName } = item;
if (typeof obj[nodeName] === 'undefined') {
obj[nodeName] = xml2json(item);
} else {
if (typeof obj[nodeName].push === 'undefined') {
const old = obj[nodeName];
obj[nodeName] = [];
obj[nodeName].push(old);
}
obj[nodeName].push(xml2json(item));
}
}
} else {
obj = xml.textContent;
}
return obj;
} catch (e) {
log.error(e.message);
}
return {};
}
class LokiRssAPI extends EventEmitter {
constructor(settings) {
super();
// properties
this.feedUrl = settings.RSS_FEED;
this.groupId = settings.CONVO_ID;
this.feedTitle = settings.title;
this.closeable = settings.closeable;
// non configureable options
this.feedTimer = null;
// initial set up
this.getFeed();
}
async getFeed() {
// deal with file server proxy hardcoding
const map = {
'https://loki.network/category/messenger-updates/feed/':
'loki/v1/rss/messenger',
'https://loki.network/feed/': 'loki/v1/rss/loki',
};
if (map[this.feedUrl] === undefined) {
log.warn('LokiRssAPI unsupported rss feed', this.feedUrl);
return;
}
const result = await window.tokenlessFileServerAdnAPI.serverRequest(
map[this.feedUrl]
);
if (!result) {
log.error('LokiRssAPI empty rss proxy response');
return;
}
if (!result.response) {
log.error('LokiRssAPI rss proxy error, no response', result);
return;
}
if (!result.response.data) {
log.error(
'LokiRssAPI rss proxy error, no data, response',
typeof result.response,
result.response
);
return;
}
const responseXML = result.response.data;
let feedDOM = {};
try {
feedDOM = await new window.DOMParser().parseFromString(
responseXML,
'text/xml'
);
} catch (e) {
log.error('LokiRssAPI xml parsing error', e, responseXML);
return;
}
const feedObj = xml2json(feedDOM);
let receivedAt = new Date().getTime();
if (!feedObj || !feedObj.rss || !feedObj.rss.channel) {
log.error(
'LokiRssAPI rss structure error',
feedObj,
feedDOM,
responseXML
);
return;
}
if (!feedObj.rss.channel.item) {
// no records, not an error
return;
}
if (feedObj.rss.channel.item.constructor !== Array) {
// Treat single record as array for consistency
feedObj.rss.channel.item = [feedObj.rss.channel.item];
}
feedObj.rss.channel.item.reverse().forEach(item => {
// log.debug('item', item)
const pubDate = new Date(item.pubDate);
// if we use group style, we can put the title in the source
const messageData = {
isSessionRequest: false,
source: this.groupId,
sourceDevice: 1,
timestamp: pubDate.getTime(),
serverTimestamp: pubDate.getTime(),
receivedAt,
isRss: true,
message: {
body: `<h2>${item.title} </h2>${item.description}`,
attachments: [],
group: {
id: this.groupId,
type: textsecure.protobuf.GroupContext.Type.DELIVER,
},
flags: 0,
expireTimer: 0,
profileKey: null,
timestamp: pubDate.getTime(),
received_at: receivedAt,
sent_at: pubDate.getTime(),
quote: null,
contact: [],
preview: [],
profile: null,
},
};
receivedAt += 1; // Ensure different arrival times
this.emit('rssMessage', {
message: messageData,
});
});
const ref = this;
function callTimer() {
ref.getFeed();
}
this.feedTimer = setTimeout(callTimer, RSS_POLL_EVERY);
}
}
module.exports = LokiRssAPI;

View File

@ -355,8 +355,6 @@ window.LokiPublicChatAPI = require('./js/modules/loki_public_chat_api');
window.LokiFileServerAPI = require('./js/modules/loki_file_server_api');
window.LokiRssAPI = require('./js/modules/loki_rss_api');
window.mnemonic = require('./libloki/modules/mnemonic');
const WorkerInterface = require('./js/modules/util_worker_interface');

1
ts/window.d.ts vendored
View File

@ -25,7 +25,6 @@ declare global {
LokiAppDotNetServerAPI: any;
LokiFileServerAPI: any;
LokiPublicChatAPI: any;
LokiRssAPI: any;
LokiSnodeAPI: any;
MessageController: any;
Session: any;