Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
59e6de35
by Philipp Hörist at 2022-10-10T22:01:37+02:00
2 changed files:
Changes:
| ... | ... | @@ -41,9 +41,9 @@ |
| 41 | 41 | |
| 42 | 42 | from .const import DEFAULT_WORKSPACE_COLOR
|
| 43 | 43 | from .emoji_data_gtk import get_emoji_data
|
| 44 | +from .util import get_contact_color
|
|
| 44 | 45 | from .util import load_icon_surface
|
| 45 | 46 | from .util import load_pixbuf
|
| 46 | -from .util import text_to_color
|
|
| 47 | 47 | from .util import scale_with_ratio
|
| 48 | 48 | from .util import get_css_show_class
|
| 49 | 49 | from .util import convert_rgb_string_to_float
|
| ... | ... | @@ -124,12 +124,11 @@ def generate_avatar(letters: str, |
| 124 | 124 | |
| 125 | 125 | @lru_cache(maxsize=None)
|
| 126 | 126 | def generate_default_avatar(letter: str,
|
| 127 | - color_string: str,
|
|
| 127 | + color: tuple[float, float, float],
|
|
| 128 | 128 | size: int,
|
| 129 | 129 | scale: int,
|
| 130 | 130 | style: str = 'circle') -> cairo.ImageSurface:
|
| 131 | 131 | |
| 132 | - color = text_to_color(color_string)
|
|
| 133 | 132 | surface = generate_avatar(letter, color, size, scale)
|
| 134 | 133 | surface = clip(surface, style)
|
| 135 | 134 | surface.set_device_scale(scale, scale)
|
| ... | ... | @@ -414,11 +413,10 @@ def get_surface(self, |
| 414 | 413 | return surface
|
| 415 | 414 | |
| 416 | 415 | name = contact.name
|
| 417 | - color_string = str(contact.jid)
|
|
| 418 | - |
|
| 416 | + color = get_contact_color(contact)
|
|
| 419 | 417 | letter = generate_avatar_letter(name)
|
| 420 | 418 | surface = generate_default_avatar(
|
| 421 | - letter, color_string, size, scale, style=style)
|
|
| 419 | + letter, color, size, scale, style=style)
|
|
| 422 | 420 | if show is not None:
|
| 423 | 421 | surface = add_status_to_avatar(surface, show)
|
| 424 | 422 | self._cache[jid][(size, scale, show)] = surface
|
| ... | ... | @@ -457,9 +455,12 @@ def get_muc_surface(self, |
| 457 | 455 | app.storage.cache.set_muc(jid, 'avatar', None)
|
| 458 | 456 | |
| 459 | 457 | client = app.get_client(account)
|
| 458 | + contact = client.get_module('Contacts').get_bare_contact(jid)
|
|
| 459 | + |
|
| 460 | 460 | name = get_groupchat_name(client, jid)
|
| 461 | + color = get_contact_color(contact)
|
|
| 461 | 462 | letter = generate_avatar_letter(name)
|
| 462 | - surface = generate_default_avatar(letter, str(jid), size, scale, style)
|
|
| 463 | + surface = generate_default_avatar(letter, color, size, scale, style)
|
|
| 463 | 464 | self._cache[jid][(size, scale, None)] = surface
|
| 464 | 465 | return surface
|
| 465 | 466 |
| ... | ... | @@ -48,12 +48,14 @@ |
| 48 | 48 | |
| 49 | 49 | from gajim.common import app
|
| 50 | 50 | from gajim.common import configpaths
|
| 51 | +from gajim.common import types
|
|
| 51 | 52 | from gajim.common.i18n import _
|
| 52 | 53 | from gajim.common.helpers import URL_REGEX
|
| 53 | 54 | from gajim.common.const import LOCATION_DATA
|
| 54 | 55 | from gajim.common.const import Display
|
| 55 | 56 | from gajim.common.const import StyleAttr
|
| 56 | 57 | from gajim.common.ged import EventHelper as CommonEventHelper
|
| 58 | +from gajim.common.modules.contacts import GroupchatParticipant
|
|
| 57 | 59 | from gajim.common.styling import PlainBlock
|
| 58 | 60 | from gajim.common.structs import VariantMixin
|
| 59 | 61 | |
| ... | ... | @@ -507,6 +509,19 @@ def text_to_color(text: str) -> tuple[float, float, float]: |
| 507 | 509 | return nbxmpp.util.text_to_color(text, background) # type: ignore
|
| 508 | 510 | |
| 509 | 511 | |
| 512 | +def get_contact_color(contact: types.ChatContactT
|
|
| 513 | + ) -> tuple[float, float, float]:
|
|
| 514 | + |
|
| 515 | + if isinstance(contact, GroupchatParticipant):
|
|
| 516 | + if contact.room.muc_context in (None, 'public'):
|
|
| 517 | + return text_to_color(contact.name)
|
|
| 518 | + |
|
| 519 | + if contact.real_jid is not None:
|
|
| 520 | + return text_to_color(str(contact.real_jid))
|
|
| 521 | + |
|
| 522 | + return text_to_color(str(contact.jid))
|
|
| 523 | + |
|
| 524 | + |
|
| 510 | 525 | def get_color_for_account(account: str) -> str:
|
| 511 | 526 | col_r, col_g, col_b = text_to_color(account)
|
| 512 | 527 | rgba = Gdk.RGBA(red=col_r, green=col_g, blue=col_b)
|