repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onContainerClick | const onContainerClick = (e: MouseEvent) => {
const container = e.currentTarget as HTMLElement
const layerId = container.dataset.layerId as LayerId
const config = layersConfig.get(layerId)
if (config.isBaseLayer) {
// Skip updates if the container is already active
if (container.classList.contains("active")) return
const activeLayerId = getMapBaseLayerId(map)
if (activeLayerId) removeMapLayer(map, activeLayerId)
addMapLayer(map, layerId)
} else {
const checked = !container.classList.contains("active")
container.classList.toggle("active", checked)
if (checked) {
addMapLayer(map, layerId)
} else {
removeMapLayer(map, layerId)
}
}
} | /** On layer click, update the active (base) layer */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_sidebar-layers.ts#L174-L194 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onOverlayCheckboxChange | const onOverlayCheckboxChange = (e: Event) => {
const checkbox = e.currentTarget as HTMLInputElement
const layerId = checkbox.value as LayerId
const checked = checkbox.checked
// Skip updates if the layer is already in the correct state
if (checked === hasMapLayer(map, layerId)) {
console.debug("Overlay layer", layerId, "is already", checked ? "added" : "removed")
return
}
if (checked) {
addMapLayer(map, layerId)
} else {
removeMapLayer(map, layerId)
}
} | /** On overlay checkbox change, add or remove the overlay layer */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_sidebar-layers.ts#L200-L216 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | updateSidebar | const updateSidebar = (): void => {
// Skip updates if the sidebar is hidden
if (!button.classList.contains("active")) return
const activeLayerId = getMapBaseLayerId(map)
const currentZoomFloor = map.getZoom() | 0
for (const layerContainer of layerContainers) {
const layerId = layerContainer.dataset.layerId as LayerId
if (layerId === activeLayerId) {
// Show section
layerContainer.classList.remove("d-none")
// Update visibility of elements
// TODO: map key not available for this layer infobox
for (const { element, visibility } of layerElementsMap.get(layerId)) {
const isVisible = visibility[currentZoomFloor]
element.classList.toggle("d-none", !isVisible)
}
} else {
// Hide section
layerContainer.classList.add("d-none")
}
}
} | /** Update the sidebar content to show only relevant elements */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_sidebar-legend.ts#L74-L98 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | openMessagePreview | const openMessagePreview = (target: HTMLElement) => {
const newMessageId = target.dataset.id
if (openMessageId === newMessageId) return
if (openTarget) closeMessagePreview()
openTarget = target
openMessageId = newMessageId
console.debug("openMessagePreview", openMessageId)
if (openTarget.classList.contains("unread")) {
openTarget.classList.remove("unread")
changeUnreadMessagesBadge(-1)
}
openTarget.classList.add("active")
senderAvatar.removeAttribute("src")
senderLink.innerHTML = ""
messageTime.innerHTML = ""
messageTitle.innerHTML = ""
messageBody.innerHTML = ""
messagePreviewContainer.classList.remove("d-none")
loadingSpinner.classList.remove("d-none")
// Set show parameter in URL
updatePageUrl(openTarget)
// Update reply link
replyLink.href = `/message/new?reply=${openMessageId}`
// Abort any pending request
abortController?.abort()
abortController = new AbortController()
// Scroll to the message container
messagePreviewContainer.scrollIntoView({
behavior: "smooth",
block: "start",
})
fetch(`/api/web/messages/${openMessageId}`, {
method: "GET",
mode: "same-origin",
cache: "no-store",
signal: abortController.signal,
priority: "high",
})
.then(async (resp) => {
if (!resp.ok) throw new Error(`${resp.status} ${resp.statusText}`)
console.debug("Fetched message", openMessageId)
const { user_display_name, user_avatar_url, time, subject, body_rich } = await resp.json()
senderAvatar.src = user_avatar_url
senderLink.href = `/user/${user_display_name}`
senderLink.textContent = user_display_name
messageTime.innerHTML = time
messageTitle.textContent = subject
messageBody.innerHTML = body_rich
resolveDatetimeLazy(messageTime)
})
.catch((error) => {
if (error.name === "AbortError") return
console.error("Failed to fetch message", error)
messageBody.textContent = error.message
alert(error.message)
})
.finally(() => {
loadingSpinner.classList.add("d-none")
})
} | /** Open a message in the sidebar preview panel */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/messages/_index.ts#L25-L90 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | closeMessagePreview | const closeMessagePreview = () => {
console.debug("closeMessagePreview", openMessageId)
messagePreviewContainer.classList.add("d-none")
abortController?.abort()
abortController = null
openTarget.classList.remove("active")
openTarget = null
openMessageId = null
// Remove show parameter from URL
updatePageUrl(undefined)
} | /** Close the message sidebar preview panel */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/messages/_index.ts#L93-L104 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | updatePageUrl | const updatePageUrl = (message: HTMLElement | undefined) => {
if (message) {
const messageLink = message.querySelector("a.stretched-link")
window.history.replaceState(null, "", messageLink.href)
} else {
const url = new URL(window.location.href)
url.searchParams.delete("show")
window.history.replaceState(null, "", url)
}
} | /** Update the URL with the given message, without reloading the page */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/messages/_index.ts#L107-L116 | 42f2654614f20520271f46b3ddd389732dde6545 |
vscode-container-wasm | github_2023 | ktock | typescript | read_ciovs | function read_ciovs (memory: ArrayBuffer, iovs: ptr, iovsLen: u32): Uint8Array[] {
const view = new DataView(memory);
const buffers: Uint8Array[] = [];
let ptr: ptr = iovs;
for (let i = 0; i < iovsLen; i++) {
const vec = Ciovec.create(view, ptr);
// We need to copy the underlying memory since if it is a shared buffer
// the WASM executable could already change it before we finally read it.
const copy = new Uint8Array(vec.buf_len);
copy.set(new Uint8Array(memory, vec.buf, vec.buf_len));
buffers.push(copy);
ptr += Ciovec.size;
}
return buffers;
} | // Used when writing data | https://github.com/ktock/vscode-container-wasm/blob/bc30c414e2476a51dbb9256ebc4f27a285372ed4/src/vendor/wasm-wasi-core/src/common/service.ts#L1180-L1195 | bc30c414e2476a51dbb9256ebc4f27a285372ed4 |
vscode-container-wasm | github_2023 | ktock | typescript | read_iovs | function read_iovs (memory: ArrayBuffer, iovs: ptr, iovsLen: u32): Uint8Array[] {
const view = new DataView(memory);
const buffers: Uint8Array[] = [];
let ptr: ptr = iovs;
for (let i = 0; i < iovsLen; i++) {
const vec = Iovec.create(view, ptr);
// We need a view onto the memory since we write the result into it.
buffers.push(new Uint8Array(memory, vec.buf, vec.buf_len));
ptr += Iovec.size;
}
return buffers;
} | // Used when reading data | https://github.com/ktock/vscode-container-wasm/blob/bc30c414e2476a51dbb9256ebc4f27a285372ed4/src/vendor/wasm-wasi-core/src/common/service.ts#L1198-L1210 | bc30c414e2476a51dbb9256ebc4f27a285372ed4 |
vscode-container-wasm | github_2023 | ktock | typescript | normalizeString | function normalizeString(path: string, allowAboveRoot: boolean, separator: string, isPathSeparator: (code?: number) => boolean) {
let res = '';
let lastSegmentLength = 0;
let lastSlash = -1;
let dots = 0;
let code = 0;
for (let i = 0; i <= path.length; ++i) {
if (i < path.length) {
code = path.charCodeAt(i);
}
else if (isPathSeparator(code)) {
break;
}
else {
code = CHAR_FORWARD_SLASH;
}
if (isPathSeparator(code)) {
if (lastSlash === i - 1 || dots === 1) {
// NOOP
} else if (dots === 2) {
if (res.length < 2 || lastSegmentLength !== 2 ||
res.charCodeAt(res.length - 1) !== CHAR_DOT ||
res.charCodeAt(res.length - 2) !== CHAR_DOT) {
if (res.length > 2) {
const lastSlashIndex = res.lastIndexOf(separator);
if (lastSlashIndex === -1) {
res = '';
lastSegmentLength = 0;
} else {
res = res.slice(0, lastSlashIndex);
lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
}
lastSlash = i;
dots = 0;
continue;
} else if (res.length !== 0) {
res = '';
lastSegmentLength = 0;
lastSlash = i;
dots = 0;
continue;
}
}
if (allowAboveRoot) {
res += res.length > 0 ? `${separator}..` : '..';
lastSegmentLength = 2;
}
} else {
if (res.length > 0) {
res += `${separator}${path.slice(lastSlash + 1, i)}`;
}
else {
res = path.slice(lastSlash + 1, i);
}
lastSegmentLength = i - lastSlash - 1;
}
lastSlash = i;
dots = 0;
} else if (code === CHAR_DOT && dots !== -1) {
++dots;
} else {
dots = -1;
}
}
return res;
} | // Resolves . and .. elements in a path with directory names | https://github.com/ktock/vscode-container-wasm/blob/bc30c414e2476a51dbb9256ebc4f27a285372ed4/src/vendor/wasm-wasi-core/src/web/path.ts#L68-L134 | bc30c414e2476a51dbb9256ebc4f27a285372ed4 |
vscode-container-wasm | github_2023 | ktock | typescript | importAll | const importAll = (r: __WebpackModuleApi.RequireContext) => r.keys().forEach(r); | // Bundles all files in the current directory matching `*.test` | https://github.com/ktock/vscode-container-wasm/blob/bc30c414e2476a51dbb9256ebc4f27a285372ed4/src/web/test/suite/index.ts#L13-L13 | bc30c414e2476a51dbb9256ebc4f27a285372ed4 |
dev-plugins | github_2023 | expo | typescript | handleCacheEvent | const handleCacheEvent = (event: QueryCacheNotifyEvent) => {
const { query } = event;
client?.sendMessage('queryCacheEvent', {
cacheEvent: stringify({ ...event, query: serializeQuery(query) }, bigintReplacer),
});
}; | /**
* handles QueryCacheNotifyEvent
* @param event - QueryCacheNotifyEvent, but RQ doesn't have it exported
*/ | https://github.com/expo/dev-plugins/blob/fe3724f8e06f1534fb25d127f84270b953f63af9/packages/react-query/src/useReactQueryDevTools.ts#L57-L62 | fe3724f8e06f1534fb25d127f84270b953f63af9 |
workbench | github_2023 | yhtt2020 | typescript | mainWorldScript | function mainWorldScript() {
const DEFAULT_PARTITION = '_self'
class BrowserActionElement extends HTMLButtonElement {
private updateId?: number
private badge?: HTMLDivElement
private pendingIcon?: HTMLImageElement
get id(): string {
return this.getAttribute('id') || ''
}
set id(id: string) {
this.setAttribute('id', id)
}
get tab(): number {
const tabId = parseInt(this.getAttribute('tab') || '', 10)
return typeof tabId === 'number' && !isNaN(tabId) ? tabId : -1
}
set tab(tab: number) {
this.setAttribute('tab', `${tab}`)
}
get partition(): string | null {
return this.getAttribute('partition')
}
set partition(partition: string | null) {
if (partition) {
this.setAttribute('partition', partition)
} else {
this.removeAttribute('partition')
}
}
static get observedAttributes() {
return ['id', 'tab', 'partition']
}
constructor() {
super()
// TODO: event delegation
this.addEventListener('click', this.onClick.bind(this))
this.addEventListener('contextmenu', this.onContextMenu.bind(this))
}
connectedCallback() {
if (this.isConnected) {
this.update()
}
}
disconnectedCallback() {
if (this.updateId) {
cancelAnimationFrame(this.updateId)
this.updateId = undefined
}
if (this.pendingIcon) {
this.pendingIcon = undefined
}
}
attributeChangedCallback() {
if (this.isConnected) {
this.update()
}
}
private activate(event: Event) {
const rect = this.getBoundingClientRect()
browserAction.activate(this.partition || DEFAULT_PARTITION, {
eventType: event.type,
extensionId: this.id,
tabId: this.tab,
anchorRect: {
x: rect.left,
y: rect.top,
width: rect.width,
height: rect.height,
},
})
}
private onClick(event: MouseEvent) {
this.activate(event)
}
private onContextMenu(event: MouseEvent) {
event.stopImmediatePropagation()
event.preventDefault()
this.activate(event)
}
private getBadge() {
let badge = this.badge
if (!badge) {
this.badge = badge = document.createElement('div')
badge.className = 'badge'
;(badge as any).part = 'badge'
this.appendChild(badge)
}
return badge
}
private update() {
if (this.updateId) return
this.updateId = requestAnimationFrame(this.updateCallback.bind(this))
}
private updateIcon(info: any) {
const iconSize = 32
const resizeType = 2
const timeParam = info.iconModified ? `&t=${info.iconModified}` : ''
const iconUrl = `crx://extension-icon/${this.id}/${iconSize}/${resizeType}?tabId=${this.tab}${timeParam}`
const bgImage = `url(${iconUrl})`
if (this.pendingIcon) {
this.pendingIcon = undefined
}
// Preload icon to prevent it from blinking
const img = (this.pendingIcon = new Image())
img.onload = () => {
if (this.isConnected) {
this.style.backgroundImage = bgImage
this.pendingIcon = undefined
}
}
img.src = iconUrl
}
private updateCallback() {
this.updateId = undefined
const action = browserAction.getAction(this.id)
const activeTabId = this.tab
const tabInfo = activeTabId > -1 ? action.tabs[activeTabId] : {}
const info = { ...tabInfo, ...action }
this.title = typeof info.title === 'string' ? info.title : ''
this.updateIcon(info)
if (info.text) {
const badge = this.getBadge()
badge.textContent = info.text
badge.style.color = '#fff' // TODO: determine bg lightness?
badge.style.backgroundColor = info.color
} else if (this.badge) {
this.badge.remove()
this.badge = undefined
}
}
}
customElements.define('browser-action', BrowserActionElement, { extends: 'button' })
class BrowserActionListElement extends HTMLElement {
private observing: boolean = false
get tab(): number | null {
const tabId = parseInt(this.getAttribute('tab') || '', 10)
return typeof tabId === 'number' && !isNaN(tabId) ? tabId : null
}
set tab(tab: number | null) {
if (typeof tab === 'number') {
this.setAttribute('tab', `${tab}`)
} else {
this.removeAttribute('tab')
}
}
get partition(): string | null {
return this.getAttribute('partition')
}
set partition(partition: string | null) {
if (partition) {
this.setAttribute('partition', partition)
} else {
this.removeAttribute('partition')
}
}
static get observedAttributes() {
return ['tab', 'partition']
}
constructor() {
super()
const shadowRoot = this.attachShadow({ mode: 'open' })
const style = document.createElement('style')
style.textContent = `
:host {
display: flex;
flex-direction: row;
gap: 5px;
}
.action {
width: 28px;
height: 28px;
background-color: transparent;
background-position: center;
background-repeat: no-repeat;
background-size: 70%;
border: none;
border-radius: 4px;
padding: 0;
position: relative;
outline: none;
}
.action:hover {
background-color: var(--browser-action-hover-bg, rgba(255, 255, 255, 0.3));
}
.badge {
box-shadow: 0px 0px 1px 1px var(--browser-action-badge-outline, #444);
box-sizing: border-box;
max-width: 100%;
height: 12px;
padding: 0 2px;
border-radius: 2px;
position: absolute;
bottom: 1px;
right: 0;
pointer-events: none;
line-height: 1.5;
font-size: 9px;
font-weight: 400;
overflow: hidden;
white-space: nowrap;
}`
shadowRoot.appendChild(style)
}
connectedCallback() {
if (this.isConnected) {
this.startObserving()
this.fetchState()
}
}
disconnectedCallback() {
this.stopObserving()
}
attributeChangedCallback(name: string, oldValue: any, newValue: any) {
if (oldValue === newValue) return
if (this.isConnected) {
this.fetchState()
}
}
private startObserving() {
if (this.observing) return
browserAction.addEventListener('update', this.update)
browserAction.addObserver(this.partition || DEFAULT_PARTITION)
this.observing = true
}
private stopObserving() {
if (!this.observing) return
browserAction.removeEventListener('update', this.update)
browserAction.removeObserver(this.partition || DEFAULT_PARTITION)
this.observing = false
}
private fetchState = async () => {
try {
await browserAction.getState(this.partition || DEFAULT_PARTITION)
} catch {
console.error(
`browser-action-list failed to update [tab: ${this.tab}, partition: '${this.partition}']`
)
}
}
private update = (state: any) => {
const tabId =
typeof this.tab === 'number' && this.tab >= 0 ? this.tab : state.activeTabId || -1
// Create or update action buttons
for (const action of state.actions) {
let browserActionNode = this.shadowRoot?.querySelector(
`[id=${action.id}]`
) as BrowserActionElement
if (!browserActionNode) {
const node = document.createElement('button', {
is: 'browser-action',
}) as BrowserActionElement
node.id = action.id
node.className = 'action'
;(node as any).part = 'action'
browserActionNode = node
this.shadowRoot?.appendChild(browserActionNode)
}
if (this.partition) browserActionNode.partition = this.partition
browserActionNode.tab = tabId
}
// Remove any actions no longer in use
const actionNodes = Array.from(
this.shadowRoot?.querySelectorAll('.action') as any
) as BrowserActionElement[]
for (const actionNode of actionNodes) {
if (!state.actions.some((action: any) => action.id === actionNode.id)) {
actionNode.remove()
}
}
}
}
customElements.define('browser-action-list', BrowserActionListElement)
} | // Function body to run in the main world. | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser-action.ts#L72-L399 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | ElectronChromeExtensions.fromSession | static fromSession(session: Electron.Session) {
return sessionMap.get(session)
} | /** Retrieve an instance of this class associated with the given session. */ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/index.ts#L39-L41 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | ElectronChromeExtensions.addTab | addTab(tab: Electron.WebContents, window: Electron.BrowserWindow) {
this.ctx.store.addTab(tab, window)
} | /** Add webContents to be tracked as a tab. */ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/index.ts#L131-L133 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | ElectronChromeExtensions.selectTab | selectTab(tab: Electron.WebContents) {
if (this.ctx.store.tabs.has(tab)) {
this.api.tabs.onActivated(tab.id)
}
} | /** Notify extension system that the active tab has changed. */ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/index.ts#L136-L140 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | ElectronChromeExtensions.addExtensionHost | addExtensionHost(host: Electron.WebContents) {
console.warn('ElectronChromeExtensions.addExtensionHost() is deprecated')
} | /**
* Add webContents to be tracked as an extension host which will receive
* extension events when a chrome-extension:// resource is loaded.
*
* This is usually reserved for extension background pages and popups, but
* can also be used in other special cases.
*
* @deprecated Extension hosts are now tracked lazily when they send
* extension IPCs to the main process.
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/index.ts#L152-L154 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | ElectronChromeExtensions.getContextMenuItems | getContextMenuItems(webContents: Electron.WebContents, params: Electron.ContextMenuParams) {
return this.api.contextMenus.buildMenuItemsForParams(webContents, params)
} | /**
* Get collection of menu items managed by the `chrome.contextMenus` API.
* @see https://developer.chrome.com/extensions/contextMenus
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/index.ts#L160-L162 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | ElectronChromeExtensions.addExtension | addExtension(extension: Electron.Extension) {
console.warn('ElectronChromeExtensions.addExtension() is deprecated')
this.api.browserAction.processExtension(extension)
} | /**
* Add extensions to be visible as an extension action button.
*
* @deprecated Not needed in Electron >=12.
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/index.ts#L169-L172 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | ElectronChromeExtensions.removeExtension | removeExtension(extension: Electron.Extension) {
console.warn('ElectronChromeExtensions.removeExtension() is deprecated')
this.api.browserAction.removeActions(extension.id)
} | /**
* Remove extensions from the list of visible extension action buttons.
*
* @deprecated Not needed in Electron >=12.
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/index.ts#L179-L182 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | PopupView.whenReady | whenReady() {
return this.readyPromise
} | /** Resolves when the popup finishes loading. */ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/popup.ts#L153-L155 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | PopupView.queryPreferredSize | private async queryPreferredSize() {
if (this.usingPreferredSize || this.destroyed) return
const rect = await this.browserWindow!.webContents.executeJavaScript(
`((${() => {
const rect = document.body.getBoundingClientRect()
return { width: rect.width, height: rect.height }
}})())`
)
if (this.destroyed) return
this.setSize({ width: rect.width, height: rect.height })
this.updatePosition()
} | /** Backwards compat for Electron <12 */ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/popup.ts#L219-L233 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | shortenValues | const shortenValues = (k: string, v: any) =>
typeof v === 'string' && v.length > 128 ? v.substr(0, 128) + '...' : v | // Shorten base64 encoded icons | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/router.ts#L6-L7 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | ExtensionRouter.apiHandler | apiHandler() {
return (name: string, callback: HandlerCallback, opts?: HandlerOptions) => {
this.handle(name, callback, opts)
}
} | /** Returns a callback to register API handlers for the given context. */ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/router.ts#L286-L290 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | ExtensionRouter.sendEvent | sendEvent(extensionId: string | undefined, eventName: string, ...args: any[]) {
const { listeners } = this
let eventListeners = listeners.get(eventName)
if (extensionId) {
// TODO: extension permissions check
eventListeners = eventListeners?.filter((el) => el.extensionId === extensionId)
}
if (!eventListeners || eventListeners.length === 0) {
debug(`ignoring '${eventName}' event with no listeners`)
return
}
for (const { host } of eventListeners) {
// TODO: may need to wake lazy extension context
if (host.isDestroyed()) {
console.error(`Unable to send '${eventName}' to extension host for ${extensionId}`)
continue
}
const ipcName = `crx-${eventName}`
host.send(ipcName, ...args)
}
} | /**
* Sends extension event to the host for the given extension ID if it
* registered a listener for it.
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/router.ts#L296-L322 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | ExtensionRouter.broadcastEvent | broadcastEvent(eventName: string, ...args: any[]) {
this.sendEvent(undefined, eventName, ...args)
} | /** Broadcasts extension event to all extension hosts listening for it. */ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/router.ts#L325-L327 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | BrowserActionAPI.setupProtocol | public setupProtocol(session:Electron.Session){
const result=session.protocol.registerBufferProtocol('crx', this.handleCrxRequest)
return result
} | //注册协议 | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/api/browser-action.ts#L198-L201 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | BrowserActionAPI.removeActions | removeActions(extensionId: string) {
if (this.actionMap.has(extensionId)) {
this.actionMap.delete(extensionId)
}
this.onUpdate()
} | // TODO: Make private for v4 major release. | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/api/browser-action.ts#L290-L296 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | BrowserActionAPI.processExtension | processExtension(extension: Electron.Extension) {
const defaultAction = getBrowserActionDefaults(extension)
if (defaultAction) {
const action = this.getAction(extension.id)
Object.assign(action, defaultAction)
}
} | // TODO: Make private for v4 major release. | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/api/browser-action.ts#L320-L326 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | getFrame | const getFrame = (frameProcessId: number, frameRoutingId: number) => {
return (
('webFrameMain' in electron &&
(electron as any).webFrameMain.fromId(frameProcessId, frameRoutingId)) ||
null
)
} | // https://github.com/electron/electron/pull/25464 | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/browser/api/web-navigation.ts#L8-L14 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | mainWorldScript | function mainWorldScript() {
// Use context bridge API or closure variable when context isolation is disabled.
const electron = ((window as any).electron as typeof electronContext) || electronContext
const chrome = window.chrome || {}
const extensionId = chrome.runtime?.id
// NOTE: This uses a synchronous IPC to get the extension manifest.
// To avoid this, JS bindings for RendererExtensionRegistry would be
// required.
const manifest: chrome.runtime.Manifest =
(extensionId && chrome.runtime.getManifest()) || ({} as any)
//取回message的内容,替换掉i18n的本地化方法,因为那个方法有问题
let localeMessages:any={}
const invokeExtension =
(fnName: string, opts: ExtensionMessageOptions = {}) =>
(...args: any[]) =>
electron.invokeExtension(extensionId, fnName, opts, ...args)
invokeExtension( 'i18n.getAllMessage')((args:[])=>{
localeMessages=args
})//取回全部的message
function imageData2base64(imageData: ImageData) {
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
if (!ctx) return null
canvas.width = imageData.width
canvas.height = imageData.height
ctx.putImageData(imageData, 0, 0)
return canvas.toDataURL()
}
class ExtensionEvent<T extends Function> implements chrome.events.Event<T> {
constructor(private name: string) {}
addListener(callback: T) {
electron.addExtensionListener(extensionId, this.name, callback)
}
removeListener(callback: T) {
electron.removeExtensionListener(extensionId, this.name, callback)
}
getRules(callback: (rules: chrome.events.Rule[]) => void): void
getRules(ruleIdentifiers: string[], callback: (rules: chrome.events.Rule[]) => void): void
getRules(ruleIdentifiers: any, callback?: any) {
throw new Error('Method not implemented.')
}
hasListener(callback: T): boolean {
throw new Error('Method not implemented.')
}
removeRules(ruleIdentifiers?: string[] | undefined, callback?: (() => void) | undefined): void
removeRules(callback?: (() => void) | undefined): void
removeRules(ruleIdentifiers?: any, callback?: any) {
throw new Error('Method not implemented.')
}
addRules(
rules: chrome.events.Rule[],
callback?: ((rules: chrome.events.Rule[]) => void) | undefined
): void {
throw new Error('Method not implemented.')
}
hasListeners(): boolean {
throw new Error('Method not implemented.')
}
}
class ChromeSetting implements Partial<chrome.types.ChromeSetting> {
set() {}
get() {}
clear() {}
// onChange: chrome.types.ChromeSettingChangedEvent
}
type DeepPartial<T> = {
[P in keyof T]?: DeepPartial<T[P]>
}
type APIFactoryMap = {
[apiName in keyof typeof chrome]: {
shouldInject?: () => boolean
factory: (base: DeepPartial<typeof chrome[apiName]>) => DeepPartial<typeof chrome[apiName]>
}
}
/**
* Factories for each additional chrome.* API.
*/
const apiDefinitions: Partial<APIFactoryMap> = {
browserAction: {
shouldInject: () => !!manifest.browser_action,
factory: (base) => {
const api = {
...base,
setTitle: invokeExtension('browserAction.setTitle'),
getTitle: invokeExtension('browserAction.getTitle'),
setIcon: invokeExtension('browserAction.setIcon', {
serialize: (details: any) => {
if (details.imageData) {
if (details.imageData instanceof ImageData) {
details.imageData = imageData2base64(details.imageData)
} else {
details.imageData = Object.entries(details.imageData).reduce(
(obj: any, pair: any[]) => {
obj[pair[0]] = imageData2base64(pair[1])
return obj
},
{}
)
}
}
return [details]
},
}),
setPopup: invokeExtension('browserAction.setPopup'),
getPopup: invokeExtension('browserAction.getPopup'),
setBadgeText: invokeExtension('browserAction.setBadgeText'),
getBadgeText: invokeExtension('browserAction.getBadgeText'),
setBadgeBackgroundColor: invokeExtension('browserAction.setBadgeBackgroundColor'),
getBadgeBackgroundColor: invokeExtension('browserAction.getBadgeBackgroundColor'),
enable: invokeExtension('browserAction.enable', { noop: true }),
disable: invokeExtension('browserAction.disable', { noop: true }),
onClicked: new ExtensionEvent('browserAction.onClicked'),
}
return api
},
},
commands: {
factory: (base) => {
return {
...base,
getAll: invokeExtension('commands.getAll'),
onCommand: new ExtensionEvent('commands.onCommand'),
}
},
},
contextMenus: {
factory: (base) => {
let menuCounter = 0
const menuCallbacks: {
[key: string]: chrome.contextMenus.CreateProperties['onclick']
} = {}
const menuCreate = invokeExtension('contextMenus.create')
let hasInternalListener = false
const addInternalListener = () => {
api.onClicked.addListener((info, tab) => {
const callback = menuCallbacks[info.menuItemId]
if (callback && tab) callback(info, tab)
})
hasInternalListener = true
}
const api = {
...base,
create: function (
createProperties: chrome.contextMenus.CreateProperties,
callback?: Function
) {
if (typeof createProperties.id === 'undefined') {
createProperties.id = `${++menuCounter}`
}
if (createProperties.onclick) {
if (!hasInternalListener) addInternalListener()
menuCallbacks[createProperties.id] = createProperties.onclick
delete createProperties.onclick
}
menuCreate(createProperties, callback)
return createProperties.id
},
update: invokeExtension('contextMenus.update', { noop: true }),
remove: invokeExtension('contextMenus.remove'),
removeAll: invokeExtension('contextMenus.removeAll'),
onClicked: new ExtensionEvent<
(info: chrome.contextMenus.OnClickData, tab: chrome.tabs.Tab) => void
>('contextMenus.onClicked'),
}
return api
},
},
cookies: {
factory: (base) => {
return {
...base,
get: invokeExtension('cookies.get'),
getAll: invokeExtension('cookies.getAll'),
set: invokeExtension('cookies.set'),
remove: invokeExtension('cookies.remove'),
getAllCookieStores: invokeExtension('cookies.getAllCookieStores'),
onChanged: new ExtensionEvent('cookies.onChanged'),
}
},
},
extension: {
factory: (base) => {
return {
...base,
isAllowedIncognitoAccess: () => false,
isAllowedFileSchemeAccess:async (callback:Function)=>{
return true//todo 此处应该还要兼容一下涉及到的文件协议
//callback(true)
},
// TODO: Add native implementation
getViews: () => [],
}
},
},
notifications: {
factory: (base) => {
return {
...base,
clear: invokeExtension('notifications.clear'),
create: invokeExtension('notifications.create'),
getAll: invokeExtension('notifications.getAll'),
getPermissionLevel: invokeExtension('notifications.getPermissionLevel'),
update: invokeExtension('notifications.update'),
onClicked: new ExtensionEvent('notifications.onClicked'),
onButtonClicked: new ExtensionEvent('notifications.onButtonClicked'),
onClosed: new ExtensionEvent('notifications.onClosed'),
}
},
},
privacy: {
factory: (base) => {
return {
...base,
network: {
networkPredictionEnabled: new ChromeSetting(),
webRTCIPHandlingPolicy: new ChromeSetting(),
},
websites: {
hyperlinkAuditingEnabled: new ChromeSetting(),
},
}
},
},
runtime: {
factory: (base) => {
return {
...base,
openOptionsPage: invokeExtension('runtime.openOptionsPage'),
// getManifest:()=>{
// manifest.current_locale='zh_CN'
// return manifest
// }
}
},
},
storage: {
factory: (base) => {
const local = base && base.local
return {
...base,
// TODO: provide a backend for browsers to opt-in to
managed: local,
sync: local,
}
},
},
tabs: {
factory: (base) => {
const api = {
...base,
create: invokeExtension('tabs.create'),
executeScript: function (arg1: unknown, arg2: unknown, arg3: unknown) {
// Electron's implementation of chrome.tabs.executeScript is in
// C++, but it doesn't support implicit execution in the active
// tab. To handle this, we need to get the active tab ID and
// pass it into the C++ implementation ourselves.
if (typeof arg1 === 'object') {
api.query(
{ active: true, windowId: chrome.windows.WINDOW_ID_CURRENT },
([activeTab]: chrome.tabs.Tab[]) => {
api.executeScript(activeTab.id, arg1, arg2)
}
)
} else {
;(base.executeScript as typeof chrome.tabs.executeScript)(
arg1 as number,
arg2 as chrome.tabs.InjectDetails,
arg3 as () => {}
)
}
},
get: invokeExtension('tabs.get'),
getSelected:invokeExtension('tabs.getSelected'),//todo 确认是否正确返回
getCurrent: invokeExtension('tabs.getCurrent'),
getAllInWindow: invokeExtension('tabs.getAllInWindow'),
insertCSS: invokeExtension('tabs.insertCSS'),
query: invokeExtension('tabs.query'),
reload: invokeExtension('tabs.reload'),
update: invokeExtension('tabs.update'),
remove: invokeExtension('tabs.remove'),
goBack: invokeExtension('tabs.goBack'),
goForward: invokeExtension('tabs.goForward'),
onCreated: new ExtensionEvent('tabs.onCreated'),
onRemoved: new ExtensionEvent('tabs.onRemoved'),
onUpdated: new ExtensionEvent('tabs.onUpdated'),
onActivated: new ExtensionEvent('tabs.onActivated'),
onReplaced: new ExtensionEvent('tabs.onReplaced'),
}
return api
},
},
webNavigation: {
factory: (base) => {
return {
...base,
getFrame: invokeExtension('webNavigation.getFrame'),
getAllFrames: invokeExtension('webNavigation.getAllFrames'),
onBeforeNavigate: new ExtensionEvent('webNavigation.onBeforeNavigate'),
onCommitted: new ExtensionEvent('webNavigation.onCommitted'),
onCompleted: new ExtensionEvent('webNavigation.onCompleted'),
onCreatedNavigationTarget: new ExtensionEvent(
'webNavigation.onCreatedNavigationTarget'
),
onDOMContentLoaded: new ExtensionEvent('webNavigation.onDOMContentLoaded'),
onErrorOccurred: new ExtensionEvent('webNavigation.onErrorOccurred'),
onHistoryStateUpdated: new ExtensionEvent('webNavigation.onHistoryStateUpdated'),
onReferenceFragmentUpdated: new ExtensionEvent(
'webNavigation.onReferenceFragmentUpdated'
),
onTabReplaced: new ExtensionEvent('webNavigation.onTabReplaced'),
}
},
},
webRequest: {
factory: (base) => {
return {
...base,
onHeadersReceived: new ExtensionEvent('webRequest.onHeadersReceived'),
}
},
},
windows: {
factory: (base) => {
return {
...base,
WINDOW_ID_NONE: -1,
WINDOW_ID_CURRENT: -2,
getCurrent:invokeExtension('windows.getCurrent'),
get: invokeExtension('windows.get'),
getLastFocused: invokeExtension('windows.getLastFocused'),
getAll: invokeExtension('windows.getAll'),
create: invokeExtension('windows.create'),
update: invokeExtension('windows.update'),
remove: invokeExtension('windows.remove'),
onCreated: new ExtensionEvent('windows.onCreated'),
onRemoved: new ExtensionEvent('windows.onRemoved'),
onFocusChanged: new ExtensionEvent('windows.onFocusChanged'),
}
},
},
}
// Initialize APIs
Object.keys(apiDefinitions).forEach((key: any) => {
const apiName: keyof typeof chrome = key
const baseApi = chrome[apiName] as any
const api = apiDefinitions[apiName]!
// Allow APIs to opt-out of being available in this context.
if (api.shouldInject && !api.shouldInject()) return
Object.defineProperty(chrome, apiName, {
value: api.factory(baseApi),
enumerable: true,
configurable: true,
})
})
// Remove access to internals
delete (window as any).electron
Object.freeze(chrome)
void 0 // no return
} | // Function body to run in the main world. | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/packages/electron-chrome-extensions/src/renderer/index.ts#L61-L459 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | AppStorageModel.getItem | async getItem(key,sign=null){
let found=await this.db.knex('storage').where({key,sign}).first()
if(found){
return found['value']
}else{
return null
}
} | /**
* 注意,取出的所有值均为string,需要自行反序列化
* @param key
* @param sign
* @returns {Promise<*>}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/src/model/appStorageModel.ts#L34-L42 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | AppStorageModel.setItem | async setItem(key,value,sign){
if(typeof value==='object'){
value=JSON.stringify(value)
}
let found= await this.db.knex('storage').where({key,sign}).first()
if(found){
return this.db.knex('storage').where({key,sign}).update({value})
}else{
return this.db.knex('storage').insert({value,key,sign,nanoid:nanoid(8)})
}
} | /**
* 支持自动序列化对象值value
* @param key
* @param value
* @param domain 跨站的值可留空
* @returns {*}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/src/model/appStorageModel.ts#L51-L62 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TableModel.getItem | async getItem(key,sign=null){
let found=await this.db.knex('storage').where({key,sign}).first()
if(found){
return found['value']
}else{
return null
}
} | /**
* 注意,取出的所有值均为string,需要自行反序列化
* @param key
* @param sign
* @returns {Promise<*>}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/src/model/tableModel.ts#L33-L41 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TableModel.setItem | async setItem(key,value,sign){
if(typeof value==='object'){
value=JSON.stringify(value)
}
let found= await this.db.knex('storage').where({key,sign}).first()
if(found){
return this.db.knex('storage').where({key,sign}).update({value})
}else{
return this.db.knex('storage').insert({value,key,sign,nanoid:nanoid(8)})
}
} | /**
* 支持自动序列化对象值value
* @param key
* @param value
* @param domain 跨站的值可留空
* @returns {*}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/src/model/tableModel.ts#L50-L61 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | sUrl | function sUrl(url:string) {
return Server.baseUrl+url
} | /**
* 生成服务端url,斜杠开头
* @param url 接口地址,斜杠开头
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/consts.ts#L11-L13 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | initStores | function initStores(){
aiStore()
appsStore()
frameStore()
browserStore()
captureStore()
cardStore()
chatStore()
codeStore()
comStore()
countDownStore()
deskStore()
filmStore()
epicStore()
fishStore()
gameStrategyStore()
homeStore()
inspectorStore()
marketStore()
myIcons()
navStore()
newsStore()
paperStore()
rankStore()
screenStore()
steamStore()
steamUserStore()
teamStore()
timerStore()
topClockSettingStore()
weatherStore()
workStore()
yuanCommunityStore()
} | /*加载其他状态end*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/initStores.ts#L36-L69 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | install | const install = (app: any) => {
list.forEach((component:any) => {
component.install(app);
});
}; | /**
* 组件挂载
*
* @param {app} app 挂载到主体
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/index.ts#L23-L27 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | plugin | const plugin = (TUICore: any) => {
list.forEach((component:any) => {
component.plugin(TUICore);
});
}; | /**
* 组件注册到TUICore
*
* @param {TUICore} TUICore 主体TUICore
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/index.ts#L34-L38 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | IComponentServer.destroyed | public destroyed() {} | /**
* 组件销毁
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/IComponentServer.ts#L11-L11 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | IComponentServer.updateStore | protected updateStore(oldValue:any, newValue:any) {} | /**
* 数据监听回调
*
* @param {any} oldValue 旧数据
* @param {any} newValue 新数据
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/IComponentServer.ts#L19-L19 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.destroyed | public destroyed() {
this.unbindTIMEvent();
} | /**
* 组件销毁
* destroy
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L26-L28 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.updateStore | updateStore(newValue: any, oldValue: any) {
Object.assign(this.currentStore, newValue);
if (!newValue.conversation.conversationID) {
this.currentStore.messageList = [];
return;
}
if (
newValue.conversation.conversationID &&
newValue.conversation.conversationID !== oldValue.conversation.conversationID
) {
this.render(newValue.conversation);
}
} | /**
* 数据监听回调
* data listener callback
*
* @param {any} newValue 新数据
* @param {any} oldValue 旧数据
*
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L38-L50 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.bindTIMEvent | private bindTIMEvent() {
this.TUICore.tim.on(this.TUICore.TIM.EVENT.MESSAGE_RECEIVED, this.handleMessageReceived, this);
this.TUICore.tim.on(this.TUICore.TIM.EVENT.MESSAGE_MODIFIED, this.handleMessageModified, this);
this.TUICore.tim.on(this.TUICore.TIM.EVENT.MESSAGE_REVOKED, this.handleMessageRevoked, this);
this.TUICore.tim.on(this.TUICore.TIM.EVENT.MESSAGE_READ_BY_PEER, this.handleMessageReadByPeer, this);
this.TUICore.tim.on(this.TUICore.TIM.EVENT.GROUP_LIST_UPDATED, this.handleGroupListUpdated, this);
this.TUICore.tim.on(
this.TUICore.TIM.EVENT.MESSAGE_READ_RECEIPT_RECEIVED,
this.handleMessageReadReceiptReceived,
this
);
} | /**
* /////////////////////////////////////////////////////////////////////////////////
* //
* // TIM 事件监听注册接口
* // TIM Event listener registration interface
* //
* /////////////////////////////////////////////////////////////////////////////////
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L94-L105 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.handleMessageOptions | public handleMessageOptions(content: any, type: string, callback?: any, to?: any) {
const options: any = {
to: '',
conversationType: to?.type || this.store.conversation.type,
payload: content,
needReadReceipt: this.currentStore.needReadReceipt,
};
if (this.currentStore.needTyping) {
options.cloudCustomData = {
messageFeature: {
needTyping: 1,
version: 1,
},
};
options.cloudCustomData = JSON.stringify(options.cloudCustomData);
}
if (type === 'file' && callback) {
options.onProgress = callback;
}
switch (options.conversationType) {
case this.TUICore.TIM.TYPES.CONV_C2C:
options.to = to?.userProfile?.userID || this.store.conversation?.userProfile?.userID || '';
break;
case this.TUICore.TIM.TYPES.CONV_GROUP:
options.to = to?.groupProfile?.groupID || this.store.conversation?.groupProfile?.groupID || '';
break;
default:
break;
}
return options;
} | /**
* 创建消息生成参数
* Create message generation parameters
*
* @param {Object} content 消息体
* @param {String} type 消息类型 text: 文本类型 file: 文件类型 face: 表情 location: 地址 custom: 自定义 merger: 合并 forward: 转发
* @param {Callback} callback 回调函数
* @param {any} to 发送的对象
* @returns {options} 消息参数
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L177-L207 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.handlePromiseCallback | public handlePromiseCallback(callback: any) {
return new Promise<void>((resolve, reject) => {
const config = {
TUIName: 'TUIChat',
callback: () => {
callback && callback(resolve, reject);
},
};
this.TUICore.setAwaitFunc(config.TUIName, config.callback);
});
} | /**
* 处理异步函数
* Handling asynchronous functions
*
* @param {callback} callback 回调函数
* @returns {Promise} 返回异步函数
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L216-L226 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.handlePromiseCallbackRetry | public handlePromiseCallbackRetry(callback: any, intervalList: Array<number> = [], retryBreakFn: any = function () { return false; }): Promise<any> {
return new Promise<void>((resolve, reject) => {
let times = 0;
function tryFn() {
times++;
callback()
.then(resolve)
.catch((error: any) => {
if (times > intervalList.length || (retryBreakFn && retryBreakFn(error))) {
reject(error);
return;
}
setTimeout(tryFn, intervalList[times - 1]);
})
}
tryFn();
})
} | /**
* 重试异步函数
* Retry asynchronous functions
* 默认执行一次,之后按时间间隔列表重复执行直到成功,重复次数完毕后仍失败则失败
* Execute once by default, and then repeat it according to the time interval list until it succeeds.
* If it still fails after the number of repetitions is complete, it will reject.
*
* @param {callback} callback 回调函数/callback function
* @param {Array<number>} intervalList 间隔时间列表/interval list
* @param {callback} retryBreakFn 强制重复结束条件函数/break retry function
* @returns {Promise} 返回异步函数/return
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L240-L257 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.handleUploadProgress | public handleUploadProgress(progress: number, message: any) {
this.currentStore.messageList.map((item: any) => {
if (item.ID === message.ID) {
item.progress = progress;
}
return item;
});
} | /**
* 文件上传进度函数处理
* File upload progress function processing
*
* @param {number} progress 文件上传进度 1表示完成
* @param {message} message 文件消息
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L267-L274 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.sendFaceMessage | public sendFaceMessage(data: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const options = this.handleMessageOptions(data, 'face');
const message = this.TUICore.tim.createFaceMessage(options);
this.currentStore.messageList.push(message);
const imResponse = await this.TUICore.tim.sendMessage(message);
this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
if (item.ID === imResponse.data.message.ID) {
return imResponse.data.message;
}
return item;
});
resolve(imResponse);
} catch (error) {
reject(error);
const middleData = this.currentStore.messageList;
this.currentStore.messageList = [];
this.currentStore.messageList = middleData;
}
});
} | /**
* 发送表情消息
* Send face messages
*
* @param {Object} data 消息内容/message content
* @param {Number} data.index 表情索引/face index
* @param {String} data.data 额外数据/extra data
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L294-L315 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.sendImageMessage | public sendImageMessage(image: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const options = this.handleMessageOptions({ file: image }, 'file', (progress: number) => {
this.handleUploadProgress(progress, message);
});
const message = this.TUICore.tim.createImageMessage(options);
message.progress = 0.01;
this.currentStore.messageList.push(message);
const imResponse = await this.TUICore.tim.sendMessage(message);
this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
if (item.ID === imResponse.data.message.ID) {
return imResponse.data.message;
}
return item;
});
resolve(imResponse);
} catch (error) {
reject(error);
const middleData = this.currentStore.messageList;
this.currentStore.messageList = [];
this.currentStore.messageList = middleData;
}
});
} | /**
* 发送图片消息
* Send image message
*
* @param {Image} image 图片文件/image
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L324-L348 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.sendVideoMessage | public sendVideoMessage(video: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const options = this.handleMessageOptions({ file: video }, 'file', (progress: number) => {
this.handleUploadProgress(progress, message);
});
const message = this.TUICore.tim.createVideoMessage(options);
message.progress = 0.01;
this.currentStore.messageList.push(message);
const imResponse = await this.TUICore.tim.sendMessage(message);
this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
if (item.ID === imResponse.data.message.ID) {
return imResponse.data.message;
}
return item;
});
resolve(imResponse);
} catch (error) {
reject(error);
const middleData = this.currentStore.messageList;
this.currentStore.messageList = [];
this.currentStore.messageList = middleData;
}
});
} | /**
* 发送视频消息
* Send video message
*
* @param {Video} video 视频文件/video
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L357-L382 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.sendFileMessage | public sendFileMessage(file: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const options = this.handleMessageOptions({ file }, 'file', (progress: number) => {
this.handleUploadProgress(progress, message);
});
const message = this.TUICore.tim.createFileMessage(options);
message.progress = 0.01;
this.currentStore.messageList.push(message);
const imResponse = await this.TUICore.tim.sendMessage(message);
this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
if (item.ID === imResponse.data.message.ID) {
return imResponse.data.message;
}
return item;
});
resolve(imResponse);
} catch (error) {
reject(error);
const middleData = this.currentStore.messageList;
this.currentStore.messageList = [];
this.currentStore.messageList = middleData;
}
});
} | /**
* 发送文件消息
* Send file message
*
* @param {File} file 文件/file
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L391-L415 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.sendCustomMessage | public sendCustomMessage(data: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
data.data = JSON.stringify(data.data);
const options = this.handleMessageOptions(data, 'custom');
const message = this.TUICore.tim.createCustomMessage(options);
this.currentStore.messageList.push(message);
const imResponse = await this.TUICore.tim.sendMessage(message);
this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
if (item.ID === imResponse.data.message.ID) {
return imResponse.data.message;
}
return item;
});
resolve(imResponse);
} catch (error) {
reject(error);
const middleData = this.currentStore.messageList;
this.currentStore.messageList = [];
this.currentStore.messageList = middleData;
}
});
} | /**
* 发送自定义消息
* Send Custom message
*
* @param {Object} data 消息内容/message content
* @param {String} data.data 自定义消息的数据字段/custom message data fields
* @param {String} data.description 自定义消息的说明字段/custom message description fields
* @param {String} data.extension 自定义消息的扩展字段/custom message extension fields
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L427-L449 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.sendLocationMessage | public sendLocationMessage(data: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const options = this.handleMessageOptions(data, 'location');
const message = this.TUICore.tim.createLocationMessage(options);
this.currentStore.messageList.push(message);
const imResponse = await this.TUICore.tim.sendMessage(message);
resolve(imResponse);
} catch (error) {
reject(error);
const middleData = this.currentStore.messageList;
this.currentStore.messageList = [];
this.currentStore.messageList = middleData;
}
});
} | /**
* 发送地理位置消息
* Send location message
*
* @param {Object} data 消息内容/message content
* @param {String} data.description 地理位置描述信息/geographic descriptive information
* @param {Number} data.longitude 经度/longitude
* @param {Number} data.latitude 纬度/latitude
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L461-L476 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.forwardMessage | public forwardMessage(message: any, to: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const options = this.handleMessageOptions(message, 'forward', {}, to);
const imMessage = this.TUICore.tim.createForwardMessage(options);
const imResponse = await this.TUICore.tim.sendMessage(imMessage);
if (this.store.conversation.conversationID === imResponse.data.message.conversationID) {
this.currentStore.messageList.push(imResponse.data.message);
}
resolve(imResponse);
} catch (error) {
reject(error);
const middleData = this.currentStore.messageList;
this.currentStore.messageList = [];
this.currentStore.messageList = middleData;
}
});
} | /**
* 转发消息
* forward message
*
* @param {message} message 消息实例/message
* @param {any} to 转发的对象/forward to
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L486-L503 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.sendMessageReadReceipt | public async sendMessageReadReceipt(messageList: Array<any>) {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse: any = await this.TUICore.tim.sendMessageReadReceipt(messageList);
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 发送消息已读回执
* Send message read receipt
*
* @param {Array} messageList 同一个 C2C 或 GROUP 会话的消息列表,最大长度为30/A list of messages for the same C2C or GROUP conversation, with a maximum length of 30
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L512-L521 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.getMessageReadReceiptList | public async getMessageReadReceiptList(messageList: Array<any>) {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse: any = await this.TUICore.tim.getMessageReadReceiptList(messageList);
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 拉取已读回执列表
* Pull read receipt list
*
* @param {Array} messageList 同一群会话的消息列表/The message list of the same group of the conversation
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L530-L539 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.getMessageList | public async getMessageList(options: any, history?: boolean) {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.getMessageList(options);
if (imResponse.data.messageList.length) {
await this.getMessageReadReceiptList(imResponse.data.messageList);
}
if (!history) {
this.currentStore.messageList = imResponse.data.messageList;
} else {
this.currentStore.messageList = [...imResponse.data.messageList, ...this.currentStore.messageList];
}
this.currentStore.nextReqMessageID = imResponse.data.nextReqMessageID;
this.currentStore.isCompleted = imResponse.data.isCompleted;
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 获取 messageList
* get messagelist
*
* @param {any} options 获取 messageList 参数/messageList options
* @param {Boolean} history 是否获取历史消息/Whether to get historical information
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L557-L577 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.getHistoryMessageList | public async getHistoryMessageList() {
const options = {
conversationID: this.currentStore.conversation.conversationID,
nextReqMessageID: this.currentStore.nextReqMessageID,
count: 15,
};
if (!this.currentStore.isCompleted) {
this.getMessageList(options, true);
}
} | /**
* 获取历史消息
* get history messagelist
*
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L585-L594 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.sendTextMessage | public sendTextMessage(text: any, data: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const options = this.handleMessageOptions({ text }, 'text');
let cloudCustomDataObj = {};
if (options.cloudCustomData) {
try {
cloudCustomDataObj = JSONToObject(options.cloudCustomData);
} catch {
cloudCustomDataObj = {};
}
}
const cloudCustomData = JSON.stringify(data);
const secondOptions = Object.assign(options, { cloudCustomData, ...cloudCustomDataObj });
const message = this.TUICore.tim.createTextMessage(secondOptions);
this.currentStore.messageList.push(message);
const imResponse = await this.TUICore.tim.sendMessage(message);
this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
if (item.ID === imResponse.data.message.ID) {
return imResponse.data.message;
}
return item;
});
resolve(imResponse);
} catch (error) {
reject(error);
const middleData = this.currentStore.messageList;
this.currentStore.messageList = [];
this.currentStore.messageList = middleData;
}
});
} | /**
* 发送文本消息
* send text message
*
* @param {any} text 发送的消息/text message
* @param {object} data 被引用消息的内容/The content of the quoted message
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L604-L635 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.sendTypingMessage | public sendTypingMessage(data: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
data.data = JSON.stringify(data.data);
const options = this.handleMessageOptions(data, 'custom');
const message = this.TUICore.tim.createCustomMessage(options);
const imResponse = await this.TUICore.tim.sendMessage(message, { onlineUserOnly: true });
resolve(imResponse);
} catch (error) {
reject(error);
const middleData = this.currentStore.messageList;
this.currentStore.messageList = [];
this.currentStore.messageList = middleData;
}
});
} | /**
* 发送【对方正在输入中】在线自定义消息
* send typing online custom message
*
* @param {Object} data 消息内容/message content
* @param {String} data.data 自定义消息的数据字段/custom message data field
* @param {String} data.description 自定义消息的说明字段/custom message description field
* @param {String} data.extension 自定义消息的扩展字段/custom message extension field
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L647-L662 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.sendTextAtMessage | public sendTextAtMessage(data: any) {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const options = this.handleMessageOptions(data, 'text');
const message = this.TUICore.tim.createTextAtMessage(options);
this.currentStore.messageList.push(message);
const imResponse = await this.TUICore.tim.sendMessage(message);
this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
if (item.ID === imResponse.data.message.ID) {
return imResponse.data.message;
}
return item;
});
resolve(imResponse);
} catch (error) {
reject(error);
const middleData = this.currentStore.messageList;
this.currentStore.messageList = [];
this.currentStore.messageList = middleData;
}
});
} | /**
* 发送@ 提醒功能的文本消息
* Send @ Reminder text message
*
* @param {any} data 消息内容/message content
* @param {String} data.text 文本消息/text message
* @param {Array} data.atUserList 需要 @ 的用户列表,如果需要 @ALL,请传入 TIM.TYPES.MSG_AT_ALL / List of users who need @, if you need @ALL, please pass in TIM.TYPES.MSG_AT_ALL
* @returns {message}
*
* - 注:此接口仅用于群聊/This interface is only used for group chat
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L675-L696 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.sendMergerMessage | public sendMergerMessage(data: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const options = this.handleMessageOptions(data, 'merger');
const message = this.TUICore.tim.createMergerMessage(options);
this.currentStore.messageList.push(message);
const imResponse = await this.TUICore.tim.sendMessage(message);
this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
if (item.ID === imResponse.data.message.ID) {
return imResponse.data.message;
}
return item;
});
resolve(imResponse);
} catch (error) {
reject(error);
const middleData = this.currentStore.messageList;
this.currentStore.messageList = [];
this.currentStore.messageList = middleData;
}
});
} | /**
* 发送合并消息
* send merger message
*
* @param {Object} data 消息内容/message content
* @param {Array.<Message>} data.messageList 合并的消息列表/merger message list
* @param {String} data.title 合并的标题/merger title
* @param {String} data.abstractList 摘要列表,不同的消息类型可以设置不同的摘要信息/Summary list, different message types can set different summary information
* @param {String} data.compatibleText 兼容文本/ompatible text
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L709-L730 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.revokeMessage | public revokeMessage(message: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.revokeMessage(message);
const cloudCustomData = JSONToObject(message?.cloudCustomData);
if (cloudCustomData?.messageReply?.messageRootID) {
await this.revokeReplyMessage(message);
}
resolve(imResponse);
} catch (error) {
reject(error);
const middleData = this.currentStore.messageList;
this.currentStore.messageList = [];
this.currentStore.messageList = middleData;
}
});
} | /**
* 消息撤回
* revoke message
*
* @param {message} message 消息实例/message
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L739-L755 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.resendMessage | public resendMessage(message: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.resendMessage(message);
this.currentStore.messageList = this.currentStore.messageList.filter((item: any) => item.ID !== message.ID);
this.currentStore.messageList.push(imResponse.data.message);
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 重发消息
* resend message
*
* @param {message} message 消息实例/message
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L764-L775 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.deleteMessage | public deleteMessage(messages: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.deleteMessage(messages);
resolve(imResponse);
const middleData = this.currentStore.messageList;
this.currentStore.messageList = [];
this.currentStore.messageList = middleData;
} catch (error) {
reject(error);
}
});
} | /**
* 删除消息
* delete message
*
* @param {Array.<message>} messages 消息实例/message
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L784-L796 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.modifyMessage | public modifyMessage(message: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.modifyMessage(message);
resolve(imResponse);
} catch (error) {
// 修改消息失败
// Modify message error
const code = (error as any)?.code;
const data = (error as any)?.data;
if (code === 2480) {
console.warn('MODIFY_MESSAGE_ERROR', '修改消息发生冲突,data.message 是最新的消息', 'data.message:', data?.message);
} else if (code === 2481) {
console.warn('MODIFY_MESSAGE_ERROR', '不支持修改直播群消息');
} else if (code === 20026) {
console.warn('MODIFY_MESSAGE_ERROR', '消息不存在');
}
reject(error);
}
})
} | /**
* 变更消息
* modify message
*
* @param {Array.<message>} message 消息实例/message
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L805-L825 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.replyMessage | public replyMessage(message: any, messageRoot?: any): Promise<any> {
const replyFunction = () => {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const repliesObject = {
messageAbstract: message?.payload?.text,
messageSender: message?.from,
messageID: message?.ID,
messageType: message?.type,
messageTime: message?.time,
messageSequence: message?.sequence,
version: 1,
}
if (!messageRoot) {
const cloudCustomData = JSONToObject(message?.cloudCustomData);
const messageRootID = cloudCustomData?.messageReply?.messageRootID;
messageRoot = await this?.currentStore?.messageList?.find((item: any) => item?.ID === messageRootID) || this.findMessage(messageRootID);
}
const rootCloudCustomData = messageRoot?.cloudCustomData ? JSONToObject(messageRoot?.cloudCustomData) : { messageReplies: {} };
if (rootCloudCustomData?.messageReplies?.replies) {
rootCloudCustomData.messageReplies.replies = [...rootCloudCustomData?.messageReplies?.replies, repliesObject];
} else {
rootCloudCustomData.messageReplies = { replies: [repliesObject], version: 1 }
}
messageRoot.cloudCustomData = JSON.stringify(rootCloudCustomData);
const imResponse = this.modifyMessage(messageRoot);
resolve(imResponse);
} catch (error) {
reject(error);
}
})
}
const retryBreakFunction = function (error: any) {
if (error && error?.code === 2480) return false;
return true;
}
return this.handlePromiseCallbackRetry(replyFunction, [500, 1000, 3000], retryBreakFunction);
} | /**
* 回复消息
* reply message
* @param {Array.<message>} message 消息实例/message
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L832-L869 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.revokeReplyMessage | public revokeReplyMessage(message: any, messageRoot?: any): Promise<any> {
const revokeReplyFunction = () => {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
if (!messageRoot) {
const cloudCustomData = JSONToObject(message?.cloudCustomData);
const messageRootID = cloudCustomData?.messageReply?.messageRootID;
messageRoot = await this?.currentStore?.messageList?.find((item: any) => item?.ID === messageRootID) || this.findMessage(messageRootID);
}
const rootCloudCustomData = messageRoot?.cloudCustomData ? JSONToObject(messageRoot?.cloudCustomData) : { messageReplies: {} };
if (rootCloudCustomData?.messageReplies?.replies) {
const index = rootCloudCustomData.messageReplies.replies.findIndex((item: any) => item?.messageID === message?.ID);
rootCloudCustomData?.messageReplies?.replies?.splice(index, 1);
}
messageRoot.cloudCustomData = JSON.stringify(rootCloudCustomData);
const imResponse = this.modifyMessage(messageRoot);
resolve(imResponse);
} catch (error) {
reject(error);
}
})
}
const retryBreakFunction = function (error: any) {
if (error && error?.code === 2480) return false;
return true;
}
return this.handlePromiseCallbackRetry(revokeReplyFunction, [500, 1000, 3000], retryBreakFunction);
} | /**
* 撤回回复消息
* revoke reply message
* @param {Array.<message>} message 消息实例/message
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L877-L904 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.emojiReact | public emojiReact(message: any, emojiID: any): Promise<any> {
const emojiReactFunction = () => {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
if (!message || !message?.ID || !emojiID) reject();
const userID = this.TUICore?.TUIServer?.TUIProfile?.store?.profile?.userID;
message = await this?.currentStore?.messageList?.find((item: any) => item?.ID === message?.ID) || this.findMessage(message?.ID);
const cloudCustomData = message?.cloudCustomData ? JSONToObject(message?.cloudCustomData) : { messageReact: {} };
if (cloudCustomData?.messageReact?.reacts) {
if (cloudCustomData?.messageReact?.reacts[emojiID]) {
const index = cloudCustomData?.messageReact?.reacts[emojiID]?.indexOf(userID);
if (index === -1) {
cloudCustomData?.messageReact?.reacts[emojiID]?.push(userID);
} else {
cloudCustomData?.messageReact?.reacts[emojiID]?.splice(index, 1);
if (cloudCustomData?.messageReact?.reacts[emojiID]?.length === 0) {
delete cloudCustomData?.messageReact?.reacts[emojiID];
}
}
} else {
cloudCustomData.messageReact.reacts[emojiID] = [userID];
}
} else {
cloudCustomData.messageReact = {
reacts: {},
version: 1
}
cloudCustomData.messageReact.reacts[emojiID] = [userID];
}
message.cloudCustomData = JSON.stringify(cloudCustomData);
const imResponse = this.modifyMessage(message);
resolve(imResponse);
} catch (error) {
reject(error);
}
})
}
const retryBreakFunction = function (error: any) {
if (error && error?.code === 2480) return false;
return true;
}
return this.handlePromiseCallbackRetry(emojiReactFunction, [500, 1000, 3000], retryBreakFunction);
} | /**
* 表情回应
* emoji react
* @param {Array.<message>} message 消息实例/message
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L912-L954 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.findMessage | public findMessage(messageID: string): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.findMessage(messageID);
resolve(imResponse);
} catch (error) {
reject(error);
}
})
} | /**
* 查询消息
* find message
* @param {String} messageID 消息实例ID/messageID
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L963-L972 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.getGroupProfile | public getGroupProfile(options: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.getGroupProfile(options);
this.currentStore.conversation.groupProfile = imResponse.data.group;
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 获取群组属性
* get group profile
*
* @param {any} options 参数
* @param {String} options.groupID 群组ID
* @param {Array.<String>} options.groupProfileFilter 群资料过滤器
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L983-L993 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.getGroupMemberProfile | public getGroupMemberProfile(options: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.getGroupMemberProfile(options);
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 获取群成员资料
* get group member profile
*
* @param {any} options 参数
* @param {String} options.groupID 群组ID
* @param {Array.<String>} options.userIDList 要查询的群成员用户 ID 列表
* @param { Array.<String>} options.memberCustomFieldFilter 群成员自定义字段筛选
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L1005-L1014 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.handleGroupApplication | public handleGroupApplication(options: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.handleGroupApplication(options);
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 处理申请加群
* handling group application
* - 管理员
* administrator
*
* @param {any} options 参数
* @param {String} options.handleAction 处理结果 Agree(同意) / Reject(拒绝)
* @param {String} options.handleMessage 附言
* @param {Message} options.message 对应【群系统通知】的消息实例
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L1028-L1037 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.getUserProfile | public async getUserProfile(userIDList: Array<string>) {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.getUserProfile({ userIDList });
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 获取其他用户资料
* get user profile
*
* @param {Array<string>} userIDList 用户的账号列表/userID list
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L1046-L1055 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.getFriendList | public async getFriendList(): Promise<void> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.getFriendList();
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 获取 SDK 缓存的好友列表
* Get the friend list cached by the SDK
*
* @param {Array<string>} userIDList 用户的账号列表
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L1064-L1073 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.checkFriend | public async checkFriend(userID: string, type: string): Promise<void> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.checkFriend({ userIDList: [userID], type });
const isFriendShip = imResponse?.data?.successUserIDList[0]?.relation;
resolve(isFriendShip);
} catch (error) {
reject(error);
}
});
} | /**
* 校验好友关系
* check friend
*
* @param {string} userID 用户账号
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L1082-L1092 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.getGroupReadMemberList | public async getGroupReadMemberList(message: any, cursor = '', count = 15): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.getGroupMessageReadMemberList({
message,
filter: 0,
cursor,
count,
});
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 获取群消息已读成员列表
* Get the list of memebers who have read the group message.
*
* @param {message} message 消息实例/message
* @param {string} cursor 分页拉取的游标,第一次拉取传''/Paging pull the cursor,first pull pass ''
* @param {number} count 分页拉取的个数/The number of page pulls
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L1103-L1117 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.getGroupUnreadMemberList | public async getGroupUnreadMemberList(message: any, cursor = '', count = 15): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.getGroupMessageReadMemberList({
message,
filter: 1,
cursor,
count,
});
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 获取群消息未读成员列表
* Get the list of memebers who have not read the group message.
*
* @param {message} message 消息实例/message
* @param {string} cursor 分页拉取的游标,第一次拉取传''/Paging pull the cursor,first pull pass ''
* @param {number} count 分页拉取的个数/The number of page pulls
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L1128-L1142 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.handleMessageSentByMeToView | public async handleMessageSentByMeToView(message: any) {
if (message?.conversationID === this?.store?.conversation?.conversationID) {
this.currentStore.messageList.push(message);
}
return;
} | /**
* 自己发送消息上屏显示
*
* @param {message} message 消息实例/message
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L1149-L1154 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIChatServer.bind | public bind(params: any) {
return (this.currentStore = params);
} | /**
* 赋值
* bind
*
* @param {Object} params 使用的数据/params
* @returns {Object} 数据/data
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIChat/server.ts#L1172-L1174 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.destroyed | public destroyed() {
this.unbindTIMEvent();
} | /**
* 组件销毁
* destroy
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L27-L29 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.updateStore | updateStore(newValue: any, oldValue: any) {
this.currentStore.groupList = newValue.groupList;
this.currentStore.searchGroup = newValue.searchGroup;
this.currentStore.systemConversation = newValue.systemConversation;
this.currentStore.systemMessageList = newValue.systemMessageList;
} | /**
* 数据监听回调
* data listener callback
*
* @param {any} newValue 新数据/new value
* @param {any} oldValue 旧数据/old value
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L38-L43 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.bindTIMEvent | private bindTIMEvent() {
this.TUICore.tim.on(this.TUICore.TIM.EVENT.GROUP_LIST_UPDATED, this.handleGroupListUpdated, this);
this.TUICore.tim.on(this.TUICore.TIM.EVENT.GROUP_ATTRIBUTES_UPDATED, this.handleGroupAttributesUpdated, this);
this.TUICore.tim.on(this.TUICore.TIM.EVENT.CONVERSATION_LIST_UPDATED, this.handleConversationListUpdate, this);
this.TUICore.tim.on(this.TUICore.TIM.EVENT.FRIEND_LIST_UPDATED, this.handleFriendListUpdated, this);
this.TUICore.tim.on(this.TUICore.TIM.EVENT.USER_STATUS_UPDATED, this.handleUserStatusUpdated, this);
} | /**
* /////////////////////////////////////////////////////////////////////////////////
* //
* // TIM 事件监听注册接口
* // TIM Event listener registration interface
* //
* /////////////////////////////////////////////////////////////////////////////////
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L54-L60 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.handlePromiseCallback | public handlePromiseCallback(callback: any) {
return new Promise<void>((resolve, reject) => {
const config = {
TUIName: 'TUIContact',
callback: () => {
callback && callback(resolve, reject);
},
};
this.TUICore.setAwaitFunc(config.TUIName, config.callback);
});
} | /**
* 处理异步函数
* Handling asynchronous functions
*
* @param {callback} callback 回调函数/callback
* @returns {Promise} 返回异步函数/return callback
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L115-L125 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.handleFilterSystem | private handleFilterSystem(list: any) {
const options = {
allConversationList: list,
systemConversationList: [],
};
options.systemConversationList = list.filter((item: any) => item.type === this.TUICore.TIM.TYPES.CONV_SYSTEM);
this.store.allConversationList = options.allConversationList;
this.store.systemConversationList = options.systemConversationList;
const [systemConversation] = options.systemConversationList;
this.store.systemConversation = systemConversation;
return options;
} | /**
* 处理conversationList
* Handle conversation list
*
* @param {Array} list conversationList
* @returns {Object}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L134-L145 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.getConversationList | public async getConversationList() {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.getConversationList();
this.handleFilterSystem(imResponse.data.conversationList);
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /*
* 获取 conversationList
* Get conversation list
*
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L162-L172 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.getSystemMessageList | public async getSystemMessageList() {
// console.log('是否进入::>>',);
if(this.store.systemConversation !== undefined){
const options = {
conversationID: this.store.systemConversation.conversationID,
count: 15,
};
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.getMessageList(options);
this.store.systemMessageList = imResponse.data.messageList;
resolve(imResponse);
} catch (error) {
reject(error);
}
});
}else{
return {}
}
} | /**
* 获取系统通知 messageList
* Get system messages
*
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L180-L200 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.setMessageRead | public async setMessageRead() {
if(this.store.systemConversation !== undefined){
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse: any = await this.TUICore.tim.setMessageRead({
conversationID: this.store.systemConversation.conversationID,
});
resolve(imResponse);
} catch (error) {
reject(error);
}
});
}else{
return {}
}
} | /**
* 设置已读
* Set message read
*
* @param {string} conversationID 会话ID/ conversation's ID
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L209-L225 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.getGroupList | public async getGroupList(options?: any) {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
let imResponse: any = {};
if (!options) {
imResponse = await this.TUICore.tim.getGroupList();
} else {
imResponse = await this.TUICore.tim.getGroupList(options);
}
this.store.groupList = imResponse.data.groupList;
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 获取群组列表
* Get group list
*
* @param {any} options 参数/options
* @param {Array.<String>} options.groupProfileFilter 群资料过滤器/group profile filter
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L235-L250 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.getGroupProfile | public getGroupProfile(options: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.getGroupProfile(options);
this.store.groupList = imResponse.data.groupList;
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 获取群组属性
* Get group profile
*
* @param {any} options 参数/options
* @param {String} options.groupID 群组ID/group's ID
* @param {Array.<String>} options.groupProfileFilter 群资料过滤器/group profile filter
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L261-L271 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.dismissGroup | public dismissGroup(groupID: string): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.dismissGroup(groupID);
this.store.groupProfile = imResponse.data.group;
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 删除群组
* Dismiss group
*
* @param {String} groupID 群组ID/group's ID
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L280-L290 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.updateGroupProfile | public updateGroupProfile(options: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.updateGroupProfile(options);
this.store.groupProfile = imResponse.data.group;
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 修改群组资料
* Update group profile
*
* @param {any} options 参数/params options
* @param {String} options.groupID 群组ID/group's ID
* @param {String} options.name 群组名称/group's name
* @param {String} options.introduction 群简介/group's introduction
* @param {String} options.notification 群公告/group's notification
* @param {String} options.avatar 群头像 URL/group's avatar url
* @param {Number} options.maxMemberNum 最大群成员数量/the max number of group's member
* @param {Number} options.joinOption 申请加群处理方式/group's join options
* @param {Array.<Object>} options.groupCustomField 群组维度的自定义字段/custom fields for group dimensions
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L307-L317 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.joinGroup | public joinGroup(options: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.joinGroup(options);
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 申请加群
* Join group
*
* @param {any} options 参数/options
* @param {String} options.groupID 群组ID/group's ID
* @param {String} options.applyMessage 附言/apply message
* @param {String} options.type 群组类型/group's type
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L329-L338 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.quitGroup | public quitGroup(groupID: string): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.quitGroup(groupID);
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 退出群组
* Quit group
*
* @param {String} groupID 群组ID/group's ID
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L347-L356 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.searchGroupByID | public searchGroupByID(groupID: string): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.searchGroupByID(groupID);
this.store.searchGroup = imResponse.data.group;
resolve(imResponse);
} catch (error) {
this.store.searchGroup = {};
reject(error);
}
});
} | /**
* 通过 groupID 搜索群组
* Search group by group's ID
*
* @param {String} groupID 群组ID/group's ID
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L365-L376 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.handleGroupApplication | public handleGroupApplication(options: any): Promise<any> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.handleGroupApplication(options);
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 处理申请加群
* Handle group application
* - 管理员/administrator
*
* @param {any} options 参数/options
* @param {String} options.handleAction 处理结果 Agree(同意) / Reject(拒绝)
* @param {String} options.handleMessage 附言/apply message
* @param {Message} options.message 对应【群系统通知】的消息实例/the message corresponding to 【group system notification】
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L389-L398 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.getFriendList | public async getFriendList(): Promise<void> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
const imResponse = await this.TUICore.tim.getFriendList();
this.currentStore.friendList = imResponse.data;
this.currentStore.userIDList = this.currentStore.friendList.map((item: any) => item.userID) || [];
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 获取 SDK 缓存的好友列表
* Get friend list from SDK
*
* @param {Array<string>} userIDList 用户的账号列表/userID list
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L407-L418 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.getUserStatus | public async getUserStatus(userIDList: Array<string>): Promise<void> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
if (!userIDList.length) return;
const imResponse = await this.TUICore.tim.getUserStatus({ userIDList });
imResponse?.data?.successUserList?.forEach((item: any) => {
if (item && item?.userID) {
this.currentStore?.userStatusList?.set(item?.userID, {
statusType: item?.statusType,
customStatus: item?.customStatus,
});
this.TUICore?.TUIServer?.TUIConversation?.currentStore?.userStatusList?.set(item?.userID, {
statusType: item?.statusType,
customStatus: item?.customStatus,
});
}
});
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 获取 用户状态
* Get users’ status
*
* @param {Array<string>} userIDList 用户 userID 列表 / userID list
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L427-L449 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.subscribeUserStatus | public async subscribeUserStatus(userIDList: Array<string>): Promise<void> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
if (!userIDList.length) return;
const imResponse = await this.TUICore.tim.subscribeUserStatus({ userIDList });
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 订阅 用户状态
* Subscribe users' status
*
* @param {Array<string>} userIDList 用户 userID 列表 / userID list
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L458-L468 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
workbench | github_2023 | yhtt2020 | typescript | TUIContactServer.unsubscribeUserStatus | public async unsubscribeUserStatus(userIDList?: Array<string>): Promise<void> {
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
try {
if (userIDList && !userIDList.length) return;
const imResponse = await this.TUICore.tim.unsubscribeUserStatus({ userIDList });
this.currentStore?.userStatusList?.clear();
resolve(imResponse);
} catch (error) {
reject(error);
}
});
} | /**
* 取消订阅 用户状态
* Unscribe users' status
*
* @param {Array<string>} userIDList 用户 userID 列表 / userID list
* @returns {Promise}
*/ | https://github.com/yhtt2020/workbench/blob/3d30910f185bdd2f72c14bff51d39fb2e774dd0a/vite/packages/table/TUIKit/TUIComponents/container/TUIContact/server.ts#L477-L488 | 3d30910f185bdd2f72c14bff51d39fb2e774dd0a |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.