Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 97ebcff

Browse files
Merge pull request #1289 from ssbc/show-lastactivity
Show last feed activity in profile
2 parents 36427be + 6e9feb6 commit 97ebcff

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

lib/depject/message/html/timestamp.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ exports.needs = nest({
1111
exports.create = function (api) {
1212
return nest('message.html.timestamp', timestamp)
1313

14-
function timestamp (msg) {
15-
return h('a.Timestamp', {
16-
href: api.message.sync.root(msg) || msg.key,
17-
anchor: msg.key,
18-
title: moment(api.message.sync.timestamp(msg)).format('LLLL zz')
19-
}, moment(api.message.sync.timestamp(msg)).fromNow())
14+
function timestamp (msg, link = true) {
15+
if (link) {
16+
return h('a.Timestamp', {
17+
href: api.message.sync.root(msg) || msg.key,
18+
anchor: msg.key,
19+
title: moment(api.message.sync.timestamp(msg)).format('LLLL zz')
20+
}, moment(api.message.sync.timestamp(msg)).fromNow())
21+
} else {
22+
return moment(api.message.sync.timestamp(msg)).fromNow()
23+
}
2024
}
2125
}

lib/depject/page/html/render/profile.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const nest = require('depnest')
22
const ref = require('ssb-ref')
3-
const { h, when, computed, map, send, dictToCollection, resolve, onceTrue } = require('mutant')
3+
const { h, when, computed, map, send, dictToCollection, resolve, onceTrue, Value } = require('mutant')
44

55
exports.needs = nest({
66
'about.obs': {
@@ -14,12 +14,14 @@ exports.needs = nest({
1414
'blob.html.input': 'first',
1515
'message.async.publish': 'first',
1616
'message.html.markdown': 'first',
17+
'message.html.timestamp': 'first',
1718
'message.sync.root': 'first',
1819
'about.html.image': 'first',
1920
'feed.html.rollup': 'first',
2021
'sbot.pull.resumeStream': 'first',
2122
'sbot.pull.stream': 'first',
2223
'sbot.async.publish': 'first',
24+
'sbot.async.getLatest': 'first',
2325
'sbot.obs.connection': 'first',
2426
'keys.sync.id': 'first',
2527
'sheet.display': 'first',
@@ -45,6 +47,16 @@ exports.create = function (api) {
4547
const contact = api.profile.obs.contact(id)
4648
const recent = api.profile.obs.recentlyUpdated()
4749
const isYou = id === yourId
50+
const lastActivity = Value()
51+
api.sbot.async.getLatest(id, (err, val) => {
52+
if (err) {
53+
console.dir(err)
54+
} else {
55+
if (val) {
56+
lastActivity.set(val)
57+
}
58+
}
59+
})
4860

4961
onceTrue(api.sbot.obs.connection, sbot => {
5062
// request a once off replicate of this feed
@@ -142,7 +154,11 @@ exports.create = function (api) {
142154
])
143155

144156
const prepend = h('header', { className: 'ProfileHeader' }, [
145-
h('div.image', api.about.html.image(id)),
157+
h('div.image', [
158+
api.about.html.image(id),
159+
h('div.lastActivity',
160+
computed(lastActivity,
161+
msg => `${i18n('Last activity')}: ${api.message.html.timestamp(msg, false)}`))]),
146162
h('div.main', [
147163
h('div.title', [
148164
h('h1', [name]),

lib/depject/sbot.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ exports.gives = {
2525
},
2626
async: {
2727
get: true,
28+
getLatest: true,
2829
publish: true,
2930
addBlob: true,
3031
connConnect: true,
@@ -142,6 +143,15 @@ exports.create = function (api) {
142143
})
143144
}
144145
}),
146+
getLatest: rec.async(function (id, cb) {
147+
if (typeof cb !== 'function') {
148+
throw new Error('cb must be function')
149+
}
150+
sbot.getLatest(id, function (err, value) {
151+
if (err) return cb(err)
152+
cb(null, value)
153+
})
154+
}),
145155
publish: rec.async((content, cb) => {
146156
const indexes = api.progress.obs.indexes()
147157
const progress = indexes()

0 commit comments

Comments
 (0)