public void JoinChat(int chatId, int profileId, string clientId) { object callbackObj = OperationContext.Current.GetCallbackChannel <IMessageCallBack>(); IMessageCallBack callback = (IMessageCallBack)callbackObj; if (chatController.JoinChat(chatId, profileId, callbackObj, clientId)) { Chat chat = chatController.FindChat(chatId); List <Tuple <object, int, string> > callbacks = new List <Tuple <object, int, string> >(); List <Profile> profiles = new List <Profile>(); foreach (var tuple in chat.Users) { profiles.Add(tuple.Item1); if (tuple.Item2 != null) { callbacks.Add(new Tuple <object, int, string>(tuple.Item2, tuple.Item1.ProfileID, tuple.Item3)); } } callback.GetChat(chat, clientId); callback.GetMessages(messageController.GetMessages(chatId), clientId); callback.GetOnlineProfiles(profiles, clientId); callback.Show(true, clientId); foreach (Tuple <object, int, string> messageCallBack in callbacks) { try { callback = (IMessageCallBack)messageCallBack.Item1; callback.GetOnlineProfiles(profiles, clientId); } catch (Exception) { chatController.LeaveChat(chatId, messageCallBack.Item2); } } } else { callback.Show(false, clientId); } }
public void DeleteChat(int profileId, int id) { Chat chat = chatController.FindChat(id); if (chatController.DeleteChat(profileId, id)) { if (chat != null) { foreach (var tuple in chat.Users) { try { IMessageCallBack callback = (IMessageCallBack)tuple.Item2; callback.Show(false, tuple.Item3); } catch (Exception) { Offline(tuple.Item1.ProfileID); } } } } }