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

UBERF-7959: Fix async issues #6409

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 20 additions & 22 deletions plugins/chunter-resources/src/components/chat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import notification, { type DocNotifyContext } from '@hcengineering/notification'
import attachment, { type SavedAttachments } from '@hcengineering/attachment'
import { type DirectMessage } from '@hcengineering/chunter'
import contact, { type PersonAccount } from '@hcengineering/contact'
import core, {
type Account,
AccountRole,
generateId,
type Ref,
SortingOrder,
type WithLookup,
hasAccountRole,
getCurrentAccount,
AccountRole,
hasAccountRole,
type IdMap,
type Account,
type UserStatus
type Ref,
SortingOrder,
type UserStatus,
type WithLookup
} from '@hcengineering/core'
import notification, { type DocNotifyContext } from '@hcengineering/notification'
import { InboxNotificationsClientImpl } from '@hcengineering/notification-resources'
import { createQuery, getClient, MessageBox } from '@hcengineering/presentation'
import { get, writable } from 'svelte/store'
import { type Action, showPopup } from '@hcengineering/ui'
import view from '@hcengineering/view'
import workbench, { type SpecialNavModel } from '@hcengineering/workbench'
import attachment, { type SavedAttachments } from '@hcengineering/attachment'
import { InboxNotificationsClientImpl } from '@hcengineering/notification-resources'
import { type Action, showPopup } from '@hcengineering/ui'
import contact, { type PersonAccount } from '@hcengineering/contact'
import { type DirectMessage } from '@hcengineering/chunter'
import { get, writable } from 'svelte/store'

import { type ChatNavGroupModel, type ChatNavItemModel, type SortFnOptions } from './types'
import chunter from '../../plugin'
import { type ChatNavGroupModel, type ChatNavItemModel, type SortFnOptions } from './types'

const navigatorStateStorageKey = 'chunter.navigatorState'

Expand Down Expand Up @@ -356,14 +356,12 @@ function archiveActivityChannels (contexts: DocNotifyContext[]): void {
MessageBox,
{
label: chunter.string.ArchiveActivityConfirmationTitle,
message: chunter.string.ArchiveActivityConfirmationMessage
},
'top',
(result?: boolean) => {
if (result === true) {
void removeActivityChannels(contexts)
message: chunter.string.ArchiveActivityConfirmationMessage,
action: async () => {
await removeActivityChannels(contexts)
}
}
},
'top'
)
}

Expand Down
130 changes: 58 additions & 72 deletions plugins/chunter-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,115 +13,101 @@
// limitations under the License.
//

import { writable } from 'svelte/store'
import { type ActivityMessage } from '@hcengineering/activity'
import chunter, { type Channel, type ChatMessage, type DirectMessage } from '@hcengineering/chunter'
import { type Resources } from '@hcengineering/platform'
import { MessageBox, getClient } from '@hcengineering/presentation'
import { getLocation, navigate, showPopup } from '@hcengineering/ui'
import { type ActivityMessage } from '@hcengineering/activity'
import { writable } from 'svelte/store'

import ChannelPresenter from './components/ChannelPresenter.svelte'
import ChannelCreatedMessage from './components/activity/ChannelCreatedMessage.svelte'
import MembersChangedMessage from './components/activity/MembersChangedMessage.svelte'
import ChannelHeader from './components/ChannelHeader.svelte'
import ChannelIcon from './components/ChannelIcon.svelte'
import ChannelPanel from './components/ChannelPanel.svelte'
import ChunterBrowser from './components/chat/specials/ChunterBrowser.svelte'
import ConvertDmToPrivateChannelModal from './components/ConvertDmToPrivateChannel.svelte'
import CreateChannel from './components/chat/create/CreateChannel.svelte'
import CreateDirectChat from './components/chat/create/CreateDirectChat.svelte'
import DmHeader from './components/DmHeader.svelte'
import DmPresenter from './components/DmPresenter.svelte'
import EditChannel from './components/EditChannel.svelte'
import ChannelPresenter from './components/ChannelPresenter.svelte'
import ChannelPreview from './components/ChannelPreview.svelte'
import ThreadView from './components/threads/ThreadView.svelte'
import ThreadViewPanel from './components/threads/ThreadViewPanel.svelte'
import ChatMessagePresenter from './components/chat-message/ChatMessagePresenter.svelte'
import ChatMessageInput from './components/chat-message/ChatMessageInput.svelte'
import ChatMessagePresenter from './components/chat-message/ChatMessagePresenter.svelte'
import ChatMessagePreview from './components/chat-message/ChatMessagePreview.svelte'
import ChatMessagesPresenter from './components/chat-message/ChatMessagesPresenter.svelte'
import Chat from './components/chat/Chat.svelte'
import ThreadMessagePresenter from './components/threads/ThreadMessagePresenter.svelte'
import ThreadParentPresenter from './components/threads/ThreadParentPresenter.svelte'
import ChannelHeader from './components/ChannelHeader.svelte'
import ChatAside from './components/chat/ChatAside.svelte'
import CreateChannel from './components/chat/create/CreateChannel.svelte'
import CreateDirectChat from './components/chat/create/CreateDirectChat.svelte'
import ChunterBrowser from './components/chat/specials/ChunterBrowser.svelte'
import SavedMessages from './components/chat/specials/SavedMessages.svelte'
import Threads from './components/threads/Threads.svelte'
import ConvertDmToPrivateChannelModal from './components/ConvertDmToPrivateChannel.svelte'
import DirectIcon from './components/DirectIcon.svelte'
import ChannelIcon from './components/ChannelIcon.svelte'
import ThreadNotificationPresenter from './components/notification/ThreadNotificationPresenter.svelte'
import DmHeader from './components/DmHeader.svelte'
import DmPresenter from './components/DmPresenter.svelte'
import EditChannel from './components/EditChannel.svelte'
import ChatMessageNotificationLabel from './components/notification/ChatMessageNotificationLabel.svelte'
import ChatAside from './components/chat/ChatAside.svelte'
import ThreadMessagePreview from './components/threads/ThreadMessagePreview.svelte'
import ChatMessagePreview from './components/chat-message/ChatMessagePreview.svelte'
import ChannelCreatedMessage from './components/activity/ChannelCreatedMessage.svelte'
import MembersChangedMessage from './components/activity/MembersChangedMessage.svelte'
import JoinChannelNotificationPresenter from './components/notification/JoinChannelNotificationPresenter.svelte'
import ThreadNotificationPresenter from './components/notification/ThreadNotificationPresenter.svelte'
import ThreadMessagePresenter from './components/threads/ThreadMessagePresenter.svelte'
import ThreadMessagePreview from './components/threads/ThreadMessagePreview.svelte'
import ThreadParentPresenter from './components/threads/ThreadParentPresenter.svelte'
import Threads from './components/threads/Threads.svelte'
import ThreadView from './components/threads/ThreadView.svelte'
import ThreadViewPanel from './components/threads/ThreadViewPanel.svelte'

import {
chunterSpaceLinkFragmentProvider,
getMessageLink,
getMessageLocation,
getThreadLink,
replyToThread
} from './navigation'
import {
ChannelTitleProvider,
DirectTitleProvider,
canCopyMessageLink,
canDeleteMessage,
canReplyToThread,
dmIdentifierProvider,
getDmName,
getTitle,
getUnreadThreadsCount,
canCopyMessageLink,
leaveChannelAction,
removeChannelAction,
canReplyToThread
removeChannelAction
} from './utils'
import {
chunterSpaceLinkFragmentProvider,
getThreadLink,
getMessageLink,
replyToThread,
getMessageLocation
} from './navigation'

export { default as ChatMessagesPresenter } from './components/chat-message/ChatMessagesPresenter.svelte'
export { default as ChatMessagePopup } from './components/chat-message/ChatMessagePopup.svelte'
export { default as ChatMessageInput } from './components/chat-message/ChatMessageInput.svelte'
export { default as ChatMessagePopup } from './components/chat-message/ChatMessagePopup.svelte'
export { default as ChatMessagesPresenter } from './components/chat-message/ChatMessagesPresenter.svelte'
export { default as Header } from './components/Header.svelte'
export { default as ThreadView } from './components/threads/ThreadView.svelte'

export async function ArchiveChannel (channel: Channel, evt: any, 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 = getLocation()
if (loc.path[3] === channel._id) {
loc.path.length = 3
navigate(loc)
}
showPopup(MessageBox, {
label: chunter.string.ArchiveChannel,
message: chunter.string.ArchiveConfirm,
action: async () => {
const client = getClient()

// eslint-disable-next-line @typescript-eslint/no-floating-promises
await client.update(channel, { archived: true })
if (afterArchive != null) afterArchive()

const loc = getLocation()
if (loc.path[3] === channel._id) {
loc.path.length = 3
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 })
}
showPopup(MessageBox, {
label: chunter.string.UnarchiveChannel,
message: chunter.string.UnarchiveConfirm,
action: async () => {
const client = getClient()
await client.update(channel, { archived: false })
}
)
})
}

async function ConvertDmToPrivateChannel (dm: DirectMessage): Promise<void> {
Expand Down
25 changes: 8 additions & 17 deletions plugins/contact-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,25 +272,16 @@ async function kickEmployee (doc: Person): Promise<void> {
if (accounts.length === 0) {
await client.update(employee, { active: false })
} else {
showPopup(
MessageBox,
{
label: contact.string.KickEmployee,
message: contact.string.KickEmployeeDescr
},
undefined,
(res?: boolean) => {
if (res === true) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
const p = getResource(login.function.LeaveWorkspace)
for (const i of accounts) {
void p.then(async (f) => {
await f(i.email)
})
}
showPopup(MessageBox, {
label: contact.string.KickEmployee,
message: contact.string.KickEmployeeDescr,
action: async () => {
const leaveWorkspace = await getResource(login.function.LeaveWorkspace)
for (const i of accounts) {
await leaveWorkspace(i.email)
}
}
)
})
}
}
async function openChannelURL (doc: Channel): Promise<void> {
Expand Down
10 changes: 6 additions & 4 deletions plugins/guest-resources/src/components/CreatePublicLink.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@
MessageBox,
{
label: guest.string.Revoke,
message: guest.string.RevokeConfirmation
message: guest.string.RevokeConfirmation,
action: async () => {
if (link !== undefined) {
await client.remove(link)
}
}
},
'top',
(res) => {
if (res === true && link !== undefined) {
client.remove(link)
}
dispatch('close')
}
)
Expand Down
17 changes: 6 additions & 11 deletions plugins/hr-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,16 @@ export async function addMember (client: TxOperations, employee?: Employee, valu
params: {
current: current.name,
department: value.name
},
action: async () => {
await client.updateMixin(employee._id, employee._class, employee.space, hr.mixin.Staff, {
department: value._id
})
}
},
undefined,
(res?: boolean) => {
if (res === true && value !== undefined) {
void client
.updateMixin(employee._id, employee._class, employee.space, hr.mixin.Staff, {
department: value._id
})
.then(() => {
resolve(null)
})
} else {
resolve(null)
}
resolve(null)
}
)
})
Expand Down
24 changes: 11 additions & 13 deletions plugins/notification-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
isReactionMessage,
messageInFocus
} from '@hcengineering/activity-resources'
import { Analytics } from '@hcengineering/analytics'
import chunter, { type ThreadMessage } from '@hcengineering/chunter'
import core, {
SortingOrder,
getCurrentAccount,
Expand All @@ -39,17 +41,18 @@ import notification, {
NotificationStatus,
notificationId,
type ActivityInboxNotification,
type BaseNotificationType,
type Collaborators,
type DisplayInboxNotification,
type DocNotifyContext,
type InboxNotification,
type MentionInboxNotification,
type BaseNotificationType,
type NotificationProvider,
type NotificationProviderSetting,
type NotificationTypeSetting
} from '@hcengineering/notification'
import { MessageBox, getClient, createQuery } from '@hcengineering/presentation'
import { getMetadata } from '@hcengineering/platform'
import { MessageBox, createQuery, getClient } from '@hcengineering/presentation'
import {
getCurrentLocation,
getLocation,
Expand All @@ -60,12 +63,9 @@ import {
type Location,
type ResolvedLocation
} from '@hcengineering/ui'
import { get, writable } from 'svelte/store'
import chunter, { type ThreadMessage } from '@hcengineering/chunter'
import { getMetadata } from '@hcengineering/platform'
import { decodeObjectURI, encodeObjectURI, type LinkIdProvider } from '@hcengineering/view'
import { getObjectLinkId } from '@hcengineering/view-resources'
import { Analytics } from '@hcengineering/analytics'
import { get, writable } from 'svelte/store'

import { InboxNotificationsClientImpl } from './inboxNotificationsClient'
import { type InboxData, type InboxNotificationsFilter } from './types'
Expand Down Expand Up @@ -311,14 +311,12 @@ export async function archiveAll (): Promise<void> {
MessageBox,
{
label: notification.string.ArchiveAllConfirmationTitle,
message: notification.string.ArchiveAllConfirmationMessage
},
'top',
(result?: boolean) => {
if (result === true) {
void client.archiveAllNotifications()
message: notification.string.ArchiveAllConfirmationMessage,
action: async () => {
await client.archiveAllNotifications()
}
}
},
'top'
)
}

Expand Down
Loading