Example #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;
		}
Example #2
0
		public async Task<bool> InjectEvent(DataBaseWrapper db, User user, Event e)
		{
			return true;
		}
Example #3
0
		private async Task<int> EventHandling(DataBaseWrapper db, JsonValue result) {
			if (result.ContainsKey ("events")) {
				JsonArray arr = (JsonArray) result ["events"];
				foreach (JsonValue v in arr) {
					var e = new Event () {
						type = v ["type"],
						msg = v ["msg"],
						nick = v ["nick"],
						text = v ["text"],
						time = v ["time"],
						author = v ["author"]
					};
					db.Insert (e);
				}

				if (backgroundService != null) {
					await backgroundService.UpdateNotifications();
				}
			}
			if (result.ContainsKey ("onLoginError")) {
				return 1;
			}
			return 0;
		}
Example #4
0
		public async Task<bool> RemoveEvent(DataBaseWrapper db, User user, Event e)
		{
			string encodedJson = escape(String.Format("{{\"id\":\"{0}\", \"removeEvent\":{{\"conversation\":\"{1}\"}}}}", user.id, e.msg));

			var result = JsonValue.Parse(await Download(user.server + "/xjcp.php?msg=" + encodedJson));
			var success = false;
			try {
				success = 0 == await EventHandling (db, result);
			} catch (Exception ex) {
				Log.Error ("BlaChat", ex.StackTrace);
			}

			return success;
		}