Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat threads #531

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f57eb86
Had to drop node to 16 for tests to work. See https://github.com/node…
timbl Feb 21, 2023
99d93f1
tests work only node 16. starting thread stuff
timbl Feb 22, 2023
a3df52b
Ass new icon for Reply
timbl Feb 24, 2023
ef62741
Thread display is basically working
timbl Feb 28, 2023
24320e3
Make new messages on thread etc
timbl Feb 28, 2023
372f872
async
timbl Mar 2, 2023
d577e51
lint issues
bourgeoa Mar 9, 2023
78404ed
merge main
bourgeoa Mar 9, 2023
a27cf0c
update messageTools.test.ts
bourgeoa Mar 9, 2023
86be5ab
skip test : complains if you have multiple bookmark docs
bourgeoa Mar 9, 2023
029ae1f
update package-lock.json
bourgeoa Mar 9, 2023
047d5bd
working on sentiments
timbl Mar 9, 2023
8415fae
hand merged
timbl Mar 9, 2023
7fe156e
limit srollback on thread
timbl Mar 9, 2023
ca09f65
initially load thread at the right place in timeline
timbl Mar 13, 2023
ff562b6
remove jss in acl
timea-solid Mar 20, 2023
90e6fe9
remove jss in header and footer, move stlys of acl in main style.js
timea-solid Mar 20, 2023
3369248
cleaned buttons from jss
timea-solid Mar 20, 2023
ed5d859
improved styles
timea-solid Mar 20, 2023
d980bb0
working on removing jss
timea-solid Mar 26, 2023
9daf358
fixing some more styles
timea-solid Mar 27, 2023
76bcd5f
updated snapshots accordingly
timea-solid Mar 27, 2023
53b74ba
avoid bing caught in loops
timbl Apr 4, 2023
8e5e7ac
added transform and test options to jest config
SharonStrats Apr 8, 2023
068520e
fixed lint errors
SharonStrats Apr 8, 2023
f9e2277
Merge branch 'main' into chat-threads
SharonStrats Apr 8, 2023
2dcc5e4
fixed broken styles
timea-solid Apr 9, 2023
36cc321
Update src/chat/bookmarks.js
bourgeoa Apr 10, 2023
d81bf22
Merge branch 'style' into chat-threads
timea-solid Apr 11, 2023
99dd2a8
Update src/chat/infinite.js
timea-solid Apr 11, 2023
eb85c49
Update src/chat/bookmarks.js
timea-solid Apr 11, 2023
ce90c57
Update src/chat/bookmarks.js
timea-solid Apr 11, 2023
f3028bd
Update src/chat/messageTools.js
timea-solid Apr 11, 2023
95bf305
Update src/chat/chatLogic.js
timea-solid Apr 11, 2023
e1d1a02
Update src/chat/messageTools.js
timea-solid Apr 11, 2023
c79215f
Update src/chat/thread.js
timea-solid Apr 11, 2023
ac08160
timbl code
timbl Apr 12, 2023
265a274
merged with sharon debug()
timbl Apr 12, 2023
efb1491
unblock initial load
timbl Apr 14, 2023
c6bf02e
merge main
bourgeoa Apr 16, 2023
f4da6dd
return message
bourgeoa May 29, 2023
5ccea2e
typing error
bourgeoa May 29, 2023
62cefbe
comment out ignore isReplaced(message)
bourgeoa May 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ module.exports = {
'**/?(*.)+(spec|test).[tj]s?(x)' ],
setupFilesAfterEnv: [
'./test/helpers/setup.ts'
]
],
transformIgnorePatterns: ["/node_modules/(?!lit-html).+\\.js"],
testEnvironmentOptions: {
customExportConditions: ['node']
}
}
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
},
"homepage": "https://github.com/solidos/solid-ui",
"dependencies": {
"16": "^0.0.2",
"acorn": "^7.4.1",
"escape-html": "^1.0.3",
"eslint-plugin-n": "^15.6.1",
Expand Down
12 changes: 6 additions & 6 deletions src/chat/bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* @packageDocumentation
*/

/* global alert confirm */
import * as debug from '../debug'
import { icons } from '../iconBase'
import { media } from '../media/index'
Expand Down Expand Up @@ -99,7 +98,8 @@ export async function findBookmarkDocument (userContext) {
if (userContext.instances && userContext.instances.length > 0) {
userContext.bookmarkDocument = userContext.instances[0]
if (userContext.instances.length > 1) {
alert('More than one bookmark file! ' + userContext.instances)
debug.warn('More than one bookmark file! ' + userContext.instances) // @@ todo - deal with > 1
// Note should pick up community bookmarks as well
bourgeoa marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
if (userContext.publicProfile) {
Expand All @@ -111,7 +111,7 @@ export async function findBookmarkDocument (userContext) {
debug.log('Creating new bookmark file ' + newBookmarkFile)
await createIfNotExists(newBookmarkFile)
} catch (e) {
alert.error("Can't make fresh bookmark file:" + e)
debug.warn("Can't make fresh bookmark file:" + e)
return userContext
}
await registerInTypeIndex(
Expand All @@ -121,7 +121,7 @@ export async function findBookmarkDocument (userContext) {
)
userContext.bookmarkDocument = newBookmarkFile
} else {
alert('You seem to have no bookmark file and not even a profile file.')
debug.warn('You seem to have no bookmark file and not even a profile file.')
timea-solid marked this conversation as resolved.
Show resolved Hide resolved
}
}
return userContext
Expand Down Expand Up @@ -164,7 +164,7 @@ async function addBookmark (context, target) {
await updatePromise([], ins) // 20190118A
} catch (e) {
const msg = 'Making bookmark: ' + e
alert.error(msg)
debug.warn(msg)
return null
}
return bookmark
Expand All @@ -188,7 +188,7 @@ export async function toggleBookmark (userContext, target, bookmarkButton) {
debug.log('Bookmark deleted: ' + bookmarks[i])
} catch (e) {
debug.error('Cant delete bookmark:' + e)
alert('Cant delete bookmark:' + e)
debug.warn('Cant delete bookmark:' + e)
timea-solid marked this conversation as resolved.
Show resolved Hide resolved
}
}
} else {
Expand Down
75 changes: 70 additions & 5 deletions src/chat/chatLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ChatChannel {
as a replacement for an existing one.
The old one iis left, and the two are linked
*/
async updateMessage (text, oldMsg = null, deleteIt) {
async updateMessage (text, oldMsg = null, deleteIt, thread = null) {
const sts = []
const now = new Date()
const timestamp = '' + now.getTime()
Expand All @@ -52,7 +52,7 @@ export class ChatChannel {
const me = authn.currentUser() // If already logged on

if (oldMsg) { // edit message replaces old one
sts.push($rdf.st(mostRecentVersion(oldMsg), ns.dct('isReplacedBy'), message, chatDocument))
sts.push($rdf.st(await mostRecentVersion(oldMsg), ns.dct('isReplacedBy'), message, chatDocument))
if (deleteIt) {
sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument))
}
Expand All @@ -68,8 +68,14 @@ export class ChatChannel {
if (me) {
sts.push($rdf.st(message, ns.foaf('maker'), me, chatDocument))
}
if (thread) {
sts.push($rdf.st(thread, ns.sioc('has_member'), message, chatDocument))
if (!thread.doc().sameTerm(message.doc())) {
sts.push($rdf.st(thread, ns.sioc('has_member'), message, thread.doc()))
}
}
try {
await store.updater.update([], sts)
await store.updater.updateMany([], sts)
} catch (err) {
const msg = 'Error saving chat message: ' + err
debug.warn(msg)
Expand All @@ -86,21 +92,80 @@ export class ChatChannel {
async deleteMessage (message) {
return this.updateMessage('(message deleted)', message, true)
}

// Create a new thread of replies to the thread root message
// or returns one which already exists
timea-solid marked this conversation as resolved.
Show resolved Hide resolved

async createThread (threadRoot) {
const already = store.each(threadRoot, ns.sioc('has_reply'), null, threadRoot.doc())
.filter(thread => store.holds(thread, ns.rdf('type'), ns.sioc('Thread'), thread.doc()))
if (already.length > 0) return already[0]

const thread = $rdf.sym(threadRoot.uri + '-thread')
const insert = [
$rdf.st(thread, ns.rdf('type'), ns.sioc('Thread'), thread.doc()),
$rdf.st(threadRoot, ns.sioc('has_reply'), thread, thread.doc())
]
await store.updater.update([], insert)
return thread
}
} // class ChatChannel

export function originalVersion (message) {
// ////////// Utility functions

// Have to not loop forever if fed loops
export async function allVersions (message) {
const versions = [message]
const done = {}
done[message.ur] = true
let m = message
while (true) { // earlier?
const prev = store.any(null, ns.dct('isReplacedBy'), m, m.doc())
if (!prev || done[prev.uri]) break
await store.fetcher.load(prev)
versions.unshift(prev)
done[prev.uri] = true
m = prev
}
m = message
while (true) { // later?
const next = store.any(m, ns.dct('isReplacedBy'), null, m.doc())
if (!next || done[next.uri]) break
versions.push(next)
done[next.uri] = true
m = next
}
return versions
}

export async function originalVersion (message) {
let msg = message
const done = {}
// done[message.ur] = true
while (msg) {
if (done[msg.uri]) {
debug.error('originalVersion: verion loop' + message)
return message
}
done[msg.uri] = true
message = msg
await store.fetcher.load(message)
msg = store.any(null, ns.dct('isReplacedBy'), message, message.doc())
}
return message
}

export function mostRecentVersion (message) {
export async function mostRecentVersion (message) {
let msg = message
const done = {}
while (msg) {
if (done[msg.uri]) {
debug.error('mostRecentVersion: verion loop' + message)
return message
}
done[msg.uri] = true
message = msg
await store.fetcher.load(message)
msg = store.any(message, ns.dct('isReplacedBy'), null, message.doc())
}
return message
Expand Down
Loading