2021-08-07 15:23:13 +00:00
|
|
|
//
|
|
|
|
// Copyright © 2020 Anticrm Platform Contributors.
|
2022-01-19 09:04:30 +00:00
|
|
|
//
|
2021-08-07 15:23:13 +00:00
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
2022-01-19 09:04:30 +00:00
|
|
|
//
|
2021-08-07 15:23:13 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
2022-01-19 09:04:30 +00:00
|
|
|
//
|
2021-08-07 15:23:13 +00:00
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
2022-04-14 08:53:33 +00:00
|
|
|
import core from '@anticrm/core'
|
|
|
|
import chunter, { Channel, ChunterMessage, Message, ThreadMessage } from '@anticrm/chunter'
|
2022-04-05 08:01:03 +00:00
|
|
|
import { NotificationClientImpl } from '@anticrm/notification-resources'
|
2022-03-22 09:10:10 +00:00
|
|
|
import { Resources } from '@anticrm/platform'
|
2022-04-18 05:56:25 +00:00
|
|
|
import { getClient, MessageBox } from '@anticrm/presentation'
|
|
|
|
import { getCurrentLocation, navigate, showPopup } from '@anticrm/ui'
|
2022-01-19 09:04:30 +00:00
|
|
|
import TxBacklinkCreate from './components/activity/TxBacklinkCreate.svelte'
|
|
|
|
import TxBacklinkReference from './components/activity/TxBacklinkReference.svelte'
|
|
|
|
import TxCommentCreate from './components/activity/TxCommentCreate.svelte'
|
|
|
|
import ChannelPresenter from './components/ChannelPresenter.svelte'
|
2021-08-07 15:23:13 +00:00
|
|
|
import ChannelView from './components/ChannelView.svelte'
|
2022-04-12 05:59:38 +00:00
|
|
|
import ChannelHeader from './components/ChannelHeader.svelte'
|
2022-01-19 09:04:30 +00:00
|
|
|
import CommentInput from './components/CommentInput.svelte'
|
2021-11-25 11:46:51 +00:00
|
|
|
import CommentPresenter from './components/CommentPresenter.svelte'
|
|
|
|
import CommentsPresenter from './components/CommentsPresenter.svelte'
|
2022-01-19 09:04:30 +00:00
|
|
|
import CreateChannel from './components/CreateChannel.svelte'
|
2022-04-12 05:59:38 +00:00
|
|
|
import EditChannel from './components/EditChannel.svelte'
|
2022-04-02 04:08:37 +00:00
|
|
|
import ThreadView from './components/ThreadView.svelte'
|
2022-04-14 16:55:56 +00:00
|
|
|
import Threads from './components/Threads.svelte'
|
2021-08-07 15:23:13 +00:00
|
|
|
|
2022-02-11 09:18:55 +00:00
|
|
|
export { CommentsPresenter }
|
2021-09-27 17:24:15 +00:00
|
|
|
|
2022-04-05 08:01:03 +00:00
|
|
|
async function MarkUnread (object: Message): Promise<void> {
|
|
|
|
const client = NotificationClientImpl.getClient()
|
|
|
|
await client.updateLastView(object.space, chunter.class.Channel, object.createOn - 1, true)
|
|
|
|
}
|
|
|
|
|
2022-04-06 06:16:01 +00:00
|
|
|
async function MarkCommentUnread (object: ThreadMessage): Promise<void> {
|
2022-04-05 08:01:03 +00:00
|
|
|
const client = NotificationClientImpl.getClient()
|
2022-04-14 16:55:56 +00:00
|
|
|
await client.updateLastView(object.attachedTo, object.attachedToClass, object.createOn - 1, true)
|
2022-04-05 08:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function SubscribeMessage (object: Message): Promise<void> {
|
2022-04-14 16:55:56 +00:00
|
|
|
const client = getClient()
|
|
|
|
const notificationClient = NotificationClientImpl.getClient()
|
|
|
|
if (client.getHierarchy().isDerived(object._class, chunter.class.ThreadMessage)) {
|
|
|
|
await notificationClient.updateLastView(object.attachedTo, object.attachedToClass, undefined, true)
|
|
|
|
} else {
|
|
|
|
await notificationClient.updateLastView(object._id, object._class, undefined, true)
|
|
|
|
}
|
2022-04-05 08:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function UnsubscribeMessage (object: Message): Promise<void> {
|
2022-04-14 16:55:56 +00:00
|
|
|
const client = getClient()
|
|
|
|
const notificationClient = NotificationClientImpl.getClient()
|
|
|
|
if (client.getHierarchy().isDerived(object._class, chunter.class.ThreadMessage)) {
|
|
|
|
await notificationClient.unsubscribe(object.attachedTo)
|
|
|
|
} else {
|
|
|
|
await notificationClient.unsubscribe(object._id)
|
|
|
|
}
|
2022-04-05 08:01:03 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 08:53:33 +00:00
|
|
|
async function PinMessage (message: ChunterMessage): Promise<void> {
|
|
|
|
const client = getClient()
|
|
|
|
|
|
|
|
await client.updateDoc<Channel>(chunter.class.Channel, core.space.Space, message.space, {
|
|
|
|
$push: { pinned: message._id }
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function UnpinMessage (message: ChunterMessage): Promise<void> {
|
|
|
|
const client = getClient()
|
|
|
|
|
|
|
|
await client.updateDoc<Channel>(chunter.class.Channel, core.space.Space, message.space, {
|
|
|
|
$pull: { pinned: message._id }
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-18 05:56:25 +00:00
|
|
|
export async function ArchiveChannel (channel: Channel, afterArchive?: () => void): Promise<void> {
|
|
|
|
showPopup(
|
|
|
|
MessageBox,
|
|
|
|
{
|
|
|
|
label: chunter.string.ArchiveChannel,
|
|
|
|
message: chunter.string.ArchiveConfirm
|
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
(result: boolean) => {
|
|
|
|
if (result) {
|
|
|
|
const client = getClient()
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
|
|
client.update(channel, { archived: true })
|
|
|
|
if (afterArchive != null) afterArchive()
|
|
|
|
|
|
|
|
const loc = getCurrentLocation()
|
|
|
|
if (loc.path[2] === channel._id) {
|
|
|
|
loc.path.length = 2
|
|
|
|
navigate(loc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function UnarchiveChannel (channel: Channel): Promise<void> {
|
|
|
|
showPopup(
|
|
|
|
MessageBox,
|
|
|
|
{
|
|
|
|
label: chunter.string.UnarchiveChannel,
|
|
|
|
message: chunter.string.UnarchiveConfirm
|
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
(result: boolean) => {
|
|
|
|
if (result) {
|
|
|
|
const client = getClient()
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
|
|
client.update(channel, { archived: false })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2022-01-19 09:04:30 +00:00
|
|
|
export default async (): Promise<Resources> => ({
|
2021-08-07 15:23:13 +00:00
|
|
|
component: {
|
2022-02-11 09:18:55 +00:00
|
|
|
CommentInput,
|
2021-08-07 15:23:13 +00:00
|
|
|
CreateChannel,
|
2022-04-12 05:59:38 +00:00
|
|
|
ChannelHeader,
|
2021-08-18 10:57:06 +00:00
|
|
|
ChannelView,
|
2021-11-25 11:46:51 +00:00
|
|
|
CommentPresenter,
|
2022-01-19 09:04:30 +00:00
|
|
|
CommentsPresenter,
|
2022-04-02 04:08:37 +00:00
|
|
|
ChannelPresenter,
|
2022-04-12 05:59:38 +00:00
|
|
|
EditChannel,
|
2022-04-14 16:55:56 +00:00
|
|
|
Threads,
|
2022-04-02 04:08:37 +00:00
|
|
|
ThreadView
|
2021-11-18 12:48:05 +00:00
|
|
|
},
|
|
|
|
activity: {
|
2022-01-19 09:04:30 +00:00
|
|
|
TxCommentCreate,
|
|
|
|
TxBacklinkCreate,
|
|
|
|
TxBacklinkReference
|
2022-04-05 08:01:03 +00:00
|
|
|
},
|
|
|
|
actionImpl: {
|
|
|
|
MarkUnread,
|
|
|
|
MarkCommentUnread,
|
|
|
|
SubscribeMessage,
|
|
|
|
UnsubscribeMessage,
|
2022-04-14 08:53:33 +00:00
|
|
|
PinMessage,
|
2022-04-18 05:56:25 +00:00
|
|
|
UnpinMessage,
|
|
|
|
ArchiveChannel,
|
|
|
|
UnarchiveChannel
|
2021-08-07 15:23:13 +00:00
|
|
|
}
|
|
|
|
})
|