Example #1
0
        /// <summary>
        /// Add users to the group.
        /// If the group's approval mode is set to require admin approval, and you're not an
        /// admin, the participants won't actually be added, they will be set as pending.
        /// In that case, the returned `ParticipantsAdded` event will not be correct.
        /// Args:
        ///     user_ids: One or more user IDs to add
        /// Example:
        ///     >>> group.add_participants(["1234", "2345"])
        /// </summary>
        /// <param name="user_ids">One or more user IDs to add</param>
        /// <returns></returns>
        public async Task <FB_ParticipantsAdded> addParticipants(List <string> user_ids)
        {
            var data = this._to_send_data();

            data["action_type"]      = "ma-type:log-message";
            data["log_message_type"] = "log:subscribe";

            var uuser_ids = Utils.require_list <string>(user_ids);

            foreach (var obj in user_ids.Select((x, index) => new { user_id = x, i = index }))
            {
                if (obj.user_id == this.session.user.uid)
                {
                    throw new FBchatUserError(
                              "Error when adding users: Cannot add self to group thread"
                              );
                }
                else
                {
                    data[
                        string.Format("log_message_data[added_participants][{0}]", obj.i)
                    ] = string.Format("fbid:{0}", obj.user_id);
                }
            }
            var req = await this.session._do_send_request(data);

            return(FB_ParticipantsAdded._from_send(thread: this, added_ids: user_ids));
        }
Example #2
0
 internal static FB_ParticipantsAdded _from_fetch(FB_Thread thread, JToken data)
 {
     (FB_User author, long at) = FB_ParticipantsAdded._parse_fetch(thread.session, data);
     return(new FB_ParticipantsAdded()
     {
         author = thread.session.user,
         thread = thread as FB_Group,
         added = data?.get("participants_added")?.Select(x => new FB_User(x?.get("id")?.Value <string>(), thread.session)).ToList(),
         at = at
     });
 }
Example #3
0
        internal static FB_ParticipantsAdded _parse(Session session, JToken data)
        {
            (FB_User author, FB_Thread thread, long at) = FB_ParticipantsAdded._parse_metadata(session, data);
            var added = data?.get("addedParticipants")?.Select(x => new FB_User(x.get("userFbId")?.Value <string>(), session));

            return(new FB_ParticipantsAdded()
            {
                author = author,
                thread = thread as FB_Group,
                added = added.ToList(),
                at = at
            });
        }
Example #4
0
        public static FB_Event parse_delta(Session session, JToken data)
        {
            var class_ = data?.get("class")?.Value <string>();

            if (class_ == "ParticipantsAddedToGroupThread")
            {
                return(FB_ParticipantsAdded._parse(session, data));
            }
            else if (class_ == "ParticipantLeftGroupThread")
            {
                return(FB_ParticipantRemoved._parse(session, data));
            }
            else if (class_ == "MarkFolderSeen")
            {
                // TODO: Finish this
                var folders = data.get("folders")?.Select(folder =>
                                                          folder?.Value <string>().Replace("FOLDER_", ""));
                var at = long.Parse(data?.get("timestamp")?.Value <string>());
                return(null);
            }
            else if (class_ == "ThreadName")
            {
                return(FB_TitleSet._parse(session, data));
            }
            else if (class_ == "ForcedFetch")
            {
                return(FB_UnfetchedThreadEvent._parse(session, data));
            }
            else if (class_ == "DeliveryReceipt")
            {
                return(FB_MessagesDelivered._parse(session, data));
            }
            else if (class_ == "ReadReceipt")
            {
                return(FB_ThreadsRead._parse_read_receipt(session, data));
            }
            else if (class_ == "MarkRead")
            {
                return(FB_ThreadsRead._parse(session, data));
            }
            else if (class_ == "NoOp")
            {
                // Skip "no operation" events
                return(null);
            }
            else if (class_ == "ClientPayload")
            {
                throw new FBchatParseError("This is implemented in `parse_events`");
            }
            else if (class_ == "NewMessage")
            {
                return(FB_MessageEvent._parse(session, data));
            }
            else if (class_ == "ThreadFolder")
            {
                return(FB_ThreadFolder._parse(session, data));
            }
            return(new FB_UnknownEvent()
            {
                source = "Delta class", data = data
            });
        }