public static string GetJsonMessage(ShortMessage msg, string userId, User peer, bool dialog) { string json = "{ "; json += @"""id"": """ + msg.ID + @""", "; json += @"""from"": """ + msg.User_FromID.Username + @""", "; json += @"""fromId"": """ + msg.FromID + @""", "; json += @"""to"": """ + peer.Username + @""", "; json += @"""toId"": """ + peer.ID + @""", "; json += @"""replyToId"": """ + (msg.ReplyToID == null ? "" : msg.ReplyToID) + @""", "; json += @"""date"": " + GroupChatContext.getUnixJsonTime(msg.CreatedDate) + @", "; json += @"""self"": false, "; json += @"""text"": """ + msg.MsgText.Replace("\"", "\\\"") + @""""; if (dialog) { json += @", ""replies"": ["; if (msg.ChangedShortMessages != null) { string subjson = ""; foreach (var r in from d in msg.ChangedShortMessages orderby d.CreatedDate ascending select d) { subjson += GetJsonMessage(r, userId, peer, true) + ", "; } json += subjson.TrimEnd(" ,".ToCharArray()); } json += "]"; } json += " }"; return(json); }
public static string GetJsonUser(User user) { var member = user.ChangedUserAppMembers[0]; var cbk = (from d in member.ChangedMemberCallbacks select d).FirstOrDefault(); bool hasIcon = !string.IsNullOrEmpty(member.IconMime); string json = "{ "; json += @"""id"": """ + user.ID + @""", "; json += @"""name"": """ + user.Username + @""", "; json += @"""email"": """ + member.Email + @""", "; json += @"""active"": " + (cbk == null || cbk.IsDisconnected || cbk.ConnectionID == null ? "false" : "true") + @", "; json += @"""icon"": " + (hasIcon ? "true" : "false") + @", "; json += @"""lastActive"": " + (cbk == null ? GroupChatContext.getUnixJsonTime(member.LastActivityDate) : GroupChatContext.getUnixJsonTime(cbk.LastActiveDate)) + @""; json += " }"; return(json); }
public static string GetJsonMessage(ShortMessage msg, string userId, bool dialog, string matchId = null) { string json = "{ "; json += @"""id"": """ + msg.ID + @""", "; json += @"""from"": " + GetJsonUser(msg.User_FromID) + @", "; json += @"""to"": " + GetJsonUser(msg.User_ToID) + @", "; json += @"""replyToId"": """ + (msg.ReplyToID == null ? "" : msg.ReplyToID) + @""", "; json += @"""date"": " + GroupChatContext.getUnixJsonTime(msg.CreatedDate) + @", "; json += @"""isOffline"": " + (msg.IsNotReceived.HasValue && msg.IsNotReceived.Value ? "true" : "false") + @", "; json += @"""self"": " + (msg.FromID == userId ? "true" : "false") + @", "; json += @"""lead"": """ + GroupChatContext.GetLeadText(msg.MsgText).Replace("\"", "\\\"") + @""", "; json += @"""text"": """ + msg.MsgText.Replace("\"", "\\\"") + @""", "; json += @"""isMatch"": " + (matchId == msg.ID ? "true" : "false") + ", "; json += @"""score"": "; if (msg.ChangedShortMessageAudiences != null) { int cnt = 0; foreach (var v in msg.ChangedShortMessageAudiences) { cnt += v.VoteCount; } json += cnt; } else { json += "0"; } if (dialog) { json += @", ""replies"": [ "; if (msg.ChangedShortMessages != null) { string subjson = ""; foreach (var r in from d in msg.ChangedShortMessages orderby d.CreatedDate ascending select d) { subjson += GetJsonMessage(r, userId, true, matchId) + ", "; } json += subjson.TrimEnd(" ,".ToCharArray()) + " "; } json += "]"; } json += " }"; return(json); }
public static string GetJsonMessage(ShortMessage msg, string userId, UserGroup g, bool dialog, string matchId = null) { string json = "{ "; json += @"""id"": """ + msg.ID + @""", "; json += @"""from"": " + GetJsonUser(msg.User_FromID) + @", "; json += @"""groupNodes"": [ "; string grp = ""; string path = ""; foreach (var gn in g.DistinctString.Split('/')) { if (gn.Trim().Length > 0) { path += (path == "" ? "" : "/") + gn; grp += @"{ ""name"": """ + gn + @""", ""path"": """ + path + @""" }, "; } } if (grp != "") { json += grp.TrimEnd(" ,".ToCharArray()) + " "; } json += "], "; json += @"""groupId"": """ + g.ID + @""", "; json += @"""replyToId"": """ + (msg.ReplyToID == null ? "" : msg.ReplyToID) + @""", "; json += @"""date"": " + GroupChatContext.getUnixJsonTime(msg.CreatedDate) + @", "; json += @"""self"": " + (msg.FromID == userId ? "true" : "false") + @", "; json += @"""lead"": """ + GroupChatContext.GetLeadText(msg.MsgText).Replace("\"", "\\\"") + @""", "; json += @"""text"": """ + msg.MsgText.Replace("\"", "\\\"") + @""", "; json += @"""isMatch"": " + (matchId == msg.ID ? "true" : "false") + ", "; json += @"""score"": "; if (msg.ChangedShortMessageAudiences != null) { int cnt = 0; foreach (var v in msg.ChangedShortMessageAudiences) { cnt += v.VoteCount; } json += cnt; } else { json += "0"; } if (dialog) { json += @", ""replies"": [ "; if (msg.ChangedShortMessages != null) { string subjson = ""; foreach (var r in from d in msg.ChangedShortMessages orderby d.CreatedDate ascending select d) { subjson += GetJsonMessage(r, userId, g, true, matchId) + ", "; } json += subjson.TrimEnd(" ,".ToCharArray()) + " "; } json += "]"; } json += " }"; return(json); }