コード例 #1
0
        /// <summary>
        /// Returns conversation Id in db or create new if doesn't exist;
        /// </summary>
        /// <param name="userId">Id of user who is message sender</param>
        /// <param name="addresseeId">Id of user who will be message addressee</param>
        /// <returns>Id of conversation record in db</returns>
        public async Task <ConversationInfoModel> GetConversationInfoModel(string userId, string addresseeId)
        {
            var result = new ConversationInfoModel();

            if (userId == addresseeId)
            {
                //sender and addressee is the same user
                return(result);
            }

            var conversation = this.conversationDbService.GetConversationByUsers(userId, addresseeId);

            if (conversation == null)
            {
                this.conversationDbService.CreateConversation(userId, addresseeId);
                conversation = this.conversationDbService.GetConversationByUsers(userId, addresseeId);
            }

            result.ConversationId           = conversation.ConversationId;
            result.InterlocutorId           = addresseeId;
            result.InterlocutorName         = conversation.Users.First(u => u.UserId != userId).User.UserName;
            result.InterlocutorPrifileImage = await this.photosService.GetUserProfilePhotoInBytes(conversation.Users.First(u => u.UserId != userId).User.UserProfilePhotoName);

            return(result);
        }
コード例 #2
0
        private void GetExtras(Intent intent = null)
        {
            var conversationInfoModelString = String.Empty;

            if (intent != null)
            {
                conversationInfoModelString = intent.GetStringExtra(ExtrasKeys.CONVERSATION_INFO_MODEL);
            }
            else
            {
                conversationInfoModelString = Intent.GetStringExtra(ExtrasKeys.CONVERSATION_INFO_MODEL);
            }

            this.conversationInfoModel = JsonConvert.DeserializeObject <ConversationInfoModel>(conversationInfoModelString);
        }
コード例 #3
0
        private void ConversationsListAdapter_ConversationItemClick(object sender, ConversationItemModel e)
        {
            var intent = new Intent(this, typeof(ConversationActivity));
            var conversationInfoModel = new ConversationInfoModel
            {
                ConversationId           = e.Id,
                InterlocutorId           = e.InterLocutorId,
                InterlocutorName         = e.InterlocutorName,
                InterlocutorPrifileImage = e.InterLocutorProfileImage
            };

            intent.PutExtra(ExtrasKeys.CONVERSATION_INFO_MODEL, JsonConvert.SerializeObject(conversationInfoModel));

            StartActivity(intent);
        }
コード例 #4
0
        private void ShowNotification(string conversationMessage)
        {
            var message = JsonConvert.DeserializeObject <ConversationMessage>(conversationMessage);

            if (lastMessageId == message.Id)
            {
                //kilka po³aczeñ z hubem a header jest unikalny dla wiadomoœci
                return;
            }
            if (!ConversationActivity.ConversationActivityStateModel.IsInForeground || ConversationActivity.ConversationActivityStateModel.ConversationId != message.ConversationId)
            {
                var nMgr           = (NotificationManager)GetSystemService(NotificationService);
                var notification   = new Notification(Resource.Drawable.logo_icon, "Mobile Second Hand - nowa wiadomoϾ");
                var notificationId = new System.Random().Next(1000);
                notification.Flags = NotificationFlags.AutoCancel;
                notification.Sound = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
                var intent = new Intent(this, typeof(ConversationActivity));
                var conversationInfoModel = new ConversationInfoModel
                {
                    ConversationId           = message.ConversationId,
                    InterlocutorId           = message.SenderId,
                    InterlocutorName         = message.SenderName,
                    InterlocutorPrifileImage = new byte[0]
                };
                intent.PutExtra(ExtrasKeys.CONVERSATION_INFO_MODEL, JsonConvert.SerializeObject(conversationInfoModel));
                var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.CancelCurrent);
                notification.SetLatestEventInfo(this, String.Format("WiadomoϾ od {0}", message.SenderName), message.MessageContent, pendingIntent);
                nMgr.Notify(conversationInfoModel.ConversationId, notification);
            }
            else
            {
                ConversationActivity.ActivityInstance.AddMessage(message);
            }

            lastMessageId = message.Id;
            this.chatHubClientService.MessageReceived(message.Id);
        }