示例#1
0
        public void DelayedInitialize()
        {
            #region Feed Templates
            var replyAction = new NotificationAction() {
                Name = "reply",
                Label = "Reply",
                Callback = delegate (IActivityFeedItem item, NotificationAction action) {
                    var twitterItem = (TwitterActivityFeedItem)item;
                    // FIXME:
                    Console.WriteLine("Reply");
                }
            };

            var retweetAction = new NotificationAction() {
                Name = "retweet",
                Label = "Retweet",
                Callback = delegate (IActivityFeedItem item, NotificationAction action) {
                    var twitterItem = (TwitterActivityFeedItem)item;
                    // FIXME:
                    Console.WriteLine("Retweet");
                }
            };

            var feedService = ServiceManager.Get<ActivityFeedService>();
            feedService.AddTemplate("tweet", "Twitter", "tweets", "tweet", new Dictionary<string, object> {
                { "IconUrl", "resource:/twitter/twitm-16.png" }
            }, replyAction, retweetAction);

            feedService.AddTemplate("direct-tweet", "Twitter", "direct tweets", "direct tweet", new Dictionary<string, object> {
                { "IconUrl", "resource:/twitter/twitm-16.png" }
            }, replyAction);

            #endregion

            var accountService = ServiceManager.Get<AccountService>();
            accountService.AccountAdded   += HandleAccountAdded;
            accountService.AccountRemoved += HandleAccountRemoved;
            foreach (Account account in accountService.Accounts) {
                HandleAccountAdded(account);
            }
        }
示例#2
0
        public void DelayedInitialize()
        {
            global::OAuth.Xmpp.RequestProxies.XmppRequestProxy.Register();

            // FIXME: This is not an ideal place for these. Perhaps create an XmppService?
            var feed = ServiceManager.Get<ActivityFeedService>();
            feed.AddTemplate("presence", "Presence Changes", "is now {0}", "are now {0}");
            feed.AddTemplate("music", "Friend Events", "is listening to", "are listening to");
            feed.AddTemplate("mood", "Friend Events", "is feeling {0}", "are feeling {0}");

            var joinMucAction = new NotificationAction() {
                Name = "join",
                Label = "Join Conference",
                Callback = delegate (IActivityFeedItem item, NotificationAction action) {
                    var xmppItem = (XmppActivityFeedItem)item;
                    xmppItem.Account.JoinMuc(xmppItem.ActionItem, null);
                }
            };
            feed.AddTemplate("invite", null, "invites you to join {0}", "invites you to join {0}",
                new Dictionary<string, object> {
                    { "DesktopNotify", true },
                    { "ShowInMainWindow", true }
                }, joinMucAction
            );

            var approveAction = new NotificationAction {
                Name = "approve",
                Label = "Approve",
                Callback = delegate (IActivityFeedItem item, NotificationAction action) {
                    var xmppItem = (XmppActivityFeedItem)item;

                    var presence = new Presence(xmppItem.Account.Client.Document);
                    presence.To = xmppItem.FromJid;
                    presence.Type = PresenceType.subscribed;
                    xmppItem.Account.Client.Write(presence);

                    // FIXME: Show some sort of "friendname has been added!" notification?
                    // FIXME: Should show AddFriendWindow instead so that nickname/groups can be set?
                    xmppItem.Account.AddRosterItem(xmppItem.FromJid, null, null, null);
                }
            };

            var denyAction = new NotificationAction {
                Name = "deny",
                Label = "Deny",
                Callback = delegate (IActivityFeedItem item, NotificationAction action) {
                    var xmppItem = (XmppActivityFeedItem)item;
                    var presence = new Presence(xmppItem.Account.Client.Document);
                    presence.To = xmppItem.FromJid;
                    presence.Type = PresenceType.unsubscribed;
                    xmppItem.Account.Client.Write(presence);
                }
            };

            feed.AddTemplate("subscribe", null, "wants to be friends with you", "want to friends with you", new Dictionary<string, object> {
                { "DesktopNotify", true },
             	{ "ShowInMainWindow", true }
            }, approveAction, denyAction);

            feed.AddTemplate("subscribed", null, "is now your friend", "are now your friend", new Dictionary<string, object> {
                { "DesktopNotify", true },
             	{ "ShowInMainWindow", true }
            });

            feed.AddTemplate("unsubscribe", null, "is no longer friends with you", "are no longer friends with you", new Dictionary<string, object> {
                { "DesktopNotify", true },
             	{ "ShowInMainWindow", true }
            });

            feed.AddTemplate("unsubscribed", null, "is no longer your friend", "are no longer your friend", new Dictionary<string, object> {
                { "DesktopNotify", true },
             	{ "ShowInMainWindow", true }
            });

            feed.AddTemplate("account-error", null, "Error with {0}", null, new Dictionary<string, object> {
                { "DesktopNotify", true },
             	{ "ShowInMainWindow", true }
            });

            feed.AddTemplate("unknown-account-error", null, "Error with {0}", null, new Dictionary<string, object> {
                { "DesktopNotify", true },
             	{ "ShowInMainWindow", true }
            }, new [] {
                new NotificationAction {
                    Name     = "details",
                    Label    = "Show Details",
                    Callback = delegate (IActivityFeedItem item, NotificationAction action) {
                        var xmppItem = (XmppActivityFeedItem)item;
                        Exception ex = (Exception)item.Data;
                        Application.Client.ShowErrorWindow("Error with {0}".FormatWith(xmppItem.Account.Jid.Bare), ex);
                    }
                } /*,
                new NotificationAction {
                    Name = "bug",
                    Label = "Report Bug",
                    Callback = delegate (IActivityFeedItem item, NotificationAction action) {
                        // FIXME:
                    }
                } */
            });
        }