Fix dashboard vue

Signed-off-by: Louis Chemineau <louis@chmn.me>
pull/1719/head
Louis Chemineau 2023-04-06 17:41:25 +02:00
rodzic 82c8a6c91e
commit 764bfcc309
6 zmienionych plików z 70 dodań i 70 usunięć

Wyświetl plik

@ -60,7 +60,7 @@ class Application extends App implements IBootstrap {
$context->registerSearchProvider(UnifiedSearchProvider::class); $context->registerSearchProvider(UnifiedSearchProvider::class);
$context->registerWellKnownHandler(WebfingerHandler::class); $context->registerWellKnownHandler(WebfingerHandler::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, ProfileSectionListener::class); $context->registerEventListener(BeforeTemplateRenderedEvent::class, ProfileSectionListener::class);
// $context->registerDashboardWidget(SocialWidget::class); $context->registerDashboardWidget(SocialWidget::class);
} }
public function boot(IBootContext $context): void { public function boot(IBootContext $context): void {

Wyświetl plik

@ -34,11 +34,12 @@
</template> </template>
<script> <script>
import Bell from 'vue-material-design-icons/Bell.vue'
import { translate } from '@nextcloud/l10n'
import TimelinePost from './TimelinePost.vue' import TimelinePost from './TimelinePost.vue'
import TimelineAvatar from './TimelineAvatar.vue' import TimelineAvatar from './TimelineAvatar.vue'
import UserEntry from './UserEntry.vue' import UserEntry from './UserEntry.vue'
import Bell from 'vue-material-design-icons/Bell.vue' import { notificationSummary } from '../services/notifications.js'
import { translate } from '@nextcloud/l10n'
export default { export default {
name: 'TimelineEntry', name: 'TimelineEntry',
@ -102,30 +103,7 @@ export default {
* @return {string} * @return {string}
*/ */
actionSummary() { actionSummary() {
switch (this.notification.type) { return notificationSummary(this.notification)
case 'mention':
return t('social', '{account} mentioned you', { account: this.notification.account.acct })
case 'status':
return t('social', '{account} posted a status', { account: this.notification.account.acct })
case 'reblog':
return t('social', '{account} boosted your post', { account: this.notification.account.acct })
case 'follow':
return t('social', '{account} started to follow you', { account: this.notification.account.acct })
case 'follow_request':
return t('social', '{account} requested to follow you', { account: this.notification.account.acct })
case 'favourite':
return t('social', '{account} liked your post', { account: this.notification.account.acct })
case 'poll':
return t('social', '{account} ended the poll', { account: this.notification.account.acct })
case 'update':
return t('social', '{account} edited a status', { account: this.notification.account.acct })
case 'admin.sign_up':
return t('social', '{account} signed up', { account: this.notification.account.acct })
case 'admin.report':
return t('social', '{account} filed a report', { account: this.notification.account.acct })
default:
return ''
}
}, },
}, },
methods: { methods: {

Wyświetl plik

@ -208,10 +208,10 @@ export default {
getSinglePostTimeline(e) { getSinglePostTimeline(e) {
// Display internal or external post // Display internal or external post
if (!this.isLocal) { if (!this.isLocal) {
// TODO - fix
if (this.type === 'Note') { if (this.type === 'Note') {
window.open(this.item.id) window.open(this.item.id)
} else if (this.type === 'Announce') { } else if (this.type === 'Announce') {
// TODO
window.open(this.item.object) window.open(this.item.object)
} else { } else {
logger.warn("Don't know what to do with posts of type " + this.type, { post: this.item }) logger.warn("Don't know what to do with posts of type " + this.type, { post: this.item })

Wyświetl plik

@ -26,8 +26,11 @@ Vue.prototype.OC = window.OC
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
OCA.Dashboard.register('social_notifications', (el, { widget }) => { OCA.Dashboard.register('social_notifications', (el, { widget }) => {
const View = Vue.extend(Dashboard) const View = Vue.extend(Dashboard)
/* eslint-disable-next-line no-new */
new View({ new View({
propsData: { title: widget.title }, propsData: { title: widget.title },
}).$mount(el) el,
name: 'SocialDashboard',
})
}) })
}) })

Wyświetl plik

@ -0,0 +1,32 @@
import { translate } from '@nextcloud/l10n'
/**
* @param {import("../types/Mastodon").Notification} notification
* @return {string}
*/
export function notificationSummary(notification) {
switch (notification.type) {
case 'mention':
return translate('social', '{account} mentioned you', { account: notification.account.acct })
case 'status':
return translate('social', '{account} posted a status', { account: notification.account.acct })
case 'reblog':
return translate('social', '{account} boosted your post', { account: notification.account.acct })
case 'follow':
return translate('social', '{account} started to follow you', { account: notification.account.acct })
case 'follow_request':
return translate('social', '{account} requested to follow you', { account: notification.account.acct })
case 'favourite':
return translate('social', '{account} liked your post', { account: notification.account.acct })
case 'poll':
return translate('social', '{account} ended the poll', { account: notification.account.acct })
case 'update':
return translate('social', '{account} edited a status', { account: notification.account.acct })
case 'admin.sign_up':
return translate('social', '{account} signed up', { account: notification.account.acct })
case 'admin.report':
return translate('social', '{account} filed a report', { account: notification.account.acct })
default:
return ''
}
}

Wyświetl plik

@ -47,6 +47,7 @@ import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs' import { showError } from '@nextcloud/dialogs'
import NcDashboardWidget from '@nextcloud/vue/dist/Components/NcDashboardWidget.js' import NcDashboardWidget from '@nextcloud/vue/dist/Components/NcDashboardWidget.js'
import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js' import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
import { notificationSummary } from '../services/notifications.js'
export default { export default {
name: 'Dashboard', name: 'Dashboard',
@ -121,25 +122,19 @@ export default {
}, },
methods: { methods: {
fetchNotifications() { async fetchNotifications() {
const req = { const url = generateUrl('apps/social/api/v1/notifications')
params: {
limit: 10, try {
},
} const response = await axios.get(url)
const url = generateUrl('/apps/social/api/v1/stream/notifications') if (response.data) {
// TODO check why 'since' param is in fact 'until' this.processNotifications(response.data)
/* if (this.lastDate) {
req.params.since = this.lastTimestamp,
} */
axios.get(url, req).then((response) => {
if (response.data?.result) {
this.processNotifications(response.data.result)
this.state = 'ok' this.state = 'ok'
} else { } else {
this.state = 'error' this.state = 'error'
} }
}).catch((error) => { } catch (error) {
clearInterval(this.loop) clearInterval(this.loop)
if (error.response?.status && error.response.status >= 400) { if (error.response?.status && error.response.status >= 400) {
showError(t('social', 'Failed to get Social notifications')) showError(t('social', 'Failed to get Social notifications'))
@ -148,8 +143,9 @@ export default {
// there was an error in notif processing // there was an error in notif processing
console.error(error) console.error(error)
} }
}) }
}, },
/** @param {import('../types/Mastodon.js').Notification[]} newNotifications */
processNotifications(newNotifications) { processNotifications(newNotifications) {
if (this.lastTimestamp !== 0) { if (this.lastTimestamp !== 0) {
// just add those which are more recent than our most recent one // just add those which are more recent than our most recent one
@ -166,55 +162,46 @@ export default {
this.notifications = this.filter(newNotifications) this.notifications = this.filter(newNotifications)
} }
}, },
/** @param {import('../types/Mastodon.js').Notification[]} notifications */
filter(notifications) { filter(notifications) {
return notifications return notifications
// TODO check if we need to filter
/* return notifications.filter((n) => {
return (n.type === 'something' || n.subtype === 'somethingElse')
}) */
}, },
/** @param {import('../types/Mastodon.js').Notification} n */
getMainText(n) { getMainText(n) {
if (n.subtype === 'Follow') { return notificationSummary(n)
return t('social', '{account} is following you', { account: this.getActorName(n) })
}
if (n.subtype === 'Like') {
return t('social', '{account} liked your post', { account: this.getActorName(n) })
}
}, },
/** @param {import('../types/Mastodon.js').Notification} n */
getAvatarUrl(n) { getAvatarUrl(n) {
return undefined return n.account.avatar
// TODO get external and internal avatars
/* return this.getActorAccountName(n)
? generateUrl('???')
: undefined */
}, },
/** @param {import('../types/Mastodon.js').Notification} n */
getActorName(n) { getActorName(n) {
return n.actor_info && n.actor_info.type === 'Person' && n.actor_info.preferredUsername return n.account.display_name
? n.actor_info.preferredUsername
: ''
}, },
/** @param {import('../types/Mastodon.js').Notification} n */
getActorAccountName(n) { getActorAccountName(n) {
return n.actor_info && n.actor_info.type === 'Person' && n.actor_info.account return n.account.acct
? n.actor_info.account
: ''
}, },
/** @param {import('../types/Mastodon.js').Notification} n */
getNotificationTarget(n) { getNotificationTarget(n) {
if (n.subtype === 'Follow') { if (n.type === 'follow') {
return generateUrl('/apps/social/@' + this.getActorAccountName(n) + '/') return generateUrl('/apps/social/@' + this.getActorAccountName(n) + '/')
} }
return this.showMoreUrl return this.showMoreUrl
}, },
/** @param {import('../types/Mastodon.js').Notification} n */
getSubline(n) { getSubline(n) {
if (n.subtype === 'Follow') { if (n.type === 'follow') {
return this.getActorAccountName(n) return this.getActorAccountName(n)
} }
if (n.subtype === 'Like') { if (n.type === 'favourite') {
return this.getActorAccountName(n) return this.getActorAccountName(n)
} }
return '' return ''
}, },
/** @param {import('../types/Mastodon.js').Notification} n */
getNotificationTypeImage(n) { getNotificationTypeImage(n) {
if (n.subtype === 'Follow') { if (n.type === 'follow') {
return generateUrl('/svg/social/add_user') return generateUrl('/svg/social/add_user')
} }
return '' return ''