# dcd-im

> im

Latest version **1.0.5** (published 2019-09-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install dcd-im
pnpm add dcd-im
yarn add dcd-im
bun add dcd-im
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2019-09-29 |
| First published | 2019-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 73.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | chenxuehui |
| Maintainers | mediocal |
| Keywords | im |

## Links

- npm: https://www.npmjs.com/package/dcd-im
- Repository: https://github.com/MEDIOCAL/freeMock.js
- Homepage: http://gitlab.alibaba-inc.com/front_web/khb-im/blob/master/README.md
- Issues: http://gitlab.alibaba-inc.com/front_web/khb-im/issues
- npm.io page: https://npm.io/package/dcd-im

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2019-09-29
- 1.0.4 — 2019-09-29
- 1.0.3 — 2019-09-29
- 1.0.2 — 2019-09-29
- 1.0.1 — 2019-09-29
- 1.0.0 — 2019-09-26

## README

1. 在分发消息的时候，无论在初始化时在消息列表，还是 poll 分发的新会话都必须调用 open 接口，所以 updateConversationList 函数改为异步。
```
async updateConversationList(data, init = true, key = 'conversationId') {
    const inits = [];
    for (const item of data) {
        this.index++;
        item.index = this.index;
        if (!this.conversationList[item[key]]) {
            const conversation = new Conversation(item);
            this.conversationList[item[key]] = conversation;
            if (init) {
                inits.push(this.conversationList[item[key]].init(this.initConversation));
            }
        }
    }
    await Promise.all(inits);
    this.updateConversations(this.conversationList);
    return this;
}
```
使用方式 
```
await window.IM.updateConversationList(message);
window.IM.updateConversationList(message).then();
```
2. 当 poll 到会话列表的时候，分发消息的顺序要保证， 先分发新会话，再分发消息，再移除会话。
```
// 分发消息
    async dispatch(message) {
        if (message) {
            message = message.map(val => ({
                ...val.msg,
                id: val.id,
                msgId: val.msg.id,
                type: val.type,
                guest: val.guest,
                ip: val.ip,
            }));
            const chatmessage = message.filter(val => val.type === 1);
            const conversations = message.filter(val => val.type === 2);
            const endTalks = message.filter(val => val.type === 3);
            await addConversation.call(this, conversations);
            dispatchMessage.call(this, chatmessage);
            removeConversation.call(this, endTalks);
        }
    }
```

3.对 poll 函数做了优化，内部自行判断是否在 polling 阶段，如果在，再次调用 poll 函数无效。

---
_Source: https://npm.io/package/dcd-im · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
