public static void Save(MessageClass inputItem, ChatListClass inputList) { if (AppData.auth.CurrentUser == null) { return; } object[] itemKeys = { "itemName", "itemTime", }; object[] itemVals = { inputItem.ItemName, inputItem.ItemTime.ToString(), }; var itemDict = NSDictionary.FromObjectsAndKeys(itemVals, itemKeys); AppData.DataNode .GetChild(inputList.ChatOwner.Uid) .GetChild(inputList.ChatName) .GetChild("items") .GetChild(inputItem.ItemName) .SetValue <NSDictionary>(itemDict); }
static NSDictionary ChatToDict(ChatListClass inputList) { var allItemsDict = new NSMutableDictionary(); foreach (MessageClass item in inputList.ChatItems) { NSMutableDictionary eachItemDict = new NSMutableDictionary(); eachItemDict.SetValueForKey((NSString)item.ItemName, (NSString)"itemName"); eachItemDict.SetValueForKey((NSString)(item.ItemTime.ToString()), (NSString)"itemTime"); allItemsDict.SetValueForKey(eachItemDict, (NSString)item.ItemName); } object[] chatOwnerKeys = { "name", "email", "uid" }; object[] chatOwnerValues = { inputList.ChatOwner.Name, inputList.ChatOwner.Email, inputList.ChatOwner.Uid }; var chatOwnerDict = NSDictionary.FromObjectsAndKeys(chatOwnerValues, chatOwnerKeys); NSMutableDictionary anyChatDataDict = new NSMutableDictionary(); anyChatDataDict.SetValueForKey(allItemsDict, (NSString)"items"); anyChatDataDict.SetValueForKey((NSString)inputList.ChatName, (NSString)"chatName"); anyChatDataDict.SetValueForKey(chatOwnerDict, (NSString)"chatOwner"); if (allItemsDict.Count == 0) { anyChatDataDict.Remove((NSString)"items"); } return(anyChatDataDict); }
public static void Invite(UIViewController thisView, ChatListClass toChat, string inviteeEmail) { UserClass inviteeUser = null; UserClass inviterUser = AppData.curUser; String thisChatName = toChat.ChatName; AppData.UsersNode.ObserveSingleEvent(DataEventType.Value, (snapshot) => { NSEnumerator children = snapshot.Children; var childSnapShot = children.NextObject() as DataSnapshot; while (childSnapShot != null) { NSDictionary childDict = childSnapShot.GetValue <NSDictionary>(); if (childDict.ValueForKey((NSString)"email").ToString() == inviteeEmail) { // user exist inviteeUser = new UserClass { Name = childDict.ValueForKey((NSString)"name").ToString(), Email = childDict.ValueForKey((NSString)"email").ToString(), Uid = childDict.ValueForKey((NSString)"uid").ToString() }; break; } childSnapShot = children.NextObject() as DataSnapshot; } if (inviteeUser == null) { AlertShow.Alert(thisView, "No Such User", "User is not registered with us"); return; } String invitationTitle = inviterUser.Uid + "|" + thisChatName; object[] ownerKeys = { "ownerUid", "ownerEmail", "ownerName" }; object[] ownerVals = { inviterUser.Uid, inviterUser.Email, inviterUser.Name }; var ownerDict = NSDictionary.FromObjectsAndKeys(ownerVals, ownerKeys); object[] inviteeKeys = { "chatName", "owner" }; object[] inviteeVals = { thisChatName, ownerDict }; var inviteeDict = NSDictionary.FromObjectsAndKeys(inviteeVals, inviteeKeys); DatabaseReference inviteeNode = AppData.UsersNode.GetChild(inviteeUser.Uid); inviteeNode.GetChild("myInvitations") .GetChild(invitationTitle) .SetValue <NSDictionary>(inviteeDict); AlertShow.Alert(thisView, "Invitation Sent", "You have successfully invited " + inviteeUser.Name + " to this chat"); }); }
public static void Save(ChatListClass inputList) { if (AppData.auth.CurrentUser == null) { return; } NSDictionary toWriteDict = ChatToDict(inputList); AppData.DataNode.GetChild(AppData.curUser.Uid).GetChild(inputList.ChatName).SetValue <NSDictionary>(toWriteDict); }
public static void Delete(ChatListClass inputChat) { if (AppData.auth.CurrentUser == null) { return; } DatabaseReference chatNode = AppData.DataNode.GetChild(inputChat.ChatOwner.Uid).GetChild(inputChat.ChatName); chatNode.RemoveValue(); }
public static List <ChatListClass> Compare(List <ChatListClass> chatA, List <ChatListClass> chatB) { List <ChatListClass> combinedChatsLST = new List <ChatListClass>(); // first, if there is a list in one that is not in other, just copy it foreach (ChatListClass a in chatA) { foreach (ChatListClass anyChat in chatB) { if (a.ChatName == anyChat.ChatName) { goto ContinueLoop; } } combinedChatsLST.Add(a); ContinueLoop :; } // and the other way around foreach (ChatListClass b in chatB) { foreach (ChatListClass anyList in chatA) { if (b.ChatName == anyList.ChatName) { goto ContinueLoop; } } combinedChatsLST.Add(b); ContinueLoop :; } // then we remove anyone we have already added foreach (ChatListClass any in combinedChatsLST) { if (chatA.Contains(any)) { chatA.Remove(any); } if (chatB.Contains(any)) { chatB.Remove(any); } } // now lt's compare the similar lists against each other foreach (ChatListClass anyChatA in chatA) { List <MessageClass> thisListResultItems = new List <MessageClass>(); ChatListClass counterPartList = new ChatListClass(); DateTime combinedTime = DateTime.UtcNow; // first we find the lists that are similar foreach (ChatListClass anyChatB in chatB) { if (anyChatB.ChatName == anyChatA.ChatName) { counterPartList = anyChatB; break; } } // then we check their items foreach (MessageClass anyItem in anyChatA.ChatItems) { // let's compare items from one list to anothert foreach (MessageClass counterItem in counterPartList.ChatItems) { if (anyItem.ItemName == counterItem.ItemName) { // item exists both sides, let's decide which one to add if (anyItem.ItemTime > counterItem.ItemTime) { thisListResultItems.Add(anyItem); } else { thisListResultItems.Add(counterItem); } goto ContinueHere; } } // if we reach here, non of the names have matchedd thisListResultItems.Add(anyItem); ContinueHere :; } // by now all items of this LIST is resolved, now, let's deal with counter part foreach (MessageClass anyCounterItem in counterPartList.ChatItems) { // let's compare items from counter to the main foreach (MessageClass anyItem in anyChatA.ChatItems) { if (anyCounterItem.ItemName == anyItem.ItemName) { // item exists both sides, we have already added that, let's drop out goto ContinueHere; } } // if we reach here, non of the names have matched thisListResultItems.Add(anyCounterItem); ContinueHere :; } // this shopping class now contains all of the similar ones and uniques ones combinedChatsLST.Add(new ChatListClass { ChatName = anyChatA.ChatName, ChatOwner = anyChatA.ChatOwner, ChatItems = thisListResultItems }); } return(combinedChatsLST); }
public MessagesDataSource(ChatListClass inputList) { thisList = inputList; }
public static async Task Fetch() { AppData.invitationsLST = new List <ChatListClass>(); if (AppData.auth.CurrentUser == null) { return; } bool done = false; foreach (InvitationClass anyCoord in AppData.invitationsData) { string chatName = anyCoord.ChatName; string ownerUid = anyCoord.ChatOwner.Uid; AppData.DataNode.GetChild(ownerUid).GetChild(chatName).ObserveSingleEvent(DataEventType.Value, (snapshot) => { var thisChatAllData = snapshot.GetValue <NSDictionary>(); List <MessageClass> itemsInChat = new List <MessageClass>(); if (thisChatAllData.ValueForKey((NSString)"items") != null) { if ((thisChatAllData.ValueForKey((NSString)"items")).IsKindOfClass(new ObjCRuntime.Class(typeof(NSDictionary)))) { NSDictionary itemsOfChatVals = (NSDictionary)NSObject.FromObject(thisChatAllData.ValueForKey((NSString)"items")); for (int i = 0; i < (int)itemsOfChatVals.Values.Length; i++) { NSDictionary eachItemVals = (NSDictionary)NSObject.FromObject(itemsOfChatVals.Values[i]); var fetchedItemName = (NSString)eachItemVals.ValueForKey((NSString)"itemName"); var fetchedItemCategory = (NSString)eachItemVals.ValueForKey((NSString)"itemCategory"); var fetchedItemTime = (NSString)eachItemVals.ValueForKey((NSString)"itemTime"); itemsInChat.Add(new MessageClass { ItemName = fetchedItemName, ItemTime = DateTime.Parse(fetchedItemTime) }); } } } ChatListClass thisChat = new ChatListClass { ChatName = chatName, ChatOwner = anyCoord.ChatOwner, ChatItems = itemsInChat }; AppData.invitationsLST.Add(thisChat); done = true; }); } while (!done) { await Task.Delay(50); } }