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 bool Invite(int chatId, string name) { Profile user = profileController.GetUser(name); if (user != null) { try { IChatCallBack chatCallback = (IChatCallBack)user.CallBack; chatCallback.Notification(chatController.FindChat(chatId)); return(true); } catch (Exception) { Offline(user.ProfileID); return(false); } } else { return(false); } }