Unsubscribe
How do I use Unsubscribe
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: ChatGui.cs
Copy
215 private void GuiSendsMsg()
216 {
217 if (string.IsNullOrEmpty(this.inputLine))
218 {
219
220 GUI.FocusControl("");
221 return;
222 }
223
224 if (this.inputLine[0].Equals('\\'))
225 {
226 string[] tokens = this.inputLine.Split(new char[] {' '}, 2);
227 if (tokens[0].Equals("\\help"))
228 {
229 this.PostHelpToCurrentChannel();
230 }
231 if (tokens[0].Equals("\\state"))
232 {
233 int newState = int.Parse(tokens[1]);
234 this.chatClient.SetOnlineStatus(newState, new string[] { "i am state " + newState }); // this is how you set your own state and (any) message
235 }
236 else if (tokens[0].Equals("\\subscribe") && !string.IsNullOrEmpty(tokens[1]))
237 {
238 this.chatClient.Subscribe(tokens[1].Split(new char[] {' ', ','}));
239 }
240 else if (tokens[0].Equals("\\unsubscribe") && !string.IsNullOrEmpty(tokens[1]))
241 {
242 this.chatClient.Unsubscribe(tokens[1].Split(new char[] {' ', ','}));
243 }
244 else if (tokens[0].Equals("\\clear"))
245 {
246 if (this.doingPrivateChat)
247 {
248 this.chatClient.PrivateChannels.Remove(this.selectedChannelName);
249 }
250 else
251 {
252 ChatChannel channel;
253 if (this.chatClient.TryGetChannel(this.selectedChannelName, this.doingPrivateChat, out channel))
254 {
255 channel.ClearMessages();
256 }
257 }
258 }
259 else if (tokens[0].Equals("\\msg") && !string.IsNullOrEmpty(tokens[1]))
260 {
261 string[] subtokens = tokens[1].Split(new char[] {' ', ','}, 2);
262 string targetUser = subtokens[0];
263 string message = subtokens[1];
264 this.chatClient.SendPrivateMessage(targetUser, message);
265 }
266 }
267 else
268 {
269 if (this.doingPrivateChat)
270 {
271 this.chatClient.SendPrivateMessage(this.userIdInput, this.inputLine);
272 }
273 else
274 {
275 this.chatClient.PublishMessage(this.selectedChannelName, this.inputLine);
276 }
277 }
278
279 this.inputLine = "";
280 GUI.FocusControl("");
281 }
File name: ChatClient.cs
Copy
245 public bool Unsubscribe(string[] channels)
246 {
247 if (!this.CanChat)
248 {
249 // TODO: log error
250 return false;
251 }
252
253 if (channels == null || channels.Length == 0)
254 {
255 this.LogWarning("Unsubscribe can't be called for empty or null cannels-list.");
256 return false;
257 }
258
259 return SendChannelOperation(channels, ChatOperationCode.Unsubscribe, 0);
260 }
File name: ChatClient.cs
Copy
576 void IPhotonPeerListener.OnEvent(EventData eventData)
577 {
578 switch (eventData.Code)
579 {
580 case ChatEventCode.ChatMessages:
581 this.HandleChatMessagesEvent(eventData);
582 break;
583 case ChatEventCode.PrivateMessage:
584 this.HandlePrivateMessageEvent(eventData);
585 break;
586 case ChatEventCode.StatusUpdate:
587 this.HandleStatusUpdate(eventData);
588 break;
589 case ChatEventCode.Subscribe:
590 this.HandleSubscribeEvent(eventData);
591 break;
592 case ChatEventCode.Unsubscribe:
593 this.HandleUnsubscribeEvent(eventData);
594 break;
595 }
596 }
File name: ChatClient.cs
Copy
598 void IPhotonPeerListener.OnOperationResponse(OperationResponse operationResponse)
599 {
600 switch (operationResponse.OperationCode)
601 {
602 case (byte)ChatOperationCode.Authenticate:
603 this.HandleAuthResponse(operationResponse);
604 break;
605
606 // the following operations usually don't return useful data and no error.
607 case (byte)ChatOperationCode.Subscribe:
608 case (byte)ChatOperationCode.Unsubscribe:
609 case (byte)ChatOperationCode.Publish:
610 case (byte)ChatOperationCode.SendPrivate:
611 default:
612 if (operationResponse.ReturnCode != 0)
613 {
614 ((IPhotonPeerListener)this).DebugReturn(DebugLevel.ERROR, string.Format("Chat Operation {0} failed (Code: {1}). Debug Message: {2}", operationResponse.OperationCode, operationResponse.ReturnCode, operationResponse.DebugMessage));
615 }
616 break;
617 }
618 }
File name: ChatClient.cs
Copy
756 private void HandleUnsubscribeEvent(EventData eventData)
757 {
758 var channelsInRequest = (string[])eventData[ChatParameterCode.Channels];
759 for (var i = 0; i < channelsInRequest.Length; i++)
760 {
761 string channelName = channelsInRequest[i];
762 this.PublicChannels.Remove(channelName);
763 }
764
765 this.listener.OnUnsubscribed(channelsInRequest);
766 }
Unsubscribe 128 lượt xem
Gõ tìm kiếm nhanh...