예제 #1
0
        private void MenuItem_Tap_AddUser(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                MessageBoxResult result = MessageBox.Show(AppResources.Please_Try_Again_Txt, AppResources.No_Network_Txt, MessageBoxButton.OK);
                return;
            }
            ListBoxItem selectedListBoxItem = this.groupChatParticipants.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem;

            if (selectedListBoxItem == null)
            {
                return;
            }

            gp_obj = selectedListBoxItem.DataContext as GroupParticipant;

            if (gp_obj == null)
            {
                return;
            }
            if (!gp_obj.Msisdn.Contains(gp_obj.Name)) // shows name is already stored so return
            {
                return;
            }
            ContactInfo ci = UsersTableUtils.getContactInfoFromMSISDN(gp_obj.Msisdn);

            if (ci != null)
            {
                return;
            }
            ContactUtils.saveContact(gp_obj.Msisdn, new ContactUtils.contactSearch_Callback(saveContactTask_Completed));
        }
예제 #2
0
        public void DeleteParticipant(string participantUsername, string groupName)
        {
            GroupParticipant participant = m_GroupParticipantRepository.Set().Where(p => p.Group.Name == groupName && p.User.UserName == participantUsername).FirstOrDefault();

            m_GroupParticipantRepository.Set().Remove(participant);
            m_GroupParticipantRepository.SaveChanges();
        }
예제 #3
0
        public GroupParticipant getGroupParticipant(string defaultName, string msisdn, string grpId)
        {
            if (grpId == null)
            {
                return(null);
            }

            if (groupCache.ContainsKey(grpId))
            {
                List <GroupParticipant> l = groupCache[grpId];
                for (int i = 0; i < l.Count; i++)
                {
                    if (l[i].Msisdn == msisdn)
                    {
                        return(l[i]);
                    }
                }
            }
            ContactInfo      cInfo = UsersTableUtils.getContactInfoFromMSISDN(msisdn);
            GroupParticipant gp    = new GroupParticipant(grpId, cInfo != null ? cInfo.Name : string.IsNullOrWhiteSpace(defaultName) ? msisdn : defaultName, msisdn, cInfo != null ? cInfo.OnHike : true);

            if (groupCache.ContainsKey(grpId))
            {
                groupCache[grpId].Add(gp);
                return(gp);
            }

            List <GroupParticipant> ll = new List <GroupParticipant>();

            ll.Add(gp);
            groupCache.Add(grpId, ll);
            return(gp);
        }
예제 #4
0
        public void AddParticipant(string groupName, string username)
        {
            Group        group = m_GroupRepository.Set().Where(p => p.Name == groupName).FirstOrDefault();
            UserIdentity user  = m_UserRepository.Set().Where(p => p.UserName == username).FirstOrDefault();

            if (group != null && user != null)
            {
                GroupParticipant participant = new GroupParticipant
                {
                    Group  = group,
                    User   = user,
                    Fellow = null
                };

                m_GroupParticipantRepository.Set().Add(participant);
                m_GroupParticipantRepository.SaveChanges();
            }

            UserInvitation invitation = m_UserInvitationRepository.Set().Where(p => p.Group.Name == groupName && p.User.UserName == username).FirstOrDefault();

            if (invitation != null)
            {
                m_UserInvitationRepository.Set().Remove(invitation);
                m_UserInvitationRepository.SaveChanges();
            }
        }
예제 #5
0
 private void inviteSMSUsers_Tap(object sender, System.Windows.Input.GestureEventArgs e)
 {
     App.AnalyticsInstance.addEvent(Analytics.INVITE_SMS_PARTICIPANTS);
     //TODO start this loop from end, after sorting is done on onHike status
     for (int i = 0; i < GroupManager.Instance.GroupCache[groupId].Count; i++)
     {
         GroupParticipant gp = GroupManager.Instance.GroupCache[groupId][i];
         if (!gp.IsOnHike)
         {
             long        time        = utils.TimeUtils.getCurrentTimeStamp();
             ConvMessage convMessage = new ConvMessage(AppResources.sms_invite_message, gp.Msisdn, time, ConvMessage.State.SENT_UNCONFIRMED);
             convMessage.IsInvite = true;
             App.HikePubSubInstance.publish(HikePubSub.MQTT_PUBLISH, convMessage.serialize(false));
         }
     }
     MessageBoxResult result = MessageBox.Show(AppResources.GroupInfo_InviteSent_MsgBoxText_Txt, AppResources.GroupInfo_InviteSent_MsgBoxHeader_Txt, MessageBoxButton.OK);
 }
예제 #6
0
        public void SaveGroupCache()
        {
            lock (readWriteLock)
            {
                using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    foreach (string grpId in groupCache.Keys)
                    {
                        string grp      = grpId.Replace(":", "_");
                        string fileName = GROUP_DIR + "\\" + grp;

                        try
                        {
                            if (store.FileExists(fileName))
                            {
                                store.DeleteFile(fileName);
                            }
                        }
                        catch { }
                        try
                        {
                            using (var file = store.OpenFile(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.ReadWrite))
                            {
                                using (BinaryWriter writer = new BinaryWriter(file))
                                {
                                    writer.Seek(0, SeekOrigin.Begin);
                                    writer.Write(groupCache[grpId].Count);
                                    for (int i = 0; i < groupCache[grpId].Count; i++)
                                    {
                                        GroupParticipant item = groupCache[grpId][i];
                                        item.Write(writer);
                                    }
                                    writer.Flush();
                                    writer.Close();
                                }
                                file.Close();
                                file.Dispose();
                            }
                        }
                        catch { }
                    }
                }
            }
        }
예제 #7
0
        private void btnGetSelected_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            groupChatParticipants.SelectedIndex = -1;
            gp_obj = (sender as ListBox).SelectedItem as GroupParticipant;
            if (gp_obj == null)
            {
                return;
            }
            if (!gp_obj.Msisdn.Contains(gp_obj.Name)) // shows name is already stored so return
            {
                return;
            }
            ContactInfo ci = UsersTableUtils.getContactInfoFromMSISDN(gp_obj.Msisdn);

            if (ci != null)
            {
                return;
            }
            ContactUtils.saveContact(gp_obj.Msisdn, new ContactUtils.contactSearch_Callback(saveContactTask_Completed));
        }
        private void listboxParticipantPicture_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (listboxParticipantPicture.SelectedItem == null)
            {
                return;
            }

            GroupParticipant groupParticipant = listboxParticipantPicture.SelectedItem as GroupParticipant;

            if (groupParticipant == null)
            {
                return;
            }

            PersonGroup       personGroup = DataBase.GetPersonGroupByName(groupParticipant.Name, false);
            PersonGroupWindow pgw         = new PersonGroupWindow(DataBase, PersonType.Unknown, personGroup);

            pgw.Owner = Window.GetWindow(this);
            pgw.ShowDialog();

            // Refresh
            this.PersonGroup = DataBase.GetPersonGroupByName(this.PersonGroup.Name, false);
        }
예제 #9
0
        public void RefreshGroupCache(ContactInfo cn, Dictionary <string, GroupInfo> allGrpsInfo)
        {
            if (allGrpsInfo == null || allGrpsInfo.Count == 0) // if no grp exists , do nothing
            {
                return;
            }

            foreach (string grpId in groupCache.Keys)
            {
                GroupParticipant gp = GetParticipant(grpId, cn.Msisdn);
                if (gp != null) // represents this contact lies in the group
                {
                    gp.Name = cn.Name;
                    if (App.ViewModel.ConvMap.ContainsKey(grpId))
                    {
                        GroupInfo g = null;
                        allGrpsInfo.TryGetValue(grpId, out g);
                        if (g != null && string.IsNullOrEmpty(g.GroupName))  // update groupname if not already set
                        {
                            GetParticipantList(grpId).Sort();
                            App.ViewModel.ConvMap[grpId].ContactName = defaultGroupName(grpId);
                            // update chat thread and group info page
                            object[] o = new object[2];
                            o[0] = grpId;
                            o[1] = App.ViewModel.ConvMap[grpId].ContactName;
                            App.HikePubSubInstance.publish(HikePubSub.GROUP_NAME_CHANGED, o);
                        }
                    }
                    else // if this group is not present in conversation , remove it
                    {
                        DeleteGroup(grpId);
                    }

                    SaveGroupCache(grpId); // save the cache
                }
            }
        }
예제 #10
0
        public void LoadGroupParticipants(string grpId)
        {
            if (groupCache.ContainsKey(grpId))
            {
                return;
            }

            lock (readWriteLock)
            {
                using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    List <GroupParticipant> gpList = null;
                    string grp      = grpId.Replace(":", "_");
                    string fileName = GROUP_DIR + "\\" + grp;
                    if (!store.FileExists(fileName))
                    {
                        return;
                    }
                    else
                    {
                        using (var file = store.OpenFile(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        {
                            using (var reader = new BinaryReader(file))
                            {
                                int count = 0;
                                try
                                {
                                    count = reader.ReadInt32();
                                }
                                catch { }
                                if (count > 0)
                                {
                                    gpList = new List <GroupParticipant>(count);
                                    for (int i = 0; i < count; i++)
                                    {
                                        GroupParticipant item = new GroupParticipant();
                                        try
                                        {
                                            item.Read(reader);
                                            gpList.Add(item);
                                        }
                                        catch
                                        {
                                            item = null;
                                        }
                                    }
                                }
                                reader.Close();
                            }
                            try
                            {
                                file.Close();
                                file.Dispose();
                            }
                            catch { }
                        }
                        if (gpList != null)
                        {
                            groupCache[grpId] = gpList;
                        }
                    }
                }
            }
        }
예제 #11
0
        public static ConversationListObject addChatMessage(ConvMessage convMsg, bool isNewGroup)
        {
            if (convMsg == null)
            {
                return(null);
            }
            ConversationListObject obj = null;

            if (!App.ViewModel.ConvMap.ContainsKey(convMsg.Msisdn))
            {
                if (Utils.isGroupConversation(convMsg.Msisdn) && !isNewGroup) // if its a group chat msg and group does not exist , simply ignore msg.
                {
                    return(null);
                }

                obj = ConversationTableUtils.addConversation(convMsg, isNewGroup);
                App.ViewModel.ConvMap.Add(convMsg.Msisdn, obj);
            }
            else
            {
                obj = App.ViewModel.ConvMap[convMsg.Msisdn];
                #region PARTICIPANT_JOINED
                if (convMsg.GrpParticipantState == ConvMessage.ParticipantInfoState.PARTICIPANT_JOINED)
                {
                    obj.LastMessage = convMsg.Message;

                    GroupInfo gi = GroupTableUtils.getGroupInfoForId(convMsg.Msisdn);
                    if (gi == null)
                    {
                        return(null);
                    }
                    if (string.IsNullOrEmpty(gi.GroupName)) // no group name is set
                    {
                        obj.ContactName = GroupManager.Instance.defaultGroupName(convMsg.Msisdn);
                    }
                }
                #endregion
                #region PARTICIPANT_LEFT
                else if (convMsg.GrpParticipantState == ConvMessage.ParticipantInfoState.PARTICIPANT_LEFT || convMsg.GrpParticipantState == ConvMessage.ParticipantInfoState.INTERNATIONAL_GROUP_USER)
                {
                    obj.LastMessage = convMsg.Message;
                    GroupInfo gi = GroupTableUtils.getGroupInfoForId(convMsg.Msisdn);
                    if (gi == null)
                    {
                        return(null);
                    }
                    if (string.IsNullOrEmpty(gi.GroupName)) // no group name is set
                    {
                        obj.ContactName = GroupManager.Instance.defaultGroupName(convMsg.Msisdn);
                    }
                }
                #endregion
                #region GROUP_JOINED_OR_WAITING
                else if (convMsg.GrpParticipantState == ConvMessage.ParticipantInfoState.GROUP_JOINED_OR_WAITING) // shows invite msg
                {
                    string[]      vals = Utils.splitUserJoinedMessage(convMsg.Message);
                    List <string> waitingParticipants = null;
                    for (int i = 0; i < vals.Length; i++)
                    {
                        string[] vars = vals[i].Split(HikeConstants.DELIMITERS, StringSplitOptions.RemoveEmptyEntries); // msisdn:0 or msisdn:1

                        // every participant is either on DND or not on DND
                        GroupParticipant gp = GroupManager.Instance.getGroupParticipant(null, vars[0], convMsg.Msisdn);
                        if (vars[1] == "0") // DND USER and not OPTED IN
                        {
                            if (waitingParticipants == null)
                            {
                                waitingParticipants = new List <string>();
                            }
                            waitingParticipants.Add(gp.FirstName);
                        }
                    }
                    if (waitingParticipants != null && waitingParticipants.Count > 0) // show waiting msg
                    {
                        StringBuilder msgText = new StringBuilder();
                        if (waitingParticipants.Count == 1)
                        {
                            msgText.Append(waitingParticipants[0]);
                        }
                        else if (waitingParticipants.Count == 2)
                        {
                            msgText.Append(waitingParticipants[0] + AppResources.And_txt + waitingParticipants[1]);
                        }
                        else
                        {
                            for (int i = 0; i < waitingParticipants.Count; i++)
                            {
                                msgText.Append(waitingParticipants[0]);
                                if (i == waitingParticipants.Count - 2)
                                {
                                    msgText.Append(AppResources.And_txt);
                                }
                                else if (i < waitingParticipants.Count - 2)
                                {
                                    msgText.Append(",");
                                }
                            }
                        }
                        obj.LastMessage = string.Format(AppResources.WAITING_TO_JOIN, msgText.ToString());
                    }
                    else
                    {
                        string[]         vars = vals[vals.Length - 1].Split(':');
                        GroupParticipant gp   = GroupManager.Instance.getGroupParticipant(null, vars[0], convMsg.Msisdn);
                        string           text = AppResources.USER_JOINED_GROUP_CHAT;
                        obj.LastMessage = gp.FirstName + text;
                    }
                }
                #endregion
                #region USER_OPT_IN
                else if (convMsg.GrpParticipantState == ConvMessage.ParticipantInfoState.USER_OPT_IN)
                {
                    if (Utils.isGroupConversation(obj.Msisdn))
                    {
                        GroupParticipant gp = GroupManager.Instance.getGroupParticipant(null, convMsg.Message, obj.Msisdn);
                        obj.LastMessage = gp.FirstName + AppResources.USER_JOINED_GROUP_CHAT;
                    }
                    else
                    {
                        obj.LastMessage = obj.NameToShow + AppResources.USER_OPTED_IN_MSG;
                    }
                    convMsg.Message = obj.LastMessage;
                }
                #endregion
                #region CREDITS_GAINED
                else if (convMsg.GrpParticipantState == ConvMessage.ParticipantInfoState.CREDITS_GAINED)
                {
                    obj.LastMessage = convMsg.Message;
                }
                #endregion
                #region DND_USER
                else if (convMsg.GrpParticipantState == ConvMessage.ParticipantInfoState.DND_USER)
                {
                    obj.LastMessage = string.Format(AppResources.DND_USER, obj.NameToShow);
                    convMsg.Message = obj.LastMessage;
                }
                #endregion
                #region USER_JOINED
                else if (convMsg.GrpParticipantState == ConvMessage.ParticipantInfoState.USER_JOINED)
                {
                    if (Utils.isGroupConversation(obj.Msisdn))
                    {
                        GroupParticipant gp = GroupManager.Instance.getGroupParticipant(null, convMsg.Message, obj.Msisdn);
                        obj.LastMessage = string.Format(AppResources.USER_JOINED_HIKE, gp.FirstName);
                    }
                    else // 1-1 chat
                    {
                        obj.LastMessage = string.Format(AppResources.USER_JOINED_HIKE, obj.NameToShow);
                    }
                    convMsg.Message = obj.LastMessage;
                }
                #endregion \
                #region GROUP NAME/PIC CHANGED
                else if (convMsg.GrpParticipantState == ConvMessage.ParticipantInfoState.GROUP_NAME_CHANGE || convMsg.GrpParticipantState == ConvMessage.ParticipantInfoState.GROUP_PIC_CHANGED)
                {
                    obj.LastMessage = convMsg.Message;
                }
                #endregion
                #region NO_INFO
                else if (convMsg.GrpParticipantState == ConvMessage.ParticipantInfoState.NO_INFO)
                {
                    //convMsg.GroupParticipant is null means message sent by urself
                    if (convMsg.GroupParticipant != null && Utils.isGroupConversation(convMsg.Msisdn))
                    {
                        GroupParticipant gp = GroupManager.Instance.getGroupParticipant(null, convMsg.GroupParticipant, convMsg.Msisdn);
                        obj.LastMessage = gp != null ? (gp.FirstName + "- " + convMsg.Message) : convMsg.Message;
                    }
                    else
                    {
                        obj.LastMessage = convMsg.Message;
                    }
                }
                #endregion
                #region OTHER MSGS
                else
                {
                    obj.LastMessage = convMsg.Message;
                }
                #endregion

                Stopwatch st1     = Stopwatch.StartNew();
                bool      success = addMessage(convMsg);
                if (!success)
                {
                    return(null);
                }
                st1.Stop();
                long msec1 = st1.ElapsedMilliseconds;
                Debug.WriteLine("Time to add chat msg : {0}", msec1);

                obj.MessageStatus = convMsg.MessageStatus;
                obj.TimeStamp     = convMsg.Timestamp;
                obj.LastMsgId     = convMsg.MessageId;
                Stopwatch st = Stopwatch.StartNew();
                ConversationTableUtils.updateConversation(obj);
                st.Stop();
                long msec = st.ElapsedMilliseconds;
                Debug.WriteLine("Time to update conversation  : {0}", msec);
            }

            return(obj);
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            GroupParticipant gp = value as GroupParticipant;

            return(string.Format("{0} - {1}", Misc.FormatDate(gp.Begin), Misc.FormatDate(gp.End)));
        }
예제 #13
0
        public void LoadGroupCache()
        {
            lock (readWriteLock)
            {
                using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    string[] files = store.GetFileNames(GROUP_DIR + "\\*");
                    if (files == null || files.Length == 0)
                    {
                        return;
                    }
                    for (int i = 0; i < files.Length; i++)
                    {
                        string grpId = files[i].Replace("_", ":");
                        if (groupCache.ContainsKey(grpId)) // if this group is already loaded ignore
                        {
                            continue;
                        }

                        string fileName = GROUP_DIR + "\\" + files[i];
                        List <GroupParticipant> gpList = null;

                        using (var file = store.OpenFile(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        {
                            using (var reader = new BinaryReader(file))
                            {
                                int count = 0;
                                try
                                {
                                    count = reader.ReadInt32();
                                }
                                catch { }
                                if (count > 0)
                                {
                                    gpList = new List <GroupParticipant>(count);
                                    for (int j = 0; j < count; j++)
                                    {
                                        GroupParticipant item = new GroupParticipant();
                                        try
                                        {
                                            item.Read(reader);
                                            gpList.Add(item);
                                        }
                                        catch
                                        {
                                            item = null;
                                        }
                                    }
                                }
                                reader.Close();
                            }
                            try
                            {
                                file.Close();
                                file.Dispose();
                            }
                            catch { }
                        }
                        if (gpList != null)
                        {
                            groupCache[grpId] = gpList;
                        }
                    }
                }
            }
        }
예제 #14
0
        public void updateAddressBook_Callback(JObject obj)
        {
            if ((obj == null) || HikeConstants.FAIL == (string)obj[HikeConstants.STAT])
            {
                Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show(AppResources.CONTACT_NOT_SAVED_ON_SERVER);
                });
                return;
            }
            JObject addressbook = (JObject)obj["addressbook"];

            if (addressbook == null)
            {
                Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show(AppResources.CONTACT_NOT_SAVED_ON_SERVER);
                });
                return;
            }
            IEnumerator <KeyValuePair <string, JToken> > keyVals = addressbook.GetEnumerator();
            KeyValuePair <string, JToken> kv;
            int count = 0;

            while (keyVals.MoveNext())
            {
                kv = keyVals.Current;
                JArray entries = (JArray)addressbook[kv.Key];
                for (int i = 0; i < entries.Count; ++i)
                {
                    JObject entry  = (JObject)entries[i];
                    string  msisdn = (string)entry["msisdn"];
                    if (string.IsNullOrWhiteSpace(msisdn))
                    {
                        continue;
                    }

                    bool onhike = (bool)entry["onhike"];
                    contactInfo.Msisdn = msisdn;
                    contactInfo.OnHike = onhike;
                    count++;
                }
            }
            UsersTableUtils.addContact(contactInfo);
            Dispatcher.BeginInvoke(() =>
            {
                gp_obj.Name         = contactInfo.Name;
                GroupParticipant gp = GroupManager.Instance.getGroupParticipant(gp_obj.Name, gp_obj.Msisdn, groupId);
                gp.Name             = gp_obj.Name;
                GroupManager.Instance.GetParticipantList(groupId).Sort();
                GroupManager.Instance.SaveGroupCache(groupId);
                // if default grp name is not set , then only update grp
                if (gi.GroupName == null)
                {
                    string gpName        = GroupManager.Instance.defaultGroupName(groupId);
                    groupNameTxtBox.Text = gpName;
                    if (App.newChatThreadPage != null)
                    {
                        App.newChatThreadPage.userName.Text = gpName;
                    }
                    if (App.ViewModel.ConvMap.ContainsKey(groupId))
                    {
                        App.ViewModel.ConvMap[groupId].ContactName = gpName;
                    }
                }

                // update normal 1-1 chat contact
                if (App.ViewModel.ConvMap.ContainsKey(gp_obj.Msisdn))
                {
                    App.ViewModel.ConvMap[gp_obj.Msisdn].ContactName = contactInfo.Name;
                }
                else // fav and pending case update
                {
                    ConversationListObject co = App.ViewModel.GetFav(gp_obj.Msisdn);
                    if (co != null)
                    {
                        co.ContactName = contactInfo.Name;
                    }
                }
                if (count > 1)
                {
                    MessageBox.Show(string.Format(AppResources.MORE_THAN_1_CONTACT_FOUND, gp_obj.Msisdn));
                }
                else
                {
                    MessageBox.Show(AppResources.CONTACT_SAVED_SUCCESSFULLY);
                }
            });
        }
예제 #15
0
        private void MenuItem_Tap_RemoveMember(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show(AppResources.RemoveFromGrpConfirmation_Txt, AppResources.Remove_From_grp_txt, MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.Cancel)
            {
                return;
            }

            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                result = MessageBox.Show(AppResources.Please_Try_Again_Txt, AppResources.No_Network_Txt, MessageBoxButton.OK);
                return;
            }
            ListBoxItem selectedListBoxItem = this.groupChatParticipants.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem;

            if (selectedListBoxItem == null)
            {
                return;
            }

            GroupParticipant gp_obj = selectedListBoxItem.DataContext as GroupParticipant;

            if (gp_obj == null)
            {
                return;
            }


            // send 'gck' packet
            // remove from OC
            // correct group name if required
            // set this guy as left in group cache

            JArray kickOutMsisdns = new JArray();

            kickOutMsisdns.Add(gp_obj.Msisdn);
            JObject data = new JObject();

            data.Add(HikeConstants.MSISDNS, kickOutMsisdns);
            JObject jObj = new JObject();

            jObj.Add(HikeConstants.TO, groupId);
            jObj.Add(HikeConstants.FROM, App.MSISDN);
            jObj.Add(HikeConstants.DATA, data);
            jObj.Add(HikeConstants.TYPE, "gck");
            mPubSub.publish(HikePubSub.MQTT_PUBLISH, jObj);

            //GroupParticipant gp = GroupManager.Instance.getGroupParticipant(null, gp_obj.Msisdn, groupId);
            //gp.HasLeft = true;
            //gp.IsUsed = false;
            //GroupManager.Instance.SaveGroupCache(groupId);

            //groupMembersOC.Remove(gp_obj);

            //if (string.IsNullOrEmpty(gi.GroupName)) // no group name is set
            //{
            //    string grpName = GroupManager.Instance.defaultGroupName(groupId);
            //    groupNameTxtBox.Text = grpName;
            //    if (App.ViewModel.ConvMap.ContainsKey(groupId))
            //        App.ViewModel.ConvMap[groupId].ContactName = grpName;
            //    if(App.newChatThreadPage != null)
            //        App.newChatThreadPage.userName.Text = grpName;
        }
예제 #16
0
        private void initPageBasedOnState()
        {
            groupId   = PhoneApplicationService.Current.State[HikeConstants.GROUP_ID_FROM_CHATTHREAD] as string;
            groupName = PhoneApplicationService.Current.State[HikeConstants.GROUP_NAME_FROM_CHATTHREAD] as string;

            gi = GroupTableUtils.getGroupInfoForId(groupId);
            if (gi == null)
            {
                return;
            }
            if (!App.IS_TOMBSTONED)
            {
                groupImage.Source = App.ViewModel.ConvMap[groupId].AvatarImage;
            }
            else
            {
                string grpId  = groupId.Replace(":", "_");
                byte[] avatar = MiscDBUtil.getThumbNailForMsisdn(grpId);
                if (avatar == null)
                {
                    groupImage.Source = UI_Utils.Instance.getDefaultGroupAvatar(grpId);
                }
                else
                {
                    MemoryStream memStream = new MemoryStream(avatar);
                    memStream.Seek(0, SeekOrigin.Begin);
                    BitmapImage empImage = new BitmapImage();
                    empImage.SetSource(memStream);
                    groupImage.Source = empImage;
                }
                GroupManager.Instance.LoadGroupParticipants(groupId);
            }
            if (Utils.isDarkTheme())
            {
                addUserImage.Source = new BitmapImage(new Uri("images/add_users_white.png", UriKind.Relative));
            }
            this.groupNameTxtBox.Text = groupName;
            List <GroupParticipant> hikeUsersList = new List <GroupParticipant>();
            List <GroupParticipant> smsUsersList  = GetHikeAndSmsUsers(GroupManager.Instance.GroupCache[groupId], hikeUsersList);
            GroupParticipant        self          = new GroupParticipant(groupId, (string)App.appSettings[App.ACCOUNT_NAME], App.MSISDN, true);

            hikeUsersList.Add(self);
            hikeUsersList.Sort();
            for (int i = 0; i < (hikeUsersList != null ? hikeUsersList.Count : 0); i++)
            {
                GroupParticipant gp = hikeUsersList[i];
                if (gi.GroupOwner == gp.Msisdn)
                {
                    gp.IsOwner = true;
                }
                if (gi.GroupOwner == (string)App.appSettings[App.MSISDN_SETTING] && gp.Msisdn != gi.GroupOwner) // if this user is owner
                {
                    gp.RemoveFromGroup = Visibility.Visible;
                }
                else
                {
                    gp.RemoveFromGroup = Visibility.Collapsed;
                }
                groupMembersOC.Add(gp);
            }

            for (int i = 0; i < (smsUsersList != null ? smsUsersList.Count : 0); i++)
            {
                GroupParticipant gp = smsUsersList[i];
                if (gi.GroupOwner == (string)App.appSettings[App.MSISDN_SETTING]) // if this user is owner
                {
                    gp.RemoveFromGroup = Visibility.Visible;
                }
                else
                {
                    gp.RemoveFromGroup = Visibility.Collapsed;
                }
                groupMembersOC.Add(gp);
                smsUsers++;
            }

            this.inviteBtn.IsEnabled = EnableInviteBtn;
            this.groupChatParticipants.ItemsSource = groupMembersOC;
            registerListeners();
        }
예제 #17
0
        private void MenuItem_Tap_AddRemoveFav(object sender, System.Windows.Input.GestureEventArgs e)
        {
            ListBoxItem selectedListBoxItem = this.groupChatParticipants.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem;

            if (selectedListBoxItem == null)
            {
                return;
            }
            GroupParticipant gp = selectedListBoxItem.DataContext as GroupParticipant;

            if (gp != null)
            {
                if (gp.IsFav) // already fav , remove request
                {
                    MessageBoxResult result = MessageBox.Show(AppResources.Conversations_RemFromFav_Confirm_Txt, AppResources.RemFromFav_Txt, MessageBoxButton.OKCancel);
                    if (result == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                    gp.IsFav = false;
                    ConversationListObject favObj = App.ViewModel.GetFav(gp.Msisdn);
                    App.ViewModel.FavList.Remove(favObj);
                    if (App.ViewModel.ConvMap.ContainsKey(gp.Msisdn))
                    {
                        (App.ViewModel.ConvMap[gp.Msisdn]).IsFav = false;
                    }
                    JObject data = new JObject();
                    data["id"] = gp.Msisdn;
                    JObject obj = new JObject();
                    obj[HikeConstants.TYPE] = HikeConstants.MqttMessageTypes.REMOVE_FAVOURITE;
                    obj[HikeConstants.DATA] = data;

                    mPubSub.publish(HikePubSub.MQTT_PUBLISH, obj);
                    App.HikePubSubInstance.publish(HikePubSub.ADD_REMOVE_FAV_OR_PENDING, null);
                    MiscDBUtil.SaveFavourites();
                    MiscDBUtil.DeleteFavourite(gp.Msisdn);
                    int count = 0;
                    App.appSettings.TryGetValue <int>(HikeViewModel.NUMBER_OF_FAVS, out count);
                    App.WriteToIsoStorageSettings(HikeViewModel.NUMBER_OF_FAVS, count - 1);
                    App.AnalyticsInstance.addEvent(Analytics.REMOVE_FAVS_CONTEXT_MENU_GROUP_INFO);
                }
                else // add to fav
                {
                    gp.IsFav = true;
                    ConversationListObject favObj;
                    if (App.ViewModel.ConvMap.ContainsKey(gp.Msisdn))
                    {
                        favObj       = App.ViewModel.ConvMap[gp.Msisdn];
                        favObj.IsFav = true;
                    }
                    else
                    {
                        favObj = new ConversationListObject(gp.Msisdn, gp.Name, gp.IsOnHike, MiscDBUtil.getThumbNailForMsisdn(gp.Msisdn));
                    }
                    App.ViewModel.FavList.Insert(0, favObj);
                    if (App.ViewModel.IsPending(gp.Msisdn))
                    {
                        App.ViewModel.PendingRequests.Remove(favObj);
                        MiscDBUtil.SavePendingRequests();
                    }
                    MiscDBUtil.SaveFavourites();
                    MiscDBUtil.SaveFavourites(favObj);
                    int count = 0;
                    App.appSettings.TryGetValue <int>(HikeViewModel.NUMBER_OF_FAVS, out count);
                    App.WriteToIsoStorageSettings(HikeViewModel.NUMBER_OF_FAVS, count + 1);
                    JObject data = new JObject();
                    data["id"] = gp.Msisdn;
                    JObject obj = new JObject();
                    obj[HikeConstants.TYPE] = HikeConstants.MqttMessageTypes.ADD_FAVOURITE;
                    obj[HikeConstants.DATA] = data;
                    mPubSub.publish(HikePubSub.MQTT_PUBLISH, obj);
                    App.HikePubSubInstance.publish(HikePubSub.ADD_REMOVE_FAV_OR_PENDING, null);
                    App.AnalyticsInstance.addEvent(Analytics.ADD_FAVS_CONTEXT_MENU_GROUP_INFO);
                }
            }
        }
예제 #18
0
        public string GetFellow(string username, string groupname)
        {
            GroupParticipant groupParticipant = m_GroupParticipantRepository.Set().Where(p => p.Group.Name == groupname && p.User.UserName == username).FirstOrDefault();

            return(groupParticipant.Fellow.User.UserName);
        }
예제 #19
0
        public void onEventReceived(string type, object obj)
        {
            #region UPDATE_UI
            if (HikePubSub.UPDATE_UI == type)
            {
                string msisdn = (string)obj;
                if (msisdn != groupId)
                {
                    return;
                }
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    groupImage.Source = App.ViewModel.ConvMap[msisdn].AvatarImage;
                });
            }
            #endregion
            #region PARTICIPANT_JOINED_GROUP
            else if (HikePubSub.PARTICIPANT_JOINED_GROUP == type)
            {
                JObject json         = (JObject)obj;
                string  eventGroupId = (string)json[HikeConstants.TO];
                if (eventGroupId != groupId)
                {
                    return;
                }
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    groupMembersOC.Clear();
                    for (int i = 0; i < GroupManager.Instance.GroupCache[groupId].Count; i++)
                    {
                        GroupParticipant gp = GroupManager.Instance.GroupCache[groupId][i];
                        if (!gp.HasLeft)
                        {
                            groupMembersOC.Add(gp);
                        }
                        if (!gp.IsOnHike && !EnableInviteBtn)
                        {
                            smsUsers++;
                            this.inviteBtn.IsEnabled = true;
                        }
                    }
                    groupName            = App.ViewModel.ConvMap[groupId].NameToShow;
                    groupNameTxtBox.Text = groupName;
                    PhoneApplicationService.Current.State[HikeConstants.GROUP_NAME_FROM_CHATTHREAD] = groupName;
                });
            }
            #endregion
            #region PARTICIPANT_LEFT_GROUP
            else if (HikePubSub.PARTICIPANT_LEFT_GROUP == type)
            {
                ConvMessage cm           = (ConvMessage)obj;
                string      eventGroupId = cm.Msisdn;
                if (eventGroupId != groupId)
                {
                    return;
                }
                string           leaveMsisdn = cm.GroupParticipant;
                GroupParticipant gp          = GroupManager.Instance.getGroupParticipant(null, leaveMsisdn, eventGroupId);
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    for (int i = 0; i < groupMembersOC.Count; i++)
                    {
                        if (groupMembersOC[i].Msisdn == leaveMsisdn)
                        {
                            groupMembersOC.RemoveAt(i);
                            groupName            = App.ViewModel.ConvMap[groupId].NameToShow; // change name of group
                            groupNameTxtBox.Text = groupName;
                            PhoneApplicationService.Current.State[HikeConstants.GROUP_NAME_FROM_CHATTHREAD] = groupName;
                            if (!gp.IsOnHike)
                            {
                                smsUsers--;
                                if (smsUsers <= 0)
                                {
                                    inviteBtn.IsEnabled = false;
                                }
                            }
                            return;
                        }
                    }
                });
            }
            #endregion
            #region GROUP_NAME_CHANGED
            else if (HikePubSub.GROUP_NAME_CHANGED == type)
            {
                if (isgroupNameSelfChanged)
                {
                    return;
                }
                string grpId = (string)obj;
                if (grpId == groupId)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        this.groupNameTxtBox.Text = App.ViewModel.ConvMap[groupId].ContactName;
                    });
                }
            }
            #endregion
            #region GROUP PIC CHANGED
            else if (HikePubSub.UPDATE_GRP_PIC == type)
            {
                string grpId = (string)obj;
                if (grpId == groupId)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        this.groupImage.Source = App.ViewModel.ConvMap[groupId].AvatarImage;
                    });
                }
            }
            #endregion
            #region GROUP_END
            else if (HikePubSub.GROUP_END == type)
            {
                string gId = (string)obj;
                if (gId == groupId)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        NavigationService.GoBack();
                    });
                }
            }
            #endregion
            #region USER JOINED HIKE
            else if (HikePubSub.USER_JOINED == type)
            {
                string ms = (string)obj;
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    for (int i = 0; i < groupMembersOC.Count; i++)
                    {
                        if (groupMembersOC[i].Msisdn == ms)
                        {
                            groupMembersOC[i].IsOnHike = true;
                            smsUsers--;
                            if (smsUsers == 0)
                            {
                                this.inviteBtn.IsEnabled = false;
                            }
                            return;
                        }
                    }
                });
            }
            #endregion
            #region USER LEFT HIKE
            else if (HikePubSub.USER_LEFT == type)
            {
                string ms = (string)obj;
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    for (int i = 0; i < groupMembersOC.Count; i++)
                    {
                        if (groupMembersOC[i].Msisdn == ms)
                        {
                            smsUsers++;
                            groupMembersOC[i].IsOnHike = false;
                            this.inviteBtn.IsEnabled   = true;
                            return;
                        }
                    }
                });
            }

            #endregion
        }