Exemple #1
0
        private async void OnUsualMessage(Xmpp.Im.Message xmppXmppMessage)
        {
            var receivedMessage = new GeneralDataModel.Models.Message();

            FillUsualMessageFields(xmppXmppMessage, receivedMessage);

            FillUsualMessageExtraParamsFields(xmppXmppMessage.ExtraParameters, receivedMessage);
            FillAttachments(xmppXmppMessage.ExtraParameters, receivedMessage);

            await LoggerHolder.Log(LogLevel.Debug, "XMPP: OnMessageReceived ====> " +
                                   " From: " + receivedMessage.SenderId +
                                   " To: " + receivedMessage.RecipientId +
                                   " Body: " + receivedMessage.MessageText +
                                   " DateSent " + receivedMessage.DateSent +
                                   " FullXmlMessage: " + xmppXmppMessage.DataString);

            receivedMessage.ExtraParameters = xmppXmppMessage.ExtraParameters;

            var handler = MessageReceived;

            if (handler != null)
            {
                var messageEventArgs = new MessageEventArgs(xmppXmppMessage.From, receivedMessage, xmppXmppMessage.Type);
                handler.Invoke(this, messageEventArgs);
            }
        }
Exemple #2
0
        private void FillUsualMessageFields(Xmpp.Im.Message xmppXmppMessage, GeneralDataModel.Models.Message result)
        {
            string from = xmppXmppMessage.From.ToString();
            string to   = xmppXmppMessage.To.ToString();

            result.From        = from;
            result.To          = to;
            result.MessageText = xmppXmppMessage.Body;

            result.Id          = xmppXmppMessage.Id;
            result.RecipientId = xmppXmppMessage.Type == Xmpp.Im.MessageType.Groupchat ? GetQbUserIdFromGroupJid(to) : GetQbUserIdFromJid(to);
            result.SenderId    = xmppXmppMessage.Type == Xmpp.Im.MessageType.Groupchat ? GetQbUserIdFromGroupJid(from) : GetQbUserIdFromJid(from);
        }
Exemple #3
0
        private void FillUsualMessageExtraParamsFields(XElement extraParams, GeneralDataModel.Models.Message result)
        {
            if (extraParams != null)
            {
                result.ChatDialogId = GetExtraParam(extraParams, ExtraParamsList.dialog_id);

                var dateSent = extraParams.Element(ExtraParams.GetXNameFor(ExtraParamsList.date_sent));
                if (dateSent != null)
                {
                    long longValue;
                    if (long.TryParse(dateSent.Value, out longValue))
                    {
                        result.DateSent = longValue;
                    }
                }

                var stringIntListConverter = new StringIntListConverter();

                result.NotificationType = GetNotificationType(extraParams);

                result.RoomPhoto           = GetExtraParam(extraParams, ExtraParamsList.room_photo);
                result.RoomName            = GetExtraParam(extraParams, ExtraParamsList.room_name);
                result.CurrentOccupantsIds = stringIntListConverter.ConvertToIntList(GetExtraParam(extraParams, ExtraParamsList.current_occupant_ids));
                result.AddedOccupantsIds   = stringIntListConverter.ConvertToIntList(GetExtraParam(extraParams, ExtraParamsList.added_occupant_ids));
                result.DeletedOccupantsIds = stringIntListConverter.ConvertToIntList(GetExtraParam(extraParams, ExtraParamsList.deleted_occupant_ids));
                result.ExtraParameters     = extraParams;

                double roomUpdateDate;
                if (Double.TryParse(GetExtraParam(extraParams, ExtraParamsList.room_updated_date), out roomUpdateDate))
                {
                    result.RoomUpdateDate = roomUpdateDate;
                }

                var deletedId = GetExtraParam(extraParams, ExtraParamsList.deleted_id);
                if (deletedId != null)
                {
                    int deletedIdInt;
                    if (int.TryParse(deletedId, out deletedIdInt))
                    {
                        result.DeletedId = deletedIdInt;
                    }
                }
            }
        }
Exemple #4
0
        private void FillAttachments(XElement extraParams, GeneralDataModel.Models.Message result)
        {
            if (extraParams != null)
            {
                var attachmentParam = extraParams.Element(ExtraParams.GetXNameFor(ExtraParamsList.attachment));
                if (attachmentParam != null)
                {
                    var attachemnt = new Attachment
                    {
                        Name = GetAttributeValue(attachmentParam, XName.Get("name")),
                        Id   = GetAttributeValue(attachmentParam, XName.Get("id")),
                        Type = GetAttributeValue(attachmentParam, XName.Get("type")),
                        Url  = GetAttributeValue(attachmentParam, XName.Get("url"))
                    };

                    result.Attachments = new Attachment[] { attachemnt };
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the MessageEventArgs class.
 /// </summary>
 /// <exception cref="ArgumentNullException">The jid parameter or the Message
 /// parameter is null.</exception>
 public MessageEventArgs(Jid jid, GeneralDataModel.Models.Message message, MessageType messageType)
 {
     Jid         = jid;
     Message     = message;
     MessageType = messageType;
 }