Use import/export instead of require, so node is not needed in the render. Also fix an issue with previous/next in timelines.
This commit is contained in:
parent
d51dc50f11
commit
caa7891b93
|
@ -5,7 +5,10 @@
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
|
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
|
||||||
<link href="apmail.css" rel="stylesheet" type="text/css" media="all" />
|
<link href="apmail.css" rel="stylesheet" type="text/css" media="all" />
|
||||||
<script src="render.js"></script>
|
<script type="module">
|
||||||
|
import {UI} from './render.js'
|
||||||
|
window.UI = UI
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="UI.checkConnection();">
|
<body onload="UI.checkConnection();">
|
||||||
<!-- Navigation column -->
|
<!-- Navigation column -->
|
||||||
|
|
2
main.js
2
main.js
|
@ -6,8 +6,6 @@ function createWindow () {
|
||||||
width: 1024,
|
width: 1024,
|
||||||
height: 768,
|
height: 768,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: true,
|
|
||||||
contextIsolation: false
|
|
||||||
},
|
},
|
||||||
icon: __dirname + '/img/APMail.png'
|
icon: __dirname + '/img/APMail.png'
|
||||||
})
|
})
|
||||||
|
|
10
render.js
10
render.js
|
@ -1,7 +1,7 @@
|
||||||
const {Actor} = require('./src/actor.js')
|
import {Actor} from './src/actor.js'
|
||||||
const {Timeline, KnownActivities} = require('./src/timeline.js')
|
import {Timeline, KnownActivities} from './src/timeline.js'
|
||||||
const {Message} = require('./src/message.js')
|
import {Message} from './src/message.js'
|
||||||
const {ConnectedUser} = require('./src/connected-user.js')
|
import {ConnectedUser} from './src/connected-user.js'
|
||||||
|
|
||||||
// For access of elements
|
// For access of elements
|
||||||
const Elem = function(id) {
|
const Elem = function(id) {
|
||||||
|
@ -493,3 +493,5 @@ const UI = {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export {UI}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const {Actor} = require('./actor.js')
|
import {Actor} from './actor.js'
|
||||||
const {KnownActors} = require('./known-actors.js')
|
import {KnownActors} from './known-actors.js'
|
||||||
|
|
||||||
// ActivityObject class: wrapper around an Object of the ActivityStream spec
|
// ActivityObject class: wrapper around an Object of the ActivityStream spec
|
||||||
const ActivityObject = function(as_object) {
|
const ActivityObject = function(as_object) {
|
||||||
|
@ -109,4 +109,4 @@ ActivityObject.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exported structures
|
// Exported structures
|
||||||
exports.ActivityObject = ActivityObject
|
export {ActivityObject}
|
||||||
|
|
|
@ -74,8 +74,8 @@ const ASMention = function() {}
|
||||||
|
|
||||||
// Object fetcher
|
// Object fetcher
|
||||||
// Convert resources from the resource fetcher into Activity objects
|
// Convert resources from the resource fetcher into Activity objects
|
||||||
const {TokenCollection} = require('./token-collection.js')
|
import {TokenCollection} from './token-collection.js'
|
||||||
Fetcher = {
|
const Fetcher = {
|
||||||
// Cache of already accessed objects
|
// Cache of already accessed objects
|
||||||
knownObjects: {},
|
knownObjects: {},
|
||||||
// Get an object
|
// Get an object
|
||||||
|
@ -536,7 +536,7 @@ ASCollectionPage.prototype.constructor = ASCollectionPage
|
||||||
ASOrderedCollectionPage.prototype = Object.create(ASCollectionPage.prototype)
|
ASOrderedCollectionPage.prototype = Object.create(ASCollectionPage.prototype)
|
||||||
Object.assign(ASOrderedCollectionPage.prototype, ASOrderedCollection.prototype)
|
Object.assign(ASOrderedCollectionPage.prototype, ASOrderedCollection.prototype)
|
||||||
// Helping function for removing duplicates
|
// Helping function for removing duplicates
|
||||||
unique = function(arr) {
|
const unique = function(arr) {
|
||||||
return arr.filter(function (elem, idx) { return idx === arr.indexOf(elem) })
|
return arr.filter(function (elem, idx) { return idx === arr.indexOf(elem) })
|
||||||
}
|
}
|
||||||
Object.assign(ASOrderedCollectionPage.prototype,
|
Object.assign(ASOrderedCollectionPage.prototype,
|
||||||
|
@ -857,63 +857,65 @@ ASMention.prototype.constructor = ASMention
|
||||||
|
|
||||||
////
|
////
|
||||||
// Exported structures
|
// Exported structures
|
||||||
|
export {
|
||||||
// Fetcher
|
// Fetcher
|
||||||
exports.Fetcher = Fetcher
|
Fetcher,
|
||||||
// Core types
|
// Core types
|
||||||
exports.ASObject = ASObject
|
ASObject,
|
||||||
exports.ASLink = ASLink
|
ASLink,
|
||||||
exports.ASActivity = ASActivity
|
ASActivity,
|
||||||
exports.ASIntransitiveActivity = ASIntransitiveActivity
|
ASIntransitiveActivity,
|
||||||
exports.ASCollection = ASCollection
|
ASCollection,
|
||||||
exports.ASOrderedCollection = ASOrderedCollection
|
ASOrderedCollection,
|
||||||
exports.ASCollectionPage = ASCollectionPage
|
ASCollectionPage,
|
||||||
exports.ASOrderedCollectionPage = ASOrderedCollectionPage
|
ASOrderedCollectionPage,
|
||||||
exports.ASActor = ASActor
|
ASActor,
|
||||||
// Activity types
|
// Activity types
|
||||||
exports.ASAccept = ASAccept
|
ASAccept,
|
||||||
exports.ASAdd = ASAdd
|
ASAdd,
|
||||||
exports.ASAnnounce = ASAnnounce
|
ASAnnounce,
|
||||||
exports.ASArrive = ASArrive
|
ASArrive,
|
||||||
exports.ASBlock = ASBlock
|
ASBlock,
|
||||||
exports.ASCreate = ASCreate
|
ASCreate,
|
||||||
exports.ASDelete = ASDelete
|
ASDelete,
|
||||||
exports.ASDislike = ASDislike
|
ASDislike,
|
||||||
exports.ASFlag = ASFlag
|
ASFlag,
|
||||||
exports.ASFollow = ASFollow
|
ASFollow,
|
||||||
exports.ASIgnore = ASIgnore
|
ASIgnore,
|
||||||
exports.ASInvite = ASInvite
|
ASInvite,
|
||||||
exports.ASJoin = ASJoin
|
ASJoin,
|
||||||
exports.ASLeave = ASLeave
|
ASLeave,
|
||||||
exports.ASLike = ASLike
|
ASLike,
|
||||||
exports.ASListen = ASListen
|
ASListen,
|
||||||
exports.ASMove = ASMove
|
ASMove,
|
||||||
exports.ASOffer = ASOffer
|
ASOffer,
|
||||||
exports.ASQuestion = ASQuestion
|
ASQuestion,
|
||||||
exports.ASReject = ASReject
|
ASReject,
|
||||||
exports.ASRead = ASRead
|
ASRead,
|
||||||
exports.ASRemove = ASRemove
|
ASRemove,
|
||||||
exports.ASTentativeReject = ASTentativeReject
|
ASTentativeReject,
|
||||||
exports.ASTentativeAccept = ASTentativeAccept
|
ASTentativeAccept,
|
||||||
exports.ASTravel = ASTravel
|
ASTravel,
|
||||||
exports.ASUpdate = ASUpdate
|
ASUpdate,
|
||||||
exports.ASView = ASView
|
ASView,
|
||||||
// Actor types
|
// Actor types
|
||||||
exports.ASApplication = ASApplication
|
ASApplication,
|
||||||
exports.ASGroup = ASGroup
|
ASGroup,
|
||||||
exports.ASOrganization = ASOrganization
|
ASOrganization,
|
||||||
exports.ASPerson = ASPerson
|
ASPerson,
|
||||||
exports.ASService = ASService
|
ASService,
|
||||||
// Object types
|
// Object types
|
||||||
exports.ASArticle = ASArticle
|
ASArticle,
|
||||||
exports.ASAudio = ASAudio
|
ASAudio,
|
||||||
exports.ASDocument = ASDocument
|
ASDocument,
|
||||||
exports.ASImage = ASImage
|
ASImage,
|
||||||
exports.ASNote = ASNote
|
ASNote,
|
||||||
exports.ASPage = ASPage
|
ASPage,
|
||||||
exports.ASPlace = ASPlace
|
ASPlace,
|
||||||
exports.ASProfile = ASProfile
|
ASProfile,
|
||||||
exports.ASRelationship = ASRelationship
|
ASRelationship,
|
||||||
exports.ASTombstone = ASTombstone
|
ASTombstone,
|
||||||
exports.ASVideo = ASVideo
|
ASVideo,
|
||||||
// Link types
|
// Link types
|
||||||
exports.ASMention = ASMention
|
ASMention,
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const {Actor} = require('./actor.js')
|
import {Actor} from './actor.js'
|
||||||
const {KnownActors} = require('./known-actors.js')
|
import {KnownActors} from './known-actors.js'
|
||||||
const {ActivityObject} = require('./activity-object.js')
|
import {ActivityObject} from './activity-object.js'
|
||||||
|
|
||||||
// Activity class
|
// Activity class
|
||||||
const Activity = function (as_activity) {
|
const Activity = function (as_activity) {
|
||||||
|
@ -127,4 +127,4 @@ Activity.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exported structures
|
// Exported structures
|
||||||
exports.Activity = Activity
|
export {Activity}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const {Fetcher, ASActor} = require('./activity-vocabulary.js')
|
import {Fetcher, ASActor} from './activity-vocabulary.js'
|
||||||
|
|
||||||
// Actor class
|
// Actor class
|
||||||
// Add additional services around an ASActor
|
// Add additional services around an ASActor
|
||||||
|
@ -125,4 +125,4 @@ Actor.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exported structures
|
// Exported structures
|
||||||
exports.Actor = Actor
|
export {Actor}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const {TokenCollection} = require('./token-collection.js')
|
import {TokenCollection} from './token-collection.js'
|
||||||
const {Actor} = require('./actor.js')
|
import {Actor} from './actor.js'
|
||||||
|
|
||||||
// Connected user structure
|
// Connected user structure
|
||||||
const ConnectedUser = {
|
const ConnectedUser = {
|
||||||
|
@ -149,4 +149,4 @@ const ConnectedUser = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exported structures
|
// Exported structures
|
||||||
exports.ConnectedUser = ConnectedUser
|
export {ConnectedUser}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const {Actor} = require('./actor.js')
|
import {Actor} from './actor.js'
|
||||||
|
|
||||||
// A cache for actors, to avoid loading same actors several times when loading timelines
|
// A cache for actors, to avoid loading same actors several times when loading timelines
|
||||||
const KnownActors = {
|
const KnownActors = {
|
||||||
|
@ -40,4 +40,4 @@ publicActor.fromDummyData('', 'public', 'Anyone', 'https://www.w3.org/ns/activit
|
||||||
KnownActors.set(publicActor.data.id, publicActor)
|
KnownActors.set(publicActor.data.id, publicActor)
|
||||||
|
|
||||||
// Exported structures
|
// Exported structures
|
||||||
exports.KnownActors = KnownActors
|
export {KnownActors}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const {ConnectedUser} = require('./connected-user.js')
|
import {ConnectedUser} from './connected-user.js'
|
||||||
|
|
||||||
// Outgoing messages
|
// Outgoing messages
|
||||||
var Message = function() {
|
var Message = function() {
|
||||||
|
@ -96,4 +96,4 @@ Message.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exported structures
|
// Exported structures
|
||||||
exports.Message = Message
|
export {Message}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const {Fetcher} = require('./activity-vocabulary.js')
|
import {Fetcher} from './activity-vocabulary.js'
|
||||||
const {Activity} = require('./activity.js')
|
import {Activity} from './activity.js'
|
||||||
|
|
||||||
// Already fetched activities, as a map, in order to be able to fetch them by their id
|
// Already fetched activities, as a map, in order to be able to fetch them by their id
|
||||||
const KnownActivities = {
|
const KnownActivities = {
|
||||||
|
@ -35,9 +35,6 @@ Timeline.prototype = {
|
||||||
// Fetch the attribute
|
// Fetch the attribute
|
||||||
fetched_timeline.refreshAttribute('first', function (ok, error) {
|
fetched_timeline.refreshAttribute('first', function (ok, error) {
|
||||||
if (load_ok) {
|
if (load_ok) {
|
||||||
this.activities = []
|
|
||||||
this.prev = fetched_timeline.prev
|
|
||||||
this.next = fetched_timeline.next
|
|
||||||
this.parsePage(fetched_timeline.first, callback)
|
this.parsePage(fetched_timeline.first, callback)
|
||||||
} else {
|
} else {
|
||||||
callback(false, error)
|
callback(false, error)
|
||||||
|
@ -45,14 +42,8 @@ Timeline.prototype = {
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
} else if (fetched_timeline.type === 'OrderedCollection' && fetched_timeline.orderedItems) {
|
} else if (fetched_timeline.type === 'OrderedCollection' && fetched_timeline.orderedItems) {
|
||||||
// Collection is not paginated
|
// Collection is not paginated
|
||||||
this.activities = []
|
|
||||||
this.prev = fetched_timeline.prev
|
|
||||||
this.next = fetched_timeline.next
|
|
||||||
this.parsePage(fetched_timeline, callback)
|
this.parsePage(fetched_timeline, callback)
|
||||||
} else if (fetched_timeline.type === 'OrderedCollectionPage') {
|
} else if (fetched_timeline.type === 'OrderedCollectionPage') {
|
||||||
this.activities = []
|
|
||||||
this.prev = fetched_timeline.prev
|
|
||||||
this.next = fetched_timeline.next
|
|
||||||
this.parsePage(fetched_timeline, callback)
|
this.parsePage(fetched_timeline, callback)
|
||||||
} else {
|
} else {
|
||||||
callback(false, 'Unexpected answer from server when fetching activity collection.')
|
callback(false, 'Unexpected answer from server when fetching activity collection.')
|
||||||
|
@ -65,12 +56,18 @@ Timeline.prototype = {
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
},
|
},
|
||||||
parsePage: function (collectionPage, callback) {
|
parsePage: function (collectionPage, callback) {
|
||||||
|
// Set the values
|
||||||
|
this.activities = []
|
||||||
|
this.prev = collectionPage.prev
|
||||||
|
this.next = collectionPage.next
|
||||||
// Fetch attributes of collectionPage
|
// Fetch attributes of collectionPage
|
||||||
collectionPage.refreshAttribute('orderedItems', function (load_ok, failure_message) {
|
collectionPage.refreshAttribute('orderedItems', function (load_ok, failure_message) {
|
||||||
if (load_ok) {
|
if (load_ok && collectionPage.orderedItems) {
|
||||||
// Elements of the page have been fetched
|
// Elements of the page have been fetched
|
||||||
// For each, convert them to Activity and put them in this.activities
|
// For each, convert them to Activity and put them in this.activities
|
||||||
this.addActivity(collectionPage.orderedItems.values(), callback, '')
|
this.addActivity(collectionPage.orderedItems.values(), callback, '')
|
||||||
|
} else if (load_ok) {
|
||||||
|
callback(false, 'No item in activity collection.')
|
||||||
} else {
|
} else {
|
||||||
callback(false, failure_message)
|
callback(false, failure_message)
|
||||||
}
|
}
|
||||||
|
@ -99,5 +96,4 @@ Timeline.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exported structures
|
// Exported structures
|
||||||
exports.Timeline = Timeline
|
export {Timeline, KnownActivities}
|
||||||
exports.KnownActivities = KnownActivities
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// A small object for getting the token when talking to a server
|
// A small object for getting the token when talking to a server
|
||||||
TokenCollection = {
|
const TokenCollection = {
|
||||||
tokens: {},
|
tokens: {},
|
||||||
set: function (server, token) {
|
set: function (server, token) {
|
||||||
TokenCollection.tokens[server] = token
|
TokenCollection.tokens[server] = token
|
||||||
|
@ -11,4 +11,4 @@ TokenCollection = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exported structures
|
// Exported structures
|
||||||
exports.TokenCollection = TokenCollection
|
export {TokenCollection}
|
||||||
|
|
Loading…
Reference in New Issue