Skip to content

Commit 22efe2d

Browse files
committed
Seems to basically work: edit and delete messages
1 parent 49af151 commit 22efe2d

4 files changed

Lines changed: 30 additions & 51 deletions

File tree

src/chat/chatLogic.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class ChatChannel {
5555
if (oldMsg) { // edit message replaces old one
5656
sts.push($rdf.st(mostRecentVersion(oldMsg), ns.dct('isReplacedBy'), message, chatDocument))
5757
if (deleteIt) {
58-
sts.push($rdf.st(message), ns.schema('dateDeleted'), dateStamp, chatDocument)
58+
sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument))
5959
}
6060
} else { // link new message to channel
6161
sts.push($rdf.st(this.channel, ns.wf('message'), message, chatDocument))
@@ -73,7 +73,9 @@ export class ChatChannel {
7373
await store.updater.update([], sts)
7474
} catch (err) {
7575
const msg = 'Error saving chat message: ' + err
76+
debug.warn(msg)
7677
alert(msg)
78+
throw new Error(msg, err)
7779
}
7880
return message
7981
}
@@ -102,9 +104,6 @@ export function mostRecentVersion (message) {
102104
message = msg
103105
msg = store.any(message, ns.dct('isReplacedBy'), null, message.doc())
104106
}
105-
if (store.any(message, ns.schema('dateDeleted'))) {
106-
return ns.schema('dateDeleted') // message has been deleted
107-
}
108107
return message
109108
}
110109

src/chat/infinite.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ export function desktopNotification (str) {
4646
/**
4747
* Renders a chat message inside a `messageTable`
4848
*/
49-
export function insertMessageIntoTable (channelObject, messageTable, bindings, fresh, options, userContext) {
49+
export function insertMessageIntoTable (channelObject, messageTable, message, fresh, options, userContext) {
5050
const messageRow = renderMessageRow(channelObject,
51-
bindings,
51+
message,
5252
fresh,
5353
options,
5454
userContext
5555
)
56-
const message = messageRow.AJAR_subject
56+
57+
// const message = messageRow.AJAR_subject
5758
if (options.selectedMessage && options.selectedMessage.sameTerm(message)) {
5859
messageRow.style.backgroundColor = 'yellow'
5960
options.selectedElement = messageRow
@@ -140,19 +141,13 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
140141
// Called once per original message displayed
141142
function addMessage (message, messageTable) {
142143
const latest = mostRecentVersion(message)
143-
const content = store.any(latest, ns.sioc('content'))
144+
// const content = store.any(latest, ns.sioc('content'))
144145
if (isDeleted(latest) && !options.showDeletedMessages) {
145146
return // ignore deleted messaged -- @@ could also leave a placeholder
146147
}
147-
const bindings = {
148-
'?msg': message,
149-
'?creator': store.any(message, ns.foaf('maker')),
150-
'?date': store.any(message, ns.dct('created')),
151-
'?content': content // store.any(mostRecentVersion(message), ns.sioc('content'))
152-
}
153148
insertMessageIntoTable(channelObject,
154149
messageTable,
155-
bindings,
150+
message,
156151
messageTable.fresh,
157152
options,
158153
userContext

src/chat/message.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ export function creatorAndDateHorizontal (td1, creator, date, message) {
114114
/**
115115
* Renders a chat message, read-only mode
116116
*/
117-
export function renderMessageRow (channelObject, bindings, fresh, options, userContext) {
117+
export function renderMessageRow (channelObject, message, fresh, options, userContext) {
118118
const colorizeByAuthor =
119119
options.colorizeByAuthor === '1' || options.colorizeByAuthor === true
120120

121-
const creator = bindings['?creator']
122-
const message = bindings['?msg']
123-
const date = bindings['?date']
124-
const content = bindings['?content']
121+
const creator = store.any(message, ns.foaf('maker'))
122+
const date = store.any(message, ns.dct('created'))
123+
const latestVersion = mostRecentVersion(message)
124+
const content = store.any(latestVersion, ns.sioc('content'))
125125

126126
const originalMessage = originalVersion(message)
127127
const edited = !message.sameTerm(originalMessage)
@@ -260,16 +260,10 @@ export function renderMessageEditor (channelObject, messageTable, userContext, o
260260
}
261261

262262
async function sendMessage (text, fromMainField) {
263-
function sendComplete (message, text2) {
264-
const dateStamp = store.any(message, ns.dct('created'), null, message.doc())
265-
const content = $rdf.literal(text2)
266-
const bindings = {
267-
'?msg': message,
268-
'?content': content,
269-
'?date': dateStamp,
270-
'?creator': me
271-
}
272-
insertMessageIntoTable(channelObject, messageTable, bindings, false, options, userContext) // not green
263+
function sendComplete (message, _text2) {
264+
// const dateStamp = store.any(message, ns.dct('created'), null, message.doc())
265+
// const content = $rdf.literal(text2)
266+
insertMessageIntoTable(channelObject, messageTable, message, false, options, userContext) // not green
273267

274268
if (originalMessage) { // editing another message
275269
const oldRow = messageEditor.originalRow
@@ -295,7 +289,7 @@ export function renderMessageEditor (channelObject, messageTable, userContext, o
295289
// await channelObject.div.refresh() // Add new day if nec @@ add back
296290
}
297291

298-
const me = authn.currentUser() // Must be logged on or wuld have got login button
292+
// const me = authn.currentUser() // Must be logged on or wuld have got login button
299293
if (fromMainField) {
300294
field.setAttribute('style', messageBodyStyle + 'color: #bbb;') // pendingedit
301295
field.disabled = true

src/chat/messageTools.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* If you made it originally: edit, delete, attach
88
* @packageDocumentation
99
*/
10-
10+
import * as debug from '../debug'
1111
import { authn } from '../authn/index'
1212
import { icons } from '../iconBase'
1313
import { store } from '../logic'
@@ -99,7 +99,16 @@ export function messageToolbar (message, messageRow, userContext, channelObject)
9999
if (!me) {
100100
alert('You can\'t delete the message, you are not logged in.')
101101
} else if (me.sameTerm(author)) {
102-
await channelObject.deleteMessage(message)
102+
try {
103+
await channelObject.deleteMessage(message)
104+
} catch (err) {
105+
const msg = 'Error deleting messaage ' + err
106+
debug.warn(msg)
107+
alert(msg)
108+
const area = userContext.statusArea || messageRow.parentNode
109+
area.appendChild(widgets.errorMessageBlock(dom, msg))
110+
}
111+
messageRow.parentNode.removeChild(messageRow)
103112
} else {
104113
alert('You can\'t delete the message, you are not logged in as the author, ' + author)
105114
}
@@ -115,24 +124,6 @@ export function messageToolbar (message, messageRow, userContext, channelObject)
115124

116125
// alain TODO allow chat owner to fully delete message + sentiments and replacing messages
117126

118-
/* if (mostRecentVersion(message).value === ns.schema('dateDeleted').value) {
119-
// TODO only admin can do : delete completely message and replacements
120-
// find message and replacements
121-
const admin
122-
if (me && (me.uri === admin)) {
123-
const messageArray = [message]
124-
const msg = message
125-
while(msg) {
126-
message = msg
127-
messageArray.push(message)
128-
msg = store.any(message, ns.dct('isReplacedBy'))
129-
}
130-
if (alert('confirm you want to completely remove this deleted message')) {
131-
messageArray.map(msg => deleteThingThen(msg))
132-
}
133-
}
134-
return
135-
} */
136127
const div = dom.createElement('div')
137128
// is message deleted ?
138129
if (mostRecentVersion(message).value === ns.schema('dateDeleted').value) return div

0 commit comments

Comments
 (0)