internal void CreatePNMessageResult(SubscribeMessage subscribeMessage, out PNMessageResult messageResult) { long timetoken = (subscribeMessage.PublishTimetokenMetadata != null) ? subscribeMessage.PublishTimetokenMetadata.Timetoken : 0; long originatingTimetoken = (subscribeMessage.OriginatingTimetoken != null) ? subscribeMessage.OriginatingTimetoken.Timetoken : 0; messageResult = new PNMessageResult( subscribeMessage.SubscriptionMatch.Replace(Utility.PresenceChannelSuffix, ""), subscribeMessage.Channel.Replace(Utility.PresenceChannelSuffix, ""), subscribeMessage.Payload, timetoken, originatingTimetoken, subscribeMessage.UserMetadata, subscribeMessage.IssuingClientId ); }
protected bool CreateFetchMessagesResult(object objChannelsDict, out Dictionary <string, List <PNMessageResult> > channelsResult) { Dictionary <string, object> channelsDict = objChannelsDict as Dictionary <string, object>; channelsResult = new Dictionary <string, List <PNMessageResult> >(); if (channelsDict != null) { foreach (KeyValuePair <string, object> kvpair in channelsDict) { string channelName = kvpair.Key; #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateFetchMessagesResult: \nChannel {0}", channelName), PNLoggingMethod.LevelInfo); #endif if (channelsResult.ContainsKey(channelName)) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateFetchMessagesResult: Channel name {0} exists in dict, continuing.", channelName), PNLoggingMethod.LevelInfo); #endif continue; } object[] channelDetails = kvpair.Value as object[]; #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateFetchMessagesResult: channelDetails {0}", channelDetails.Length), PNLoggingMethod.LevelInfo); #endif List <PNMessageResult> lstMessageResult = new List <PNMessageResult>(); foreach (object messageData in channelDetails) { Dictionary <string, object> messageDataDict = messageData as Dictionary <string, object>; if (messageDataDict != null) { object objPayload; messageDataDict.TryGetValue("message", out objPayload); object meta; if (messageDataDict.TryGetValue("meta", out meta)) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateFetchMessagesResult: meta {0}.", meta.ToString()), PNLoggingMethod.LevelInfo); #endif } object objTimetoken; long timetoken = 0; if (messageDataDict.TryGetValue("timetoken", out objTimetoken)) { if (long.TryParse(objTimetoken.ToString(), out timetoken)) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateFetchMessagesResult: timetoken {0}.", timetoken.ToString()), PNLoggingMethod.LevelInfo); #endif } } if (!string.IsNullOrEmpty(this.PubNubInstance.PNConfig.CipherKey) && (this.PubNubInstance.PNConfig.CipherKey.Length > 0)) { //TODO: handle exception objPayload = Helpers.DecodeMessage(this.PubNubInstance.PNConfig.CipherKey, objPayload, OperationType, this.PubNubInstance); } PNMessageResult pnMessageResult = new PNMessageResult( channelName, channelName, objPayload, timetoken, timetoken, meta, "" ); object objMessageType; if (messageDataDict.TryGetValue("message_type", out objMessageType)) { int messageType; if (int.TryParse(objMessageType.ToString(), out messageType)) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateFetchMessagesResult: messageType {0}.", messageType.ToString()), PNLoggingMethod.LevelInfo); #endif } pnMessageResult.MessageType = messageType; } object objUUID; if (messageDataDict.TryGetValue("uuid", out objUUID)) { pnMessageResult.IssuingClientId = objUUID.ToString(); } pnMessageResult.MessageActions = MessageActionsHelpers.ExtractMessageActions(messageDataDict); lstMessageResult.Add(pnMessageResult); } } channelsResult.Add(channelName, lstMessageResult); } return(true); } return(false); }