# websocket

# 1.接收消息 (假如当前消息的 from_id = 12, 当前登录用户id=17)

# 场景一: 与当前用户12处于聊天页面

  • (1) 渲染到页面

  • (2) 存储到本地存储

    • a. chatdetail_17_12

    • b. chatlist_17 (将当前会话置顶, 修改chatlist中当前会话的data和time显示)

# 场景二: 与当前用户12不处于聊天界面

  • (1) 渲染到页面 (处于paper页面, 留个接口)

  • (2) 存储到本地存储

    • a. chatdetail_17_12

    • b. chatlist_17

  • (3) (将当前会话置顶, 修改chatlist中当前会话的data和time显示 和 当前会话未读数+1)

    • c. 总未读数+1 (显示在tabbar上)

# 接收到的消息格式:

{

  to_id:1,      // 接收人 

  from_id:12,   // 发送人

  from_username:"某某",  // 发送人昵称

  from_userpic:"http://pic136.nipic.com/file/20170725/10673188_152559977000_2.jpg",

  type:"text",   // 发送类型

  data:"你好啊",  // 发送内容

  time:151235451   // 接收到的时间

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# 发送消息

  • (1) 写入存储

    • chatdetail_17__12

    • chatlist_17(将当前会话置顶,修改chatlist中当前会话的data和time显示)

  • (2) 请求ajax发送消息

  • (3) 渲染到页面(user-chat页面实现)

# 读取消息

  • (1) 写入存储

    • chatlist_17:获取将当前会话的未读数设为0,减少总未读数,渲染tabbar
上次更新: 2020/10/28 下午11:02:30