/// <summary> /// 构造并添加消息控件到消息窗口 /// </summary> /// <param name="message">云信IM点对点消息</param> public void addMessage(NimMessage message) { var control = new MessageBox { width = pceHistory.Width, message = message, targetHead = targetHead, Dock = DockStyle.Top }; control.play += (sender, args) => play(args.id); control.stop += (sender, args) => playing = false; pceHistory.Controls.Add(control); height = height + control.Size.Height; var time = Util.getDateTime(message.timetag); if (messageTime == DateTime.MinValue) { messageTime = time; addTime(time); } var ts = messageTime - time; if (ts.TotalMinutes > 15) { addTime(time); } pceHistory.Height = height; }
/// <summary> /// 新增消息 /// </summary> /// <param name="message">消息对象</param> public void addMessage(NimMessage message) { messages.Add(message); void action() => refresh(); while (!(Parent?.IsHandleCreated ?? false)) { Thread.Sleep(100); } Invoke((Action)action); }
/// <summary> /// 发送消息 /// </summary> /// <param name="type">消息类型</param> /// <param name="body">消息体</param> private void sendMessage(int type, object body) { var message = new NimMessage { id = Util.newId("N"), from = myId, to = targetId, type = type, direction = 0, body = body }; mlcMessage.addMessage(message); messageSend?.Invoke(this, new MessageEventArgs(message)); }
/// <summary> /// 将接收到的消息添加到消息列表 /// </summary> /// <param name="msg">云信消息数据</param> private void addMessage(NIMIMMessage msg) { var message = new NimMessage { id = msg.ClientMsgID, msgid = msg.ServerMsgId, from = msg.SenderID, to = msg.ReceiverID, type = msg.MessageType.GetHashCode(), body = NimUtil.getMsg(msg), direction = msg.SenderID == targetId ? 1 : 0, timetag = msg.TimeStamp / 1000 }; messages.Add(message); }
/// <summary> /// 发送消息 /// </summary> /// <param name="type">消息类型</param> /// <param name="body">消息体</param> private string sendMessage(int type, object body) { var id = Util.newId("N"); var message = new NimMessage { id = id, from = myId, to = target.accid, type = type, direction = 0, body = body, timetag = Util.getTimeStamp(DateTime.Now) }; mlcMessage.addMessage(message); return(id); }
/// <summary> /// 查询历史消息 /// </summary> private void getHistory() { MessagelogAPI.QueryMsglogOnline(targetId, NIMSessionType.kNIMSessionTypeP2P, 6, 0, endTime, 0, false, true, true, (code, accountId, sType, result) => { void action() { var list = result.MsglogCollection; if (list == null || list.Length == 0) { return; } foreach (var msg in list.OrderByDescending(i => i.TimeStamp)) { var message = new NimMessage { id = msg.ClientMsgID, msgid = msg.ServerMsgId, from = msg.SenderID, to = msg.ReceiverID, type = msg.MessageType.GetHashCode(), body = NimUtil.getMsg(msg), direction = msg.SenderID == targetId ? 1 : 0, timetag = msg.TimeStamp / 1000 }; addMessage(message); } if (list.Length < 6) { sbeNext.Enabled = false; sbeNext.Text = "已到达终点"; return; } endTime = list.Last().TimeStamp; } Invoke((Action)action); }); }
/// <summary> /// 构造函数 /// </summary> /// <param name="message">云信IM点对点消息</param> public MessageEventArgs(NimMessage message) { this.message = message; }
/// <summary> /// 将接收到的消息添加到消息列表 /// </summary> /// <param name="message"></param> public void addMessage(NimMessage message) { message.direction = 1; mlcMessage.addMessage(message); }