Beispiel #1
0
        private async Task <int> HandleEvent(DataBaseWrapper db, AsyncNetwork network, User user, Event e)
        {
            if (e.type != "onMessage")
            {
                return(0);
            }
            var chat = db.Get <Chat> (e.msg);

            if (chat == null)
            {
                while (!await network.UpdateChats(db, user))
                {
                    await network.Authenticate(db, user);
                }
                chat = db.Get <Chat> (e.msg);
            }
            chat.time = e.time;
            db.Update(chat);

            var msg = new Message();

            msg.conversation = chat.conversation;
            msg.author       = e.author;
            msg.nick         = e.nick;
            msg.text         = e.text;
            msg.time         = e.time;
            db.InsertIfNotContains <Message> (msg);

            ResetUpdateInterval();
            if (e.msg != ActiveConversation && user.user != e.nick)
            {
                chat.Marked = true;
                db.Update(chat);
                if (chat.Notifications)
                {
                    await Notify(network, e.nick, e.text);
                }
            }
            if (ChatActivity != null)
            {
                ChatActivity.OnUpdateRequested();
            }
            else if (MainActivity != null)
            {
                MainActivity.OnUpdateRequested();
            }
            return(0);
        }
		private async Task<int> HandleEvent(DataBaseWrapper db, AsyncNetwork network, User user, Event e) {
			if (e.type != "onMessage") {
				return 0;
			}
			var chat = db.Get<Chat> (e.msg);
			if (chat == null) {
				while(!await network.UpdateChats (db, user)) {
					await network.Authenticate(db, user);
				}
				chat = db.Get<Chat> (e.msg);
			}
			chat.time = e.time;
			db.Update (chat);

			var msg = new Message ();
			msg.conversation = chat.conversation;
			msg.author = e.author;
			msg.nick = e.nick;
			msg.text = e.text;
			msg.time = e.time;
			db.InsertIfNotContains<Message> (msg);

			ResetUpdateInterval ();
			if (e.msg != ActiveConversation && user.user != e.nick) {
				chat.Marked = true;
				db.Update (chat);
				if (chat.Notifications) {
					await Notify (network, e.nick, e.text);
				}
			}
			if (ChatActivity != null) {
				ChatActivity.OnUpdateRequested ();
			} else if (MainActivity != null) {
				MainActivity.OnUpdateRequested ();
			}
			return 0;
		}
Beispiel #3
0
        private void initializeNotAuthenticated()
        {
            SetContentView(Resource.Layout.Authentication);

            Button login = FindViewById <Button> (Resource.Id.login);

            login.Click += async delegate {
                InputMethodManager manager = (InputMethodManager)GetSystemService(InputMethodService);
                manager.HideSoftInputFromWindow(FindViewById <EditText> (Resource.Id.username).WindowToken, 0);
                manager.HideSoftInputFromWindow(FindViewById <EditText> (Resource.Id.password).WindowToken, 0);
                manager.HideSoftInputFromWindow(FindViewById <EditText> (Resource.Id.server).WindowToken, 0);

                login.Text    = "Connecting...";
                login.Enabled = false;

                var user = new User()
                {
                    user     = FindViewById <EditText> (Resource.Id.username).Text.ToLower(),
                    password = FindViewById <EditText> (Resource.Id.password).Text,
                    server   = !string.IsNullOrEmpty(FindViewById <EditText> (Resource.Id.server).Text) ?
                               FindViewById <EditText> (Resource.Id.server).Text :
                               FindViewById <EditText> (Resource.Id.server).Hint
                };
                if (user.user == "" || user.password == "")
                {
                    login.Text    = "Login";
                    login.Enabled = true;
                    return;
                }

                if (await network.Authenticate(db, user))
                {
                    login.Text = "Loading data...";
                    new Thread(async() => {
                        int i = 0;
                        db.Insert(user);
                        while (!await network.UpdateChats(db, user))
                        {
                            await network.Authenticate(db, user);
                        }
                        var x     = db.Table <Chat> ();
                        int count = x.Count();
                        var tasks = new List <Task <bool> >();
                        RunOnUiThread(() => { if (isUnbound())
                                              {
                                                  return;
                                              }
                                              initializeAuthenticated(user); });

                        foreach (var chat in x)
                        {
                            while (!await network.UpdateHistory(db, user, chat, 30))
                            {
                                await network.Authenticate(db, user);
                            }
                            OnUpdateRequested();
                        }
                    }).Start();
                }
                else
                {
                    login.Text    = "Retry Login";
                    login.Enabled = true;
                }
            };
        }