I want to get private messages (provided by the Privatemsg module) that are related to a particular user, programatically.
How can I do this?
Private messages are entities so you can use entity_load() to load them by condition...or use the wrapper provided by the private message module itself:
$messages = privatemsg_message_load_multiple(array(), array('author' => $uid));
That will get all messages created by the user identified by $uid.
Related
I want to check if my account is member of the channel. How can I do this if I only have valid invite link
With the current telethon API, you can't check if you're a member of a channel or private group using an invite link. However, you can resolve the invite link into channel ID and then use iter_dialogs to check if there is a same ID.
To avoid FloodWait, it's better to do iter_dialogs once and save a local copy for yourself. You may update your local copy when you join new channels and groups.
For public groups you can iter_participants and find yourself. However, the former method still works here as well.
You can do:
async for dialog in client.iter_dialogs():
if dialog.entity.megagroup:
group_name = dialog.entity.title
members_count = str(dialog.entity.participants_count)
print(f'GROUP: {group_name} - ({members_count} members)')
Here I checked if the chat is a megagroup, if so then it will print participants count and group's name.
we are using EWS Managed API to process items in our exchange public folders. We are able to traverse through folders, retrieve new items and change them. It is possible to Move an item to a specific folder but when we use copy method strange exception occurs: An internal server error occurred. The operation failed., IdAndSession.MailboxSession: session is not IMailboxSession
To exclude a code issue I use an example provided by microsoft:
// As a best practice, limit the properties returned by the Bind method to only those that are required.
PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, EmailMessageSchema.ParentFolderId);
// Bind to the existing item by using the ItemId.
// This method call results in a GetItem call to EWS.
EmailMessage originalMessage = EmailMessage.Bind(service, ItemId, propSet);
// Copy the orignal message into another folder in the mailbox and store the returned item.
Item item = originalMessage.Copy("epQ/3AAA=");
// Check that the item was copied by binding to the copied email message
// and retrieving the new ParentFolderId.
// This method call results in a GetItem call to EWS.
EmailMessage copiedMessage = EmailMessage.Bind(service, item.Id, propSet);
Source
But the exception still occurs. Is it possible that this is a bug in Framework?
Thanks in advance for any help.
To send messages (messages.sendMessage), you need channel_id and access_hash. For any public channels or chats, I can get it using contacts.resolveUsername and pass the username. But what about private channels, Is it accessible only by link? I Can't find a solution. Thanks!
You can get it either by joining the channel and checking the retval or iterating your dialogs (client.iter_dialogs)
I want to subscribe to my own presence changes in my Skype for Buisness Client and tried the ContactInformationChanged event from the Lync Client SDK. The documentation on subscribing to presence (doc) writes that their is also a need to create a Subscription, fill it with the ContactInformationTypes i want to subscribe to, add the contact i want to subscribe to and call Subscribe() on the subscription object. Now unless i misunderstood the documentation you still habe to subscribe to the ContactInformationChanged event if you do that. The thing is even if i leave out the subscription creation part and just subscribe to the ContactInformationChanged event it makes no difference. For example if i do this:
var selfContact = m_lyncClient.Self.Contact;
selfContact.ContactInformationChanged += Contact_ContactInformationChanged;
m_subscription = m_lyncClient.ContactManager.CreateSubscription();
m_subscription.AddContact(selfContact);
List<ContactInformationType> contactInformationList = new List<ContactInformationType>
{
ContactInformationType.Activity,
ContactInformationType.Availability,
ContactInformationType.ActivityId,
ContactInformationType.CustomActivity,
};
m_subscription.Subscribe(ContactSubscriptionRefreshRate.High, contactInformationList);
I get event messages for ContactInformationChanged with a ContactInformationTypethat i didn't specify.
My Questions:
Is the Subscription creation part even necessary?
Is there a way to just get Presence Notifications of specific ContactInformationType's changing (like Availabilty for example)?
Is the Subscription creation part even necessary?
For your own contact, no you don't need to create a subscription.
Is there a way to just get Presence Notifications of specific ContactInformationType's changing (like Availabilty for example)?
No. You just need to filter out all other callbacks like so:
private void Contact_ContactInformationChanged(object sender, ContactInformationChangedEventArgs e)
{
if (e.ChangedContactInformation.Contains(ContactInformationType.Availability) ||
e.ChangedContactInformation.Contains(ContactInformationType.ActivityId) ||
e.ChangedContactInformation.Contains(ContactInformationType.CustomActivity))
{
OnLyncPresenceChanged();
}
}
I have a multi-tenant system where each tenant shares the same instance of the codebase, but has their own databases.
I'm using RavenDB for persistence, with a standard c# facade/BLL backend wrapped with Asp.net WebAPI, and I'm finding that at every lower level operation (deep within my business logic classes) that touch the datbase, I need to pass in an identifier so that my RavenDb client session knows which database to operate against.
When the user authenticates, I resolve the appropriate database identifer, store it in the session manager. Every call against the Web API layer passes in a session ID which resolves the database ID in the backend, which is then used to pass into every single facade/BLL call.
All my dependencies are handled via an IoC container at the WebAPI level, but i can't pass in the database ID at this phase because it can be different for every user that is logged in.
this, of course is getting tedious.
can someone give me some guidance as to what I can do to alleviate this? Maybe perhaps some sort of policy injection/AOP solution?
a rough sample of my backend code looks like..
public class WidgetService()
{
private WidgetBLL _widgetBLL;
private ISessionManager _sessionManager;
public WidgetService(WidgetBLL _widgetBLL, ISessionManager sessionManager)
{
_widgetBLL = widgetBLL;
_sessionManager = sessionManager
}
public Widget getWidget(string sessionId, string widgetId)
{
string DbId = sessionManager.ResolveDbId(sessionId)
return _widgetBLL.GetWidget(string dbId, string widgetId);
}
}
public class WidgetManager()
{
public GetWidget(string dbId, string widgetId)
{
using (IDocumentSession session = documentStore.OpenSession(dbId)
{
var widget = session.load<Widget>(widgetid);
}
return widget;
}
}
the DBID is the identifier for that particular tenant that this particular user is a member of.
You need to change how you are using the session.
Instead of opening and closing the session yourself, do that in the IoC code.
Then you pass a session that is already opened for the right db.