public FakeMainViewModel() { Entity entity = new Entity() { properties = new EntityProperties() { display_name = "Test", canonical_email="*****@*****.**"}, presence = new Presence() { available = false} }; CurrentUser = new User(entity); List<User> _contacts = new List<User>(); _contacts.Add(CurrentUser); Contacts = CollectionViewSource.GetDefaultView(_contacts) as ListCollectionView; }
public int Compare(User x, User y) { return x.DisplayName.CompareTo(y.DisplayName);// +x.Online.CompareTo(y.Online); }
public async Task GetSelfInfoAsync() { GetSelfInfoRequest request = new GetSelfInfoRequest() { request_header = RequestHeaderBody, }; using (HttpResponseMessage message = await _client.PostProtoJson("contacts/getselfinfo", _api_key, request)) { if (UserInformationReceived != null) { GetSelfInfoResponse response = await message.Content.ReadAsProtoJson<GetSelfInfoResponse>(); CurrentUser = new User(response.self_entity); UserInformationReceived(this, CurrentUser); } } }
async Task initializeChat() { // We first need to fetch the 'pvt' token, which is required for the // initialization request (otherwise it will return 400). HttpResponseMessage message = await _client.Execute(HangoutUri.PVT_TOKEN_URL, _initParams); string data = await message.Content.ReadAsStringAsync(); Newtonsoft.Json.Linq.JArray array = JArray.Parse(data); _initParams["pvt"] = array[1].ToString(); // Now make the actual initialization request: message = await _client.Execute(HangoutUri.CHAT_INIT_URL, _initParams); data = await message.Content.ReadAsStringAsync(); message.Dispose(); // Parse the response by using a regex to find all the JS objects, and // parsing them. Not everything will be parsable, but we don't care if // an object we don't need can't be parsed. Dictionary<string, Newtonsoft.Json.Linq.JArray> dataDictionary = Parser.ParseInitParams(data); // a this time we can not fix key as index can change. string key = null; foreach (JArray jarray in dataDictionary.Values) { try { key = jarray[0][0].ToString(); } catch { key = null; } switch (key) { case "cin:cac": _api_key = jarray[0][2].ToString(); break; case "cic:vd": _email = jarray[0][2].ToString(); // cic:vd break; case "cin:acc": if (jarray[0].Count() > 6) { _header_date = jarray[0][4].ToString(); //cin:acc _header_version = jarray[0][6].ToString(); } break; case "cin:bcsc": _header_id = jarray[0][7].ToString(); // cin:bcsc break; case "cgserp": jarray[0][0].Remove(); GetSuggestedEntitiesResponse cgserp = ProtoJsonSerializer.Deserialize<GetSuggestedEntitiesResponse>(jarray[0] as JArray); if (cgserp.response_header.status == ResponseStatus.RESPONSE_STATUS_OK) { _contacts = cgserp.contacts_you_hangout_with.contact.ToDictionary(c => c.entity.id.gaia_id, c => new User(c.entity)); } break; case "cgsirp": jarray[0][0].Remove(); GetSelfInfoResponse cgsirp = ProtoJsonSerializer.Deserialize<GetSelfInfoResponse>(jarray[0] as JArray); if (cgsirp.response_header.status == ResponseStatus.RESPONSE_STATUS_OK) { if (!string.IsNullOrEmpty(_email)) cgsirp.self_entity.properties.canonical_email = _email; CurrentUser = new User(cgsirp.self_entity); } break; case "csrcrp": jarray[0][0].Remove(); SyncRecentConversationsResponse csrcrp = ProtoJsonSerializer.Deserialize<SyncRecentConversationsResponse>(jarray[0] as JArray); if (csrcrp.response_header.status == ResponseStatus.RESPONSE_STATUS_OK) { _active_conversations = csrcrp.conversation_state.ToDictionary(c => c.conversation_id.id, c => new WTalk.Model.Conversation(c)); } break; } } // call all events if (UserInformationReceived != null) UserInformationReceived(this, CurrentUser); if (ContactListLoaded != null) ContactListLoaded(this, _contacts.Values.ToList()); if (_contacts == null || _contacts.Count == 0) { string[] participants_id = _active_conversations.Values.SelectMany(c => c._conversation.current_participant.Where(p => p.gaia_id != CurrentUser.Id).Select(p => p.gaia_id)).Distinct().ToArray(); await GetEntityByIdAsync(participants_id); } if (ConversationHistoryLoaded != null) ConversationHistoryLoaded(this, _active_conversations.Values.ToList()); data = null; dataDictionary = null; //this._timestamp = double.Parse(dataDictionary["ds:21"][0][1][4].ToString()); }
private void setPresence(User user, Presence presence) { user.SetPresence(presence); if (UserPresenceChanged != null) UserPresenceChanged(this, user); }
void _client_UserInformationLoaded(object sender, User e) { CurrentUser = _client.CurrentUser; OnPropertyChanged("CurrentUser"); }
void _client_ContactInformationReceived(object sender, User e) { reorderContacts(); }
void _client_UserInformationReceived(object sender, User e) { OnPropertyChanged("CurrentUser"); }
void _client_UserPresenceChanged(object sender, User e) { reorderContacts(); }
void _client_UserInformationLoaded(object sender, Entity e) { CurrentUser = new User(_client.CurrentUser); OnPropertyChanged("CurrentUser"); }