public FormChat(IClient client, ChatDataModel.Account account, IAudioCall phoneCall) { InitializeComponent(); _client = client; _user = account; Stream imageMe, imageFriend; string myName = ""; lock (this) { imageMe = GoogleDriveFilesRepository.DownloadFile(Util.Instance.CurrentUser.AvatarDriveID); myName = Util.Instance.CurrentUser.Name; } imageFriend = GoogleDriveFilesRepository.DownloadFile(_user.AvatarDriveID); _ptbFriendsAvatar.Image = Image.FromStream(imageFriend); _ptbFriendsAvatar.SizeMode = PictureBoxSizeMode.StretchImage; _lbFriendsName.Text = _user.Name; authorMe = new Author(Image.FromStream(imageMe), myName); authorFriend = new Author(Image.FromStream(imageFriend), _user.Name); _rcChatlog.Author = authorMe; //gửi yêu cầu lấy lịch sử chat _client.RequestGetHistory(Util.Instance.CurrentUser.Email, _user.Email); _rcChatlog.ChatElement.ShowToolbarButtonElement.Click += ShowToolbarButtonElement_Click; _rcChatlog.ChatElement.SendButtonElement.Click += SendButtonElement_Click; _rcChatlog.CardActionClicked += _rcChatlog_CardActionClicked; _rcChatlog.ChatElement.MessagesViewElement.BackColor = Color.White; _rcChatlog.AutoScroll = false; _phoneCall = phoneCall; _phoneCall.CallStateChange += _phoneCall_CallStateChange; }
private static void ListFiles(DriveService service, ref string pageToken) { // Define parameters of request. FilesResource.ListRequest listRequest = service.Files.List(); listRequest.Fields = "nextPageToken, files(id, name)"; listRequest.PageToken = pageToken; listRequest.Spaces = "drive"; listRequest.Q = "'10TVA8fya_XoPa0nwg7m2WPsqh_scfyK4' in parents"; //listRequest.Q = "'root' in parents"; request = listRequest.Execute(); if (request.Files != null && request.Files.Count > 0) { foreach (var file in request.Files) { GoogleDriveFilesRepository.DownloadFile(service, file); test.Add(new FileDetails() { FileID = file.Id, FileName = file.Name }); } pageToken = request.NextPageToken; } else { MessageBox.Show("No Files Found"); } }
public void ReceiveMediaMessage(ChatDataModel.ChatMessage message) { var stream = GoogleDriveFilesRepository.DownloadFile(message.ImageMessageDriveID); var img = Image.FromStream(stream); var displayImage = ResizeImagePercentage(img); ChatMediaMessage mess = new ChatMediaMessage(displayImage, displayImage.Size, null, authorFriend, message.TimeSend); _rcChatlog.AddMessage(mess); }
public void LoadHistory() { foreach (var item in messages) { if (item.ImageMessageDriveId != "") { var download = GoogleDriveFilesRepository.DownloadFile(item.ImageMessageDriveId); var img = ResizeImagePercentage(Image.FromStream(download)); if (item.Sender == _me.Email) { ChatMediaMessage mess = new ChatMediaMessage(img, img.Size, "", _authorMe, item.TimeSend); _radchatChatGroup.AddMessage(mess); } else if (item.Sender != _me.Email) { Author auth; if (_authorFriends.TryGetValue(item.Sender, out auth)) { ChatMediaMessage mess = new ChatMediaMessage(img, img.Size, "", auth, item.TimeSend); _radchatChatGroup.AddMessage(mess); } else { Author author = new Author(null, item.Sender); ChatMediaMessage mess = new ChatMediaMessage(img, img.Size, "", author, item.TimeSend); _radchatChatGroup.AddMessage(mess); } } } else if (item.Message != "") { if (item.Sender == _me.Email) { ChatTextMessage mess = new ChatTextMessage(item.Message, _authorMe, item.TimeSend); _radchatChatGroup.AddMessage(mess); } else if (item.Sender != _me.Email) { Author auth; if (_authorFriends.TryGetValue(item.Sender, out auth)) { ChatTextMessage mess = new ChatTextMessage(item.Message, auth, item.TimeSend); _radchatChatGroup.AddMessage(mess); } else { Author author = new Author(null, item.Sender); ChatTextMessage mess = new ChatTextMessage(item.Message, author, item.TimeSend); _radchatChatGroup.AddMessage(mess); } } } } _isLoadHistory = true; }
private void LoadMyAvatar(string fileId) { Stream result = null; Thread thread = new Thread(delegate() { result = GoogleDriveFilesRepository.DownloadFile(fileId); _authorMe.Avatar = Image.FromStream(result); }); thread.Start(); }
public void UpdateAvatar(string driveFileId) { Thread thread = new Thread(delegate() { var file = GoogleDriveFilesRepository.DownloadFile(driveFileId); _ptbAvatar.SizeMode = PictureBoxSizeMode.StretchImage; _ptbAvatar.Image = Image.FromStream(file); }); thread.Start(); }
private void _radLVFriendRequest_ItemDataBound(object sender, ListViewItemEventArgs e) { Thread thread = new Thread(delegate() { var image = Image.FromStream(GoogleDriveFilesRepository.DownloadFile(((ChatDataModel.Account)e.Item.DataBoundItem).AvatarDriveID)); _radlvFriendList.Invoke(new MethodInvoker(delegate() { e.Item.Image = ImageConverter.ImageResize.ResizeImageCircle(image, 42); })); }); thread.Start(); }
private void Init() { //_ptbChinhSua.BackColor = Color.FromArgb(200, 255, 255, 255); _lbUserName.Text = _account.Name; Thread thread = new Thread(delegate() { var file = GoogleDriveFilesRepository.DownloadFile(_account.AvatarDriveID); _ptbAvatar.SizeMode = PictureBoxSizeMode.StretchImage; _ptbAvatar.Image = Image.FromStream(file); }); thread.Start(); _radlvFriendList.AllowEdit = false; _radlvFriendList.AllowRemove = false; _radlvFriendList.VisualItemCreating += VisualItemCreating; _radlvFriendList.ItemDataBound += _radlvFriendList_ItemDataBound; _radlvFriendList.ItemSize = new Size(_radlvFriendList.ItemSize.Width, 50); _radlvFriendList.ItemMouseClick += _radlvFriendList_ItemMouseClick; _radlvFriendList.ItemMouseDown += _radlvFriendList_ItemMouseDown; _btnCreateGroupChat.AutoSizeMode = AutoSizeMode.GrowAndShrink; _btnCreateGroupChat.Click += _btnCreateGroupChat_Click; _btnAddFriend.Click += _btnAddFriend_Click; _radLVFriendRequest.ItemMouseClick += _radLVFriendRequest_ItemMouseClick; InitGroupsChat(); InitListFriendRequest(); if (!_client.IsSending) { SendRequestGetListGroup(); } if (!_client.IsSending) { _client.RequestGetListFriendRequest(_account.Email); } if (!_client.IsSending) { _client.RequsetGetListFriend(_account.Email); } _client.RequestGetListFriendIRequest(_account.Email); }
public void ReceiveTextMessage(ChatDataModel.ChatMessage message) { if (!string.IsNullOrEmpty(message.ImageMessageDriveID)) { var stream = GoogleDriveFilesRepository.DownloadFile(message.ImageMessageDriveID); var img = Image.FromStream(stream); ChatMediaMessage mess = new ChatMediaMessage(img, new Size(128, 128), null, authorFriend, message.TimeSend); _rcChatlog.AddMessage(mess); return; } else { ChatTextMessage mess = new ChatTextMessage(message.Message, authorFriend, message.TimeSend); _rcChatlog.AddMessage(mess); } }
private void _radLVListFriendInGroup_ItemDataBound(object sender, ListViewItemEventArgs e) { Thread thread = new Thread(delegate() { var image = Image.FromStream(GoogleDriveFilesRepository.DownloadFile(((Account)e.Item.DataBoundItem).AvatarDriveID)); lock (this) { _authorFriends.Add(((Account)e.Item.DataBoundItem).Email, new Author(image, ((Account)e.Item.DataBoundItem).Name)); } _radLVListFriendInGroup.Invoke(new MethodInvoker(delegate() { e.Item.Image = ImageConverter.ImageResize.ResizeImageCircle(image, 23); })); }); thread.Priority = ThreadPriority.Highest; thread.Start(); }
private void _radlvFriendList_ItemDataBound(object sender, ListViewItemEventArgs e) { try { Thread thread = new Thread(delegate() { var image = Image.FromStream(GoogleDriveFilesRepository.DownloadFile(((ChatDataModel.Account)e.Item.DataBoundItem).AvatarDriveID)); _radlvFriendList.Invoke(new MethodInvoker(delegate() { e.Item.Image = ImageConverter.ImageResize.ResizeImageCircle(image, 46); })); }); thread.Start(); } catch { MessageBox.Show("không có kết nổi , xin kiểm tra lại internet!"); _radlvFriendList_ItemDataBound(sender, e); } }
public void ReceiveMessage(ChatGroupMessage message) { Author auth; if (!_authorFriends.TryGetValue(message.Sender, out auth)) { return; } if (message.Message != "") { var mess = new ChatTextMessage(message.Message, auth, message.TimeSend); _radchatChatGroup.AddMessage(mess); } else if (message.ImageMessageDriveId != "") { var download = GoogleDriveFilesRepository.DownloadFile(message.ImageMessageDriveId); var image = Image.FromStream(download); var displayImage = ResizeImagePercentage(image); var mess = new ChatMediaMessage(displayImage, displayImage.Size, null, auth, message.TimeSend); _radchatChatGroup.AddMessage(mess); } }
public FormInCall(IAudioCall phoneCall, Account account) { InitializeComponent(); _phoneCall = phoneCall; _account = account; _lbName.Text = _account.Name; _ptbAvatar.SizeMode = PictureBoxSizeMode.StretchImage; _timerThoiLuongCuocGoi.Interval = 1000; _timerThoiLuongCuocGoi.Start(); _timerThoiLuongCuocGoi.Tick += _timerThoiLuongCuocGoi_Tick; Thread thread = new Thread(delegate() { var image = Image.FromStream(GoogleDriveFilesRepository.DownloadFile((_account.AvatarDriveID))); _ptbAvatar.Invoke(new MethodInvoker(delegate() { _ptbAvatar.Image = ImageConverter.ImageResize.ResizeImageCircle(image, 70); })); }); thread.Start(); }
public void AddMessageHistory() { var me = Util.Instance.CurrentUser.Email; foreach (var item in AllMessage) { if (item.ImageMessageDriveID != "") { var image = GoogleDriveFilesRepository.DownloadFile(item.ImageMessageDriveID); var displayImage = ResizeImagePercentage(Image.FromStream(image)); if (item.Sender == me) { ChatMediaMessage message = new ChatMediaMessage(displayImage, displayImage.Size, null, authorMe, item.TimeSend); _rcChatlog.AddMessage(message); } else { ChatMediaMessage message = new ChatMediaMessage(displayImage, displayImage.Size, null, authorFriend, item.TimeSend); _rcChatlog.AddMessage(message); } } else if (item.Message != "") { if (item.Sender == me) { ChatTextMessage message = new ChatTextMessage(item.Message, authorMe, item.TimeSend); _rcChatlog.AddMessage(message); } else { ChatTextMessage message = new ChatTextMessage(item.Message, authorFriend, item.TimeSend); _rcChatlog.AddMessage(message); } } else if (item.Call != null) { var tittle = ""; if (item.Call.Called) { tittle = "Cuộc gọi"; } else { tittle = "Cuộc gọi nhỡ"; } List <ChatCardAction> actions = new List <ChatCardAction>(); actions.Add(new ChatCardAction("Call")); if (item.Sender == me) { ChatImageCardDataItem card = new ChatImageCardDataItem(null, tittle, "bạn & " + authorFriend.Name, TimeSpan.FromSeconds(item.Call.Duration).ToString(@"mm\:ss"), actions, item.Receiver); ChatCardMessage message = new ChatCardMessage(card, authorMe, item.TimeSend); _rcChatlog.AddMessage(message); } else { ChatImageCardDataItem card = new ChatImageCardDataItem(null, tittle, "bạn & " + authorFriend.Name, TimeSpan.FromSeconds(item.Call.Duration).ToString(@"mm\:ss"), actions, item.Sender); ChatCardMessage message = new ChatCardMessage(card, authorFriend, item.TimeSend); _rcChatlog.AddMessage(message); } } } }